-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis.py
More file actions
72 lines (67 loc) · 1.85 KB
/
analysis.py
File metadata and controls
72 lines (67 loc) · 1.85 KB
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
def createdata():
collabels = [
'Num',
'UFL',
'TimeStamp',
'Year',
'Month',
'Day',
'Hour',
'Minute',
'Wifi Access Points',
'UFL Building',
'Total_Count',
'SomeNum',
'Zero'
]
from sys import stdin
from datetime import datetime
from collections import defaultdict
buildings = defaultdict(lambda: [0] * (7 * 24 * 6))
import itertools as it
for counter in it.count(1):
if counter % 10000 == 0:
print(f'Checked {counter} lines. ', end='\r')
row = stdin.readline()
if not row:
break
items = {}
for label,col in zip(collabels,row.split(',')):
try:
items[label] = int(col)
except ValueError:
items[label] = col
rowtime = datetime(
items['Year'],
items['Month'],
items['Day'],
items['Hour'],
items['Minute'],
)
dayofweek = rowtime.weekday()
hour = rowtime.hour
minute = rowtime.minute // 10
total = items['Total_Count']
build = items['UFL Building']
buildings[build][dayofweek * 24 * 6 + hour * 6 + minute] += total
print(f'Checked {counter} lines.')
return dict(buildings)
import pickle
import os
try:
with open('pkl/buildings.pkl', 'rb') as f:
buildings = pickle.load(f)
except FileNotFoundError:
if not os.path.exists('pkl'):
os.mkdir('pkl')
with open('pkl/buildings.pkl', 'wb') as f:
buildings = createdata()
pickle.dump(buildings, f)
def indextotime(index):
minute = index % 6
hour = (index // 6) % 24
day = index // (24 * 6)
return day, hour, minute * 10
import json
with open('data.json', 'w') as datafile:
json.dump(buildings, datafile)