Last active
January 3, 2016 08:59
-
-
Save Ms2ger/8440074 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import json | |
import matplotlib | |
matplotlib.use('Agg') | |
import matplotlib.pyplot as plt | |
def parse_time(s): | |
return datetime.datetime.strptime(s, "%Y-%m-%d %H:%M:%S") | |
def parse_date(s): | |
return datetime.datetime.strptime(s, "%Y-%m-%d") | |
with open('open_prs.json', 'r') as fh: | |
open_prs = json.load(fh) | |
with open('closed_prs.json', 'r') as fh: | |
closed_prs = json.load(fh) | |
changes = {} | |
for pr in open_prs: | |
opened = parse_time(pr["created"]) | |
changes.setdefault(opened, []).append((pr["id"], +1)) | |
for pr in closed_prs: | |
opened = parse_time(pr["created"]) | |
closed = parse_time(pr["closed"]) | |
changes.setdefault(opened, []).append((pr["id"], +1)) | |
changes.setdefault(closed, []).append((pr["id"], -1)) | |
def get_numbers(): | |
number_open_prs = 0 | |
number_prs = 0 | |
for time, prs in sorted(changes.iteritems()): | |
number_open_prs += sum(change for _, change in prs) | |
number_prs += sum(change for _, change in prs if change > 0) | |
yield time, number_open_prs, number_prs | |
#print "%s: %s\t%s" % (time, prs, number_open_prs) | |
with open('testtwf.json', 'r') as fh: | |
events = json.load(fh) | |
def get_dates(): | |
for start, end, _ in events: | |
yield parse_time(start + " 00:00:00") | |
yield parse_time(end + " 23:59:59") | |
data_points = zip(*get_numbers()) | |
plt.plot(data_points[0], data_points[1]) | |
plt.plot(data_points[0], data_points[2]) | |
plt.ylabel('Number of (open) pull requests') | |
plt.vlines(list(get_dates()), 0, data_points[-1][-1], linestyle='dotted') | |
plt.savefig('prs.svg') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function, unicode_literals | |
import json | |
from github import Github | |
TOKEN = '...' | |
repo = Github(TOKEN).get_user('w3c').get_repo('web-platform-tests') | |
open_prs = [{ "id": pr.number, "created": str(pr.created_at) } for pr in repo.get_pulls('open')] | |
closed_prs = [{ "id": pr.number, "created": str(pr.created_at), "closed": str(pr.closed_at)} for pr in repo.get_pulls('closed')] | |
with open('open_prs.json', 'w') as fh: | |
json.dump(open_prs, fh) | |
with open('closed_prs.json', 'w') as fh: | |
json.dump(closed_prs, fh) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
["2013-11-09", "2013-11-09", "Shenzhen, China"], | |
["2013-08-17", "2013-08-18", "Shanghai, China"], | |
["2013-06-07", "2013-06-08", "Tokyo, Japan"], | |
["2013-04-12", "2013-04-13", "Seattle, WA, USA"], | |
["2013-02-08", "2013-02-09", "Sydney, Australia"] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment