Merge "Added getting group stats by weeks"
This commit is contained in:
commit
03a312a2ae
@ -194,6 +194,45 @@ def get_activity(records, start_record, page_size, query_message=None):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def week_to_timestamp(week):
|
||||||
|
return week * 7 * 24 * 3600 + 3 * 24 * 3600
|
||||||
|
|
||||||
|
|
||||||
|
def get_commits_by_week(records):
|
||||||
|
raw_weeks = _get_commits_by_week(records)
|
||||||
|
dict_weeks = [
|
||||||
|
{'w': week_to_timestamp(k), 'c': raw_weeks[k]}
|
||||||
|
for k in raw_weeks
|
||||||
|
]
|
||||||
|
sorted_weeks = sorted(dict_weeks, key=lambda w: w['w'])
|
||||||
|
|
||||||
|
result = {
|
||||||
|
'total': sum(raw_weeks.values()),
|
||||||
|
'weeks': sorted_weeks}
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def _get_commits_by_week(record_iterator):
|
||||||
|
records = list(record_iterator)
|
||||||
|
weeks = {}
|
||||||
|
|
||||||
|
if len(records) == 0:
|
||||||
|
return weeks
|
||||||
|
|
||||||
|
max_week = min_week = records[0].week
|
||||||
|
for record in records:
|
||||||
|
week = record.week
|
||||||
|
min_week = min(min_week, week)
|
||||||
|
max_week = max(max_week, week)
|
||||||
|
weeks[week] = weeks.get(week, 0) + 1
|
||||||
|
|
||||||
|
for week in range(min_week, max_week + 1):
|
||||||
|
if week not in weeks:
|
||||||
|
weeks[week] = 0
|
||||||
|
|
||||||
|
return weeks
|
||||||
|
|
||||||
|
|
||||||
def get_contribution_summary(records):
|
def get_contribution_summary(records):
|
||||||
marks = dict((m, 0) for m in [-2, -1, 0, 1, 2, 'A', 'WIP', 'x', 's'])
|
marks = dict((m, 0) for m in [-2, -1, 0, 1, 2, 'A', 'WIP', 'x', 's'])
|
||||||
commit_count = 0
|
commit_count = 0
|
||||||
|
@ -266,6 +266,15 @@ def get_activity_json(records, **kwargs):
|
|||||||
query_message)
|
query_message)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/api/1.0/commits_by_week')
|
||||||
|
@decorators.exception_handler()
|
||||||
|
@decorators.response()
|
||||||
|
@decorators.jsonify('stats')
|
||||||
|
@decorators.record_filter()
|
||||||
|
def get_commits_by_week(records, **kwargs):
|
||||||
|
return helpers.get_commits_by_week(records)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/1.0/contribution')
|
@app.route('/api/1.0/contribution')
|
||||||
@decorators.exception_handler()
|
@decorators.exception_handler()
|
||||||
@decorators.response()
|
@decorators.response()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user