Skip to content

Commit 7f32e37

Browse files
committed
Update github3.repos.stats for consistency
1 parent f93ca04 commit 7f32e37

File tree

1 file changed

+61
-23
lines changed

1 file changed

+61
-23
lines changed

github3/repos/stats.py

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,86 @@
11
# -*- coding: utf-8 -*-
2+
"""Repository and contributor stats logic."""
23
from __future__ import unicode_literals
34

4-
from datetime import datetime
5+
import datetime
56

6-
from .. import users
7+
import dateutil.tz
78

8-
from ..models import GitHubCore
9+
from .. import models
10+
from .. import users
911

1012

1113
def alternate_week(week):
14+
"""Map GitHub 'short' data to usable data.
15+
16+
.. note:: This is not meant for public consumption
17+
18+
:param dict week:
19+
The week's statistical data from GitHub
20+
:returns:
21+
Huamnized week statistical data
22+
:rtype:
23+
dict
24+
"""
25+
start_of_week = datetime.datetime.utcfromtimestamp(int(week['w']))
1226
return {
13-
'start of week': datetime.fromtimestamp(int(week['w'])),
27+
'start of week': start_of_week.replace(tzinfo=dateutil.tz.tzutc()),
1428
'additions': week['a'],
1529
'deletions': week['d'],
1630
'commits': week['c'],
1731
}
1832

1933

20-
class ContributorStats(GitHubCore):
34+
class ContributorStats(models.GitHubCore):
35+
"""Representation of a user's contributor statistics to a repository.
36+
37+
See also http://developer.github.com/v3/repos/statistics/
38+
39+
This object has the following attributes:
40+
41+
.. attribute:: author
42+
43+
A :class:`~github3.users.ShortUser` representing the contributor
44+
whose stats this object represents.
45+
46+
.. attribute:: total
47+
48+
The total number of commits authored by :attr:`author`.
49+
50+
.. attribute:: weeks
51+
52+
A list of dictionaries containing weekly statistical data.
53+
54+
.. attribute:: alternate_weeks
55+
56+
.. note::
57+
58+
:mod:`github3` generates this data for a more humane interface
59+
to the data in :attr:`weeks`.
60+
61+
A list of dictionaries that provide an easier to remember set of
62+
keys as well as a :class:`~datetime.datetime` object representing the
63+
start of the week. The dictionary looks vaguely like:
2164
22-
"""This object provides easy access to information returned by the
23-
statistics section of the API.
65+
.. code-block:: python
2466
25-
See http://developer.github.com/v3/repos/statistics/ for specifics.
67+
{
68+
'start of week': datetime(2013, 5, 5, 5, 0, tzinfo=tzutc())
69+
'additions': 100,
70+
'deletions': 150,
71+
'commits': 5,
72+
}
2673
2774
"""
2875

2976
def _update_attributes(self, stats_object):
30-
#: Contributor in particular that this relates to
31-
self.author = self._class_attribute(
32-
stats_object, 'author', users.ShortUser, self
33-
)
34-
#: Total number of commits authored by ``author``.
35-
self.total = self._get_attribute(stats_object, 'total')
36-
#: List of weekly dictionaries.
77+
self.author = users.ShortUser(stats_object['author'], self)
78+
self.total = stats_object['total']
3779
self.weeks = self._get_attribute(stats_object, 'weeks', [])
38-
#: Alternative collection of weekly dictionaries
39-
#: This provides a datetime object and easy to remember keys for each
40-
#: element in the list.
41-
#: 'w' -> 'start of week', 'a' -> 'Number of additions',
42-
#: 'd' -> 'Number of deletions', 'c' -> 'Number of commits'
43-
self.alt_weeks = self.weeks
44-
if self.alt_weeks:
45-
self.alt_weeks = [alternate_week(w) for w in self.weeks]
80+
alt_weeks = self.weeks
81+
if alt_weeks:
82+
alt_weeks = [alternate_week(w) for w in self.weeks]
83+
self.alternate_weeks = self.alt_weeks = alt_weeks
4684

4785
def _repr(self):
4886
return '<Contributor Statistics [{0}]>'.format(self.author)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy