forked from sigmavirus24/github3.py
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstats.py
More file actions
40 lines (31 loc) · 1.42 KB
/
Copy pathstats.py
File metadata and controls
40 lines (31 loc) · 1.42 KB
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
# -*- coding: utf-8 -*-
from datetime import datetime
from github3.models import GitHubCore
from github3.users import User
def alternate_week(week):
return {
'start of week': datetime.fromtimestamp(int(week['w'])),
'additions': week['a'],
'deletions': week['d'],
'commits': week['c'],
}
class ContributorStats(GitHubCore):
"""This object provides easy access to information returned by the
statistics section of the API.
See http://developer.github.com/v3/repos/statistics/ for specifics.
"""
def __init__(self, stats_object, session=None):
super(ContributorStats, self).__init__(stats_object, session)
#: Contributor in particular that this relates to
self.author = User(stats_object.get('author', {}), session)
#: Total number of commits authored by ``author``.
self.total = stats_object.get('total')
#: List of weekly dictionaries.
self.weeks = stats_object.get('weeks', [])
#: Alternative collection of weekly dictionaries
#: This provides a datetime object and easy to remember keys for each
#: element in the list. 'w' -> 'start of week', 'a' -> 'Number of additions',
#: 'd' -> 'Number of deletions', 'c' -> 'Number of commits'
self.alt_weeks = [alternate_week(w) for w in self.weeks]
def __repr__(self):
return '<Contributor Statistics [{0}]>'.format(self.author)