-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_file_type.py
More file actions
52 lines (43 loc) · 1.6 KB
/
plot_file_type.py
File metadata and controls
52 lines (43 loc) · 1.6 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
import matplotlib.pyplot as plt
import json
import pandas as pd
import calendar
from datetime import datetime
from style import set_style
set_style(plt)
year = datetime.now().year
with open(f'data/{year}-file-type.json', 'r') as file:
all_data = json.load(file)
fig, ax = plt.subplots(figsize=(10, 6))
previous = None
for type in all_data.keys():
data = all_data[type]
# Skip first date
if year == 2025:
first_date = sorted(data.keys())[0]
del data[first_date]
if len(data) == 0:
continue
# Per month
df = pd.DataFrame({'date': pd.to_datetime(list(data.keys())),
'downloads': list(data.values())
})
# Fill missing days with 0
df = df.set_index('date')
full_date_range = pd.date_range(start=pd.to_datetime(f'{year}-01-01'), end=pd.Timestamp.now(), freq='D')
df = df.reindex(full_date_range, fill_value=0)
df['month'] = df.index.to_period('M')
df['month_name'] = df.index.strftime('%b')
monthly_data = df.groupby('month')['downloads'].sum().reset_index()
monthly_data = monthly_data.sort_values(by='month')
monthly_data['month_name'] = monthly_data['month'].apply(lambda x: calendar.month_abbr[x.month])
bars = ax.bar(monthly_data['month_name'], monthly_data['downloads'], bottom=previous, label=type)
if previous is None:
previous = monthly_data['downloads']
else:
previous += monthly_data['downloads']
plt.title(f'Monthly downloads of FAST GitHub releases per file type {year}')
plt.legend()
plt.tight_layout()
fig.savefig(f'plots/{year}-file-type.svg')
#plt.show()