-
Notifications
You must be signed in to change notification settings - Fork 130
/
graph.py
64 lines (44 loc) · 1.86 KB
/
graph.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
import datetime
import os
import history
import fbapi
import status
LOG_DATA_DIR = "log"
CSV_OUTPUT_DIR = "generated_graphs/csv"
# LOL TIMEZONES TOO HARD
UTC_OFFSET = 11
ONE_DAY_SECONDS = 60 * 60 * 24
class Grapher():
def __init__(self):
if not os.path.exists(CSV_OUTPUT_DIR):
os.makedirs(CSV_OUTPUT_DIR)
def to_csv(self, uid, start_time, end_time):
# The user's history.
status_history = history.StatusHistory(uid)
# Their Facebook username.
#uname = fbapi.get_user_name(uid)
# Generate a CSV from the multiple linear timeseries
with open("generated_graphs/csv/{uid}.csv".format(uid=uid), "w") as f:
f.write("time,")
f.write(",".join(status.Status.statuses))
f.write("\n")
# TODO preprocess sort and splice this instead of linear search.
# UPDATE nahhhh I think I'll just commit it to github ;>_>
for data_point in status_history.activity:
if start_time < data_point.time < end_time:
# Write the time.
f.write(str(data_point.time) + ",")
# Write the various statuses.
# Sample line: <time>,3,1,1,1,1
f.write(",".join(str(data_point._status[status_type]) for status_type in status.Status.statuses))
f.write("\n")
def generate_all_csvs(self, start_time, end_time):
for filename in os.listdir(LOG_DATA_DIR):
print(filename)
uid = filename.split(".")[0]
self.to_csv(uid, start_time, end_time)
if __name__ == "__main__":
g = Grapher()
now = history.StatusHistory.START_TIME
# Graph the last three days by default, but you can do ~whatever you believe you cannnnn~
g.generate_all_csvs(start_time=now - 3 * ONE_DAY_SECONDS, end_time=now)