-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_stats.py
executable file
·76 lines (60 loc) · 2.06 KB
/
load_stats.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
#! /usr/bin/python
import os
import re
from datetime import date
from datetime import datetime
from collections import defaultdict
import sqlite3
#
# GLOBAL variables
#
homeDir = '/Users/zdev/dev/mamp/apache2/htdocs/jscad/jscad-performance'
csvDir = homeDir + '/csvs'
statDir = homeDir + '/reports'
maxDelta = 1;
dbPath = homeDir + '/jscad.stats.db'
#
# regular expressions for parsing statistics
#
csv_re = re.compile( '([\w\(\)]*),([\d]*),([\d]*),([\d\.]*),([\d]*)' )
#------------------------------------------------------------
#------------------------------------------------------------
def loadCsv( fp ) :
data = []
for xline in fp :
xline = xline.strip()
#print 'line [',xline,']'
xmatch = csv_re.match( xline )
if xmatch:
xname = xmatch.group(1)
xweight = xmatch.group(2)
xinterations = xmatch.group(3)
xaverage = xmatch.group(4)
xallocation = xmatch.group(5)
#print 'match',xname,xweight,xinterations,xaverage,xallocation
data.append([xname, xweight, xinterations, xaverage, xallocation])
return data
#------------------------------------------------------------
# TABLE:
# CREATE TABLE daily (date TEXT, name TEXT, weight INTEGER, interations INTEGER, average NUMERIC, allocation INTEGER)
#------------------------------------------------------------
def insertStatistics( db, today, data ) :
xtoday = today.isoformat()
for index, stats in enumerate(data) :
#print stats[0]
db.execute("insert into daily values(?, ?, ?, ?, ?, ?)", (xtoday, stats[0], stats[1], stats[2], stats[3], stats[4]))
db.commit()
#------------------------------------------------------------
# Main Program Entry
#------------------------------------------------------------
xtoday = date.today()
xtoday = date(2020, 6, 12)
print 'Loading JSCAD Performace Statistics:',xtoday
dbconn = sqlite3.connect( dbPath )
xfilepath = homeDir + '/performance_' + xtoday.isoformat() + '.csv'
with open( xfilepath, 'r' ) as fp :
csvdata = loadCsv(fp)
#print csvdata
fp.close()
insertStatistics(dbconn, xtoday, csvdata)
dbconn.close()