-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_output.py
156 lines (129 loc) · 4.54 KB
/
test_output.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
'''
Created on 12.02.2014
@author: uwe
This code require Python 2.2.1 or later
'''
import time,atexit,curses,sys
import datetime
import sqlite3
import matplotlib.pyplot as plt
from matplotlib.dates import YearLocator, MonthLocator, DateFormatter
import plotGraph
class Intervall:
def __init__(self):
self.times = set()
self.wb = 0
self.rb = 0
self.wbs = 0
self.rbs = 0
self.show_time = 0
def toString(self):
return 'show_time = ' + str(self.show_time) + ' wbs / rbs ' + str(self.wbs) + ' / ' + str(self.rbs)
def toDB(self):
return (self.show_time, self.wbs, self.rbs)
def ResultIter(cursor, arraysize=100):
'An iterator that uses fetchmany to keep memory usage down'
while True:
results = cursor.fetchmany(arraysize)
if not results:
break
for result in results:
yield result
def getTimeStamp(year, month, day, houer, minute):
''' convert from year day month to time stamp '''
dateTimeInput = datetime.datetime(year, month, day, houer, minute)
timeStamp = time.mktime(dateTimeInput.timetuple())
timeStamp = int(timeStamp)
return timeStamp
#------------------------------------------------------------------------------
def timeStampToDate(timeStamp):
''' converts form time stamp to year day month '''
return datetime.datetime.fromtimestamp(
float(timeStamp)).strftime('%Y-%m-%d %H:%M:%S')
#------------------------------------------------------------------------------
def eta(secs):
if secs<60:
return "%2.2d sec "%secs
else:
return "%d min %2.2d sec" % (secs/60, secs%60)
def cleanup():
print curses.tigetstr("cnorm")
if __name__ == '__main__':
curses.setupterm()
print curses.tigetstr("civis"),
atexit.register(cleanup)
time_start = time.time()
#------------------------------------------------------------------------------
dbFile = 'sqlite_new.db'
conn = sqlite3.connect(dbFile)
conn.row_factory = sqlite3.Row
c = conn.cursor()
c.execute('''
CREATE TABLE IF NOT EXISTS
ost_oneHouer_stat (
id integer primary key asc,
time integer,
wbs integer,
rbs integer)
''')
output = c.execute('''
SELECT * FROM timestamps ORDER BY time limit 100
''').fetchall()
first_last_timestamp = 0
one_houer = 3600*8
rbSum = {} #dict read
wbSum = {} #dict write
cpSum = {} #dict complete
starttime = time.time()
size = len(output)
counter=1
for DBtimestamp in output:
timestampID = DBtimestamp[0]
timestamp = DBtimestamp[1]
#c.execute('''SELECT rb, wb FROM samples_ost WHERE time = ?''', (timestampID,)) # <- slow as hell :-)
c.execute('''SELECT rb, wb FROM ost_values WHERE time = ?''', (timestampID,))
tmpSumRB = 0
tmpSumWB = 0
tmpSumCP = 0
if timestamp not in rbSum:
rbSum[timestamp]=0
wbSum[timestamp]=0
cpSum[timestamp]=0
while True:
res = c.fetchmany(500)
if not res:
break
else:
for item in res:
tmpSumRB -= ((item[0]/60)/1000000)
tmpSumWB += ((item[1]/60)/1000000)
tmpSumCP = tmpSumCP + (((item[1] +item[0])/60)/1000000)
rbSum[timestamp]+= tmpSumRB
wbSum[timestamp]+= tmpSumWB
cpSum[timestamp]+= tmpSumCP
if counter%10 == 0:
duration = (time.time() - starttime)
fraction = (float(counter)/float(size))
endtime = duration * (1.0/ fraction) - duration
printString = str("\rextracted %9d timestamps [%s] ETA = %s"
%(counter,"|"*int(fraction*20.0)+"\\|/-"[counter%4]+"-"*(19-int(fraction*20.0)), eta(endtime)))
print printString,
sys.stdout.flush()
counter+=1
# progressbar end
plotrb = []
plotwb = []
for key in sorted(rbSum.keys()):
plotrb.append(rbSum[key])
for key in sorted(wbSum.keys()):
plotwb.append(wbSum[key])
#------------------------------------------------------------------------------
time_end = time.time()
print "end with no errors in: " + str(time_end - time_start)
#-----------------------------------------------------------------------------
list_of_list = []
list_of_list.append(sorted(rbSum.keys()))
list_of_list.append(plotrb)
list_of_list.append(sorted(wbSum.keys()))
list_of_list.append(plotwb)
plotGraph.plotGraph(list_of_list, 'ich bin ein Test!')