-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Author stats over multiple repos #70
Open
PriitParmakson
wants to merge
5
commits into
erikbern:master
Choose a base branch
from
agiil:Author-stats-over-multiple-repos
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1ee92e6
Author stats over multiple repos
9fa9137
Integrated multi-repo option into stack_plot; added two tests.
7596c0f
Put .gitignore into wrong directory. Trying again.
190201e
Updated xvfb in travis.yml to Ubuntu 16.04 (Xenial)
d266a2a
Removed erroneus line from __init__.py
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
LOCAL* |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
|
||
import argparse, dateutil.parser, itertools, json, numpy, sys | ||
from matplotlib import pyplot | ||
from collections import defaultdict | ||
|
||
|
||
def generate_n_colors(n): | ||
|
@@ -32,8 +33,59 @@ def euclidean(a, b): | |
return colors | ||
|
||
|
||
def stack_plot(input_fn, display=False, outfile='stack_plot.png', max_n=20, normalize=False, dont_stack=False): | ||
data = json.load(open(input_fn)) # TODO do we support multiple arguments here? | ||
def stack_plot(input_fns, display=False, | ||
outfile='stack_plot.png', max_n=20, normalize=False, dont_stack=False, outmerged=False): | ||
|
||
loc = {} # Helper data structure | ||
authors = set() # All authors | ||
tss = set() # All timestamps | ||
for fn in input_fns: | ||
print('Reading %s' % fn) | ||
data = json.load(open(fn)) | ||
locr = defaultdict(defaultdict) | ||
for i, a in enumerate(data['labels']): | ||
authors.add(a) | ||
locr[a] = {} | ||
for j, t in enumerate(data['ts']): | ||
tss.add(t) | ||
locr[a][t] = data['y'][i][j] | ||
loc[fn] = locr | ||
|
||
authorss = sorted(authors) # Authors, sorted | ||
tsss = sorted(tss) # Timestamps, sorted | ||
|
||
merged = [[0 for j in range(len(tsss))] for i in range(len(authorss))] | ||
|
||
for i, r in enumerate(loc): | ||
# print("repo: ", r) | ||
for j, a in enumerate(authorss): | ||
# print(" ", a) | ||
l = 0 | ||
for k, t in enumerate(tsss): | ||
# print(r, a, t) | ||
if a in loc[r].keys(): | ||
if t in loc[r][a].keys(): | ||
l = loc[r][a][t] | ||
# print("l = ", l) | ||
merged[j][k] = merged[j][k] + l | ||
|
||
data = { | ||
'y': merged, | ||
'ts': [t for t in tsss], | ||
'labels': [a for a in authorss] | ||
} | ||
if outmerged: | ||
mergefn = 'merged.json' | ||
print('Writing data to %s' % mergefn) | ||
f = open(mergefn, 'w') | ||
json.dump( | ||
{ | ||
'y': merged, | ||
'ts': [t for t in tsss], | ||
'labels': [a for a in authorss] | ||
}, f) | ||
f.close() | ||
|
||
y = numpy.array(data['y']) | ||
if y.shape[0] > max_n: | ||
js = sorted(range(len(data['labels'])), key=lambda j: max(y[j]), reverse=True) | ||
|
@@ -74,7 +126,8 @@ def stack_plot_cmdline(): | |
parser.add_argument('--max-n', default=20, type=int, help='Max number of dataseries (will roll everything else into "other") (default: %(default)s)') | ||
parser.add_argument('--normalize', action='store_true', help='Normalize the plot to 100%%') | ||
parser.add_argument('--dont-stack', action='store_true', help='Don\'t stack plot') | ||
parser.add_argument('input_fn') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test |
||
parser.add_argument('--outmerged', action='store_true', help='Output merged data to merged.json') | ||
parser.add_argument('input_fns', nargs='*') | ||
kwargs = vars(parser.parse_args()) | ||
|
||
stack_plot(**kwargs) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"y": [ | ||
[100, 170, 600, 400, 700], | ||
[0, 0, 150, 150, 300], | ||
[0, 50, 150, 200, 200] | ||
], | ||
"ts": [ | ||
"2019-01-01T07:00:00", | ||
"2019-02-01T07:00:00", | ||
"2019-04-01T08:00:00", | ||
"2019-06-01T08:00:00", | ||
"2019-08-01T08:00:00" | ||
], | ||
"labels": [ | ||
"Author A", | ||
"Author B", | ||
"Author C" | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"y": [ | ||
[100, 200, 500], | ||
[0, 150, 300] | ||
], | ||
"ts": [ | ||
"2019-01-01T07:00:00", | ||
"2019-04-01T08:00:00", | ||
"2019-08-01T08:00:00" | ||
], | ||
"labels": [ | ||
"Author A", | ||
"Author B" | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"y": [ | ||
[70, 400, 200], | ||
[50, 150, 200] | ||
], | ||
"ts": [ | ||
"2019-02-01T07:00:00", | ||
"2019-04-01T08:00:00", | ||
"2019-06-01T08:00:00" | ||
], | ||
"labels": [ | ||
"Author A", | ||
"Author C" | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Tests for stack_plot | ||
# | ||
# To run tests: | ||
# (1) ensure that git-of-theuseus in installed | ||
# (2) go to folder tests and | ||
# (3) python tests.py | ||
|
||
import json | ||
from git_of_theseus import stack_plot | ||
|
||
print('Testing stack_plot...') | ||
|
||
print('Test 1 - Run stack_plot for repos 1 and 2') | ||
out_fn = 'stack_plot.png' | ||
in_fns = ['test_data_repo_1.json', 'test_data_repo_2.json'] | ||
|
||
stack_plot(outfile=out_fn, input_fns=in_fns, outmerged=True) | ||
|
||
# merged.json and test_data_merged.json must have equal JSON contents. | ||
if json.load(open('merged.json')) == json.load(open('test_data_merged_1_2.json')): | ||
print('Test succeeded') | ||
else: | ||
print('Test failed') | ||
|
||
print('Test 2 - Run stack_plot for repo 1') | ||
out_fn = 'stack_plot.png' | ||
in_fns = ['test_data_repo_1.json'] | ||
|
||
stack_plot(outfile=out_fn, input_fns=in_fns, outmerged=True) | ||
|
||
# merged.json and test_data_merged.json must have equal JSON contents. | ||
if json.load(open('merged.json')) == json.load(open('test_data_repo_1.json')): | ||
print('Test succeeded') | ||
else: | ||
print('Test failed') |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.