-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstats.py
executable file
·188 lines (175 loc) · 4.79 KB
/
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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env python3
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import utils
TSV_FILE = "data/stats.tsv"
COLUMNS: dict[str | None, list[str]] = {
# We ignore the following fields, but we have to include them nevertheless
# to appease our tests.
None: [
# Timestamps
"date",
"timestamp",
# Disk usage
"disk_usage",
"disk_usage_human",
# Noisy code statistics.
"foc",
"loc",
"loc_archive",
# Noise Crum statistics.
"crum_sisters_sum",
"crum_antonyms_sum",
"crum_dawoud_sum",
"crum_greek_sisters_sum",
"crum_homonyms_sum",
"crum_img_sum",
"crum_root_senses_sum",
"crum_categories_sum",
],
"Crum Fixes": [
# The following Crum fields are not expected to be populated for every
# entry.
"crum_drv_typos",
"crum_last_page",
"crum_notes",
"crum_pages_changed",
"crum_type_override",
"crum_typos",
"crum_wrd_typos",
],
"Crum Appendices": [
# The following Crum fields are ones that we seek to populated for most
# entries.
"crum_antonyms",
"crum_dawoud",
"crum_greek_sisters",
"crum_homonyms",
"crum_img",
"crum_root_senses",
"crum_sisters",
"crum_categories",
],
"Files of Code per Language": [
"foc_css",
"foc_dot",
"foc_html",
"foc_js",
"foc_json",
"foc_keyboard_layout",
"foc_make",
"foc_md",
"foc_python",
"foc_sh",
"foc_toml",
"foc_ts",
"foc_txt",
"foc_yaml",
],
"Lines of code per Language": [
# Lines of code, broken by language.
"loc_css",
"loc_dot",
"loc_html",
"loc_js",
"loc_json",
"loc_keyboard_layout",
"loc_make",
"loc_md",
"loc_python",
"loc_sh",
"loc_toml",
"loc_ts",
"loc_txt",
"loc_yaml",
],
"Lines of Code per Project": [
# Lines of code, broken by project.
"loc_bible",
"loc_copticsite",
"loc_crum",
"loc_flashcards",
"loc_grammar",
"loc_kellia",
"loc_keyboard",
"loc_morphology",
"loc_shared",
"loc_site",
],
"Number of Commits": [
"num_commits",
],
"Number of GitHub Issues": [
"open_issues",
"closed_issues",
],
"Number of Contributors": [
"num_contributors",
],
}
TARGET_ANNOTATIONS = 15
def validate(df: pd.DataFrame) -> None:
available: set[str] = set(df.columns)
included: set[str] = set(
sum([COLUMNS[key] for key in COLUMNS if key is not None], []),
)
excluded: set[str] = set(COLUMNS[None])
if available != (included | excluded):
utils.fatal(
"Absent columns:",
available - (included | excluded),
"Extra columns",
(included | excluded) - available,
)
dupe = included & excluded
if dupe:
utils.fatal(
"The following elements are marked as excluded although they are used:",
dupe,
)
del dupe
for key, columns in COLUMNS.items():
if not columns:
utils.fatal(key, "is empty!")
def main():
# Read the TSV file.
df = pd.read_csv(TSV_FILE, sep="\t")
validate(df)
# Convert the Unix epoch timestamp to a datetime object.
df["timestamp"] = pd.to_datetime(df["timestamp"], unit="s")
# Set the timestamp as the index.
df.set_index("timestamp", inplace=True)
# Plot each list of column names.
for title, columns in COLUMNS.items():
if title is None:
continue
plt.figure(figsize=(10, 6))
for column in columns:
total_points: int = len(df[column])
interval: int = max(1, total_points // TARGET_ANNOTATIONS)
plt.plot(df.index, df[column], label=column)
for i, (x, y) in enumerate(zip(df.index, df[column])):
if not np.isfinite(y):
continue
if i == total_points - 1 or (
i % interval == 0 and total_points - i >= interval / 2
):
plt.text(
x,
y,
str(int(y)),
ha="center",
va="bottom",
fontsize=8,
color="black",
)
plt.title(title)
plt.xlabel("Time")
plt.ylabel("Values")
plt.legend()
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
if __name__ == "__main__":
main()