-
Notifications
You must be signed in to change notification settings - Fork 0
/
stat.py
50 lines (47 loc) · 1.54 KB
/
stat.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
"""
Created on 15:56, Aug. 19th, 2021
Author: fassial
Filename: stat.py
"""
import sys
import json
import datetime
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import pandas as pd
import requests
from requests.exceptions import HTTPError
closed_time = []
page = 1
while True:
try:
response = requests.get("https://api.github.com/repos/fassial/read-papers/issues",
params={"state": "closed",
"per_page": "100", "page": page},
headers={"Accept": "application/vnd.github.v3+json"})
response.raise_for_status()
except HTTPError as http_error:
print(f"HTTP error occurred: {http_error}")
sys.exit(1)
except Exception as err:
print(f"Other error occurred: {err}")
sys.exit(1)
else:
print("Success!")
json_response = response.json()
if not json_response:
break
closed_time.extend([item["closed_at"] for item in json_response])
page += 1
print(len(closed_time))
df = pd.DataFrame(index=pd.to_datetime(closed_time))
stat = df.groupby(pd.Grouper(freq='M')).size()
ticklabels = [item.strftime("%Y-%m") for item in stat.index]
ax = stat.plot.bar(figsize=(15, 10))
ax.xaxis.set_major_formatter(ticker.FixedFormatter(ticklabels))
ax.figure.autofmt_xdate(rotation=30, ha='center')
ax.set_xlabel("Date")
ax.set_ylabel("# Papers")
ax.set_title("Statistics of Reading Papers (up to %s)" %
datetime.datetime.today().strftime('%Y-%m-%d'))
plt.savefig("stat.png")