-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
173 lines (148 loc) · 5.71 KB
/
Copy pathplot.py
File metadata and controls
173 lines (148 loc) · 5.71 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
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
import copy
import matplotlib.pyplot as plt
import numpy as np
import os
import pandas
from code_stats import GithubStats, TravisStats
from code_stats_data import (
area_plot_fmt,
get_all_weekly_stats,
get_weekly_dates,
get_weekly_stats,
legend_values,
)
import pandas.plotting
pandas.plotting.register_matplotlib_converters()
def area_plot(df, title, fontsize=None, saveas=None):
fig, ax = plt.subplots(figsize=(10, 6))
plt.tick_params(axis="both", which="major", labelsize=fontsize)
fig.autofmt_xdate()
cumsum_bottom = np.zeros(df.shape[0])
linewidth = 2
legend_handles = []
date = np.array(df.index.values, dtype=np.datetime64)
for val in area_plot_fmt:
repo_name = val[0]
facecolor = val[2]
cumsum_top = cumsum_bottom + np.array(df.loc[:, repo_name], dtype=np.float64)
h1 = ax.fill_between(date, cumsum_bottom, cumsum_top, facecolor=facecolor)
h2 = ax.plot(date, cumsum_top, color="black", linewidth=1)
h3 = ax.fill(np.NaN, np.NaN, facecolor=facecolor, linewidth=0.0)
legend_handles.append((h3[0],))
cumsum_bottom = copy.deepcopy(cumsum_top)
ax.plot(date, np.zeros(df.shape[0]), color="black", linewidth=1, label=None)
# ax.set_title(title, fontsize=fontsize)
ax.set_ylabel(title, fontsize=fontsize)
# ax.set_xlabel("Updated:" + str(datetime.date.today()), fontsize=fontsize)
legend_handles.reverse()
ax.legend(legend_handles, legend_values, loc="upper left", fontsize=fontsize)
if saveas:
plt.savefig(saveas)
return ax
def make_plots(db, dates, colname, title, fontsize=None, estimate_missing=True):
df = get_all_weekly_stats(db, dates, colname, estimate_missing=estimate_missing)
df.loc[:, "prisms-center/prisms_jobs"] += df.loc[:, "prisms-center/pbs"]
df = df.drop(axis="columns", labels="prisms-center/pbs")
area_plot(df, title, fontsize=fontsize, saveas="images/" + colname + ".png")
dfc = df.cumsum()
# print(title, colname)
# for col in dfc.columns:
# print(dfc[col])
# print(f"~~~ {col} ~~~")
# for i in range(df.shape[0]):
# print(dfc.index[i], df[col][i], sum(df[col][:i]))
# print()
header = f"Cumulative {title} {dfc.index[-1]}"
print(header)
print("~" * len(header))
for col in dfc.columns:
print(f"{col}: ", dfc[col].iloc[-1])
print("--> Sum:", sum(dfc.iloc[-1, :]))
print()
area_plot(
df.cumsum(),
"Cumulative " + title,
fontsize=fontsize,
saveas="images/" + colname + "_cumulative.png",
)
def make_plots_excluding_travis_builds(
db, dates, colname, title, fontsize=None, estimate_missing=True
):
df = get_all_weekly_stats(db, dates, colname, estimate_missing=estimate_missing)
df.loc[:, "prisms-center/prisms_jobs"] += df.loc[:, "prisms-center/pbs"]
df = df.drop(axis="columns", labels="prisms-center/pbs")
travis_db = TravisStats()
travis_db.connect()
travis_df = get_all_weekly_stats(travis_db, dates, "build_count")
travis_db.close()
# if a >= b: -> max(a-b,0)
for repo_name in travis_df.columns:
if repo_name in df.columns:
df.loc[:, repo_name] = df.loc[:, repo_name] - travis_df.loc[:, repo_name]
df.loc[df.loc[:, repo_name] < 0, repo_name] = 0
area_plot(
df,
title,
saveas="images/" + colname + "_exclude_travis_builds.png",
fontsize=fontsize,
)
dfc = df.cumsum()
area_plot(
dfc,
"Cumulative " + title,
fontsize=fontsize,
saveas="images/" + colname + "_cumulative_exclude_travis_builds.png",
)
header = f"Cumulative {title} (Excluding travis builds) {dfc.index[-1]}"
print(header)
print("~" * len(header))
for col in dfc.columns:
print(f"{col}: ", dfc[col].iloc[-1])
print("--> Sum:", sum(dfc.iloc[-1, :]))
print()
with open('stats.html', 'w') as f:
f.write('<div class="software-area">\n')
f.write(' <img src="assets/code_stats/unique_clones_cumulative_exclude_travis_builds.png">\n')
f.write(f" <h3>{header}</h3>\n")
f.write("<ul>\n")
for col in dfc.columns:
count = int(dfc[col].iloc[-1])
f.write(f" <li>{col}:{count}</li>\n")
f.write("</ul>\n")
total_count = int(sum(dfc.iloc[-1, :]))
f.write(f"<span>Total: {total_count}</span>\n")
f.write('</div>\n')
def print_data_by_week(db, repo_name, col):
dates = get_weekly_dates(db)
df = pandas.DataFrame(index=dates, columns=[repo_name])
for repo_name in [repo_name]:
curs = db.conn.cursor()
curs.execute(
"SELECT day, " + col + " FROM stats WHERE repo_id=? ORDER BY day",
(db.get_repo_id(repo_name),),
)
weekly_stats = get_weekly_stats(curs, dates, col)
curs.close()
df.loc[:, repo_name] = weekly_stats
for i in range(df.shape[0]):
print(dates[i], df[repo_name][i], sum(df[repo_name][:i]))
db = GithubStats()
db.connect()
dates = get_weekly_dates(db)
if not os.path.exists("images"):
os.mkdir("images")
fontsize = 14
# prisms-center/CASMcode
# prisms-center/phaseField
# dftfeDevelopers/dftfe
# print_data_by_week(db, "dftfeDevelopers/dftfe", 'unique_clones')
# print_data_by_week(db, "prisms-center/Fatigue", 'views')
# exit()
make_plots(db, dates, "views", "Weekly Views", fontsize=fontsize)
make_plots(db, dates, "unique_views", "Weekly Unique Views", fontsize=fontsize)
make_plots(db, dates, "clones", "Weekly Clones", fontsize=fontsize)
make_plots(db, dates, "unique_clones", "Weekly Unique Clones", fontsize=fontsize)
make_plots_excluding_travis_builds(
db, dates, "unique_clones", "Weekly Unique Clones", fontsize=fontsize
)
db.close()