Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7f32e37

Browse files
committed
Update github3.repos.stats for consistency
1 parentf93ca04 commit7f32e37

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__importunicode_literals
34

4-
fromdatetimeimportdatetime
5+
importdatetime
56

6-
from ..importusers
7+
importdateutil.tz
78

8-
from ..modelsimportGitHubCore
9+
from ..importmodels
10+
from ..importusers
911

1012

1113
defalternate_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-
classContributorStats(GitHubCore):
34+
classContributorStats(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-
ifself.alt_weeks:
45-
self.alt_weeks= [alternate_week(w)forwinself.weeks]
80+
alt_weeks=self.weeks
81+
ifalt_weeks:
82+
alt_weeks= [alternate_week(w)forwinself.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)

[8]ページ先頭

©2009-2025 Movatter.jp