-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
update.py
78 lines (63 loc) · 2.51 KB
/
update.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
# -*- coding: utf-8 -*-
""" Update Readme.md and cumulative_gans.jpg """
from __future__ import print_function
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
from bs4 import BeautifulSoup
import requests
import csv
def load_data():
""" Load GANs data from the gans.csv file """
with open('gans.tsv') as fid:
reader = csv.DictReader(fid, delimiter='\t')
gans = [row for row in reader]
return gans
def update_readme(gans):
""" Update the Readme.md text file from a Jinja2 template """
import jinja2 as j2
gans.sort(key=lambda v: v['Abbr.'].upper())
j2_env = j2.Environment(loader=j2.FileSystemLoader('.'),
trim_blocks=True, lstrip_blocks=True)
with open('README.md', 'w') as fid:
print(j2_env.get_template('README.j2.md').render(gans=gans), file=fid)
def update_figure(gans):
""" Update the figure cumulative_gans.jpg """
data = np.array([int(gan['Year']) + int(gan['Month']) / 12
for gan in gans])
x_range = int(np.ceil(np.max(data) - np.min(data)) * 12) + 1
y_range = int(np.ceil(data.size / 10)) * 10 + 1
with plt.style.context("seaborn"):
plt.hist(data, x_range, cumulative="True")
plt.xticks(range(2014, 2019))
plt.yticks(np.arange(0, y_range, 15))
plt.title("Cumulative number of named GAN papers by month")
plt.xlabel("Year")
plt.ylabel("Total number of papers")
plt.savefig('cumulative_gans.jpg')
def update_github_stats(gans):
""" Update Github stats """
num_rows = len(gans)
print('Fetching Github stats...')
for i, gan in enumerate(gans):
url = gan['Official_Code']
if url != "-" and url != "":
print(str(i) + '/' + str(num_rows))
result = requests.get(url)
c = result.text
soup = BeautifulSoup(c, "html.parser")
samples = soup.select("a.social-count")
gan['Watches'] = samples[0].get_text().strip().replace(",", "")
gan['Stars'] = samples[1].get_text().strip().replace(",", "")
gan['Forks'] = samples[2].get_text().strip().replace(",", "")
print(str(i) + '/' + str(num_rows))
print('Complete.')
with open('gans.tsv', 'w') as outfile:
fp = csv.DictWriter(outfile, gans[0].keys(), delimiter='\t')
fp.writeheader()
fp.writerows(gans)
if __name__ == '__main__':
GANS = load_data()
update_readme(GANS)
update_figure(GANS)
update_github_stats(GANS)