-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyze.py
96 lines (82 loc) · 2.13 KB
/
analyze.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
# ---
# jupyter:
# jupytext:
# cell_metadata_filter: -all
# formats: ipynb,py:percent
# text_representation:
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.6.0
# kernelspec:
# display_name: Python 3
# language: python
# name: python3
# ---
# %%
from datetime import date, timedelta as td
from download import fname
import pandas as pd
import numpy as np
# %%
def load_data(cdate):
try:
return pd.read_csv(fname(cdate), sep="\t")
except FileNotFoundError:
return pd.DataFrame(
{
key: []
for key in [
"Date",
"Seconds",
"NumberPeople",
"Activity",
"Document",
"Category",
"Productivity",
]
}
)
# %%
def load_data_week(cdate):
return [load_data(date.today() - td(days=i)) for i in range(7, -1, -1)]
# %%
def score_day(cdate):
df = load_data(cdate)
if np.sum(df.Seconds) == 0.0:
return 0.0
score = np.sum((df.Productivity + 2) * df.Seconds) / (4 * np.sum(df.Seconds))
return score * 100
# %%
def weekday(cdate):
return d.weekday()
# %%
def score_over_time(cdate, weeks=1):
cweekday = weekday(cdate)
days_to_monday = cweekday
days_to_score = days_to_monday + 7 * weeks
day_start = cdate - td(days=days_to_score)
scores = -np.ones((weeks + 1, 7)).ravel()
for i in range(days_to_score + 1):
cur_day = day_start + td(days=i)
try:
cur_score = score_day(cur_day)
scores[i] = cur_score
except FileNotFoundError:
continue
scores = scores.reshape(weeks + 1, 7)
return scores
# %%
def writing_time(cdate):
df = load_data(cdate)
sites = [
"overleaf.com",
"hyper",
"scholar.google.com",
"arxiv.org",
"microsoft powerpoint",
"Google Documents",
"Google Presentations",
]
minutes = df.query(f"Activity in {sites}").Seconds.sum() / 60.0
return minutes