-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocess.py
61 lines (54 loc) · 1.46 KB
/
preprocess.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#####################################################################
#### Developed by Bence Ladoczki <ladoczki@tmit.bme.hu> 2022 Maj ####
#### All rights reserved ####
#####################################################################
import sys
import numpy as np
import json
import datetime
import time
import math
import matplotlib
import matplotlib.pyplot as plt
from scipy.integrate import quad
rates = []
with open('bifi_prices') as f:
for line in f:
x, y = line.split(",")
rates.append([int(x),float(y)])
prev=-1
delta_hist={}
for x,y in rates:
#print(x,prev)
if prev!=-1:
if x-prev>=10000:
print('big skip at',x,'prev:',prev,'diff:',(x-prev)/1000,'sec')
else:
try:
delta_hist[x-prev] += 1
except KeyError:
delta_hist[x-prev] = 1
prev=x
avg_delta=(rates[-1][0]-rates[0][0])/len(rates)
print('avg delta=',avg_delta)
delta=1000
#print(delta)
plt.clf()
plt.xlabel(r'delta time')
plt.ylabel('number of')
plt.grid(axis='y', color='0.95')
plt.bar(delta_hist.keys(), delta_hist.values(), 1.0, color='g')
plt.yscale("log")
plt.show()
price_output = open("bifi_price_list", "w")
time=rates[0][0]//delta
time0=time
for x,y in rates:
if x>time*delta:
dx= x// delta
#print('dx=',dx,'time',time*delta)
for i in range(dx-time):
price_output.write(str(y)+"\n")#+' at '+str(x)
time+=1
print('time:',time-time0)
price_output.close()