Merge lp:~adeuring/charmworld/1206158-dl-count-by-week-half-year into lp:~juju-jitsu/charmworld/trunk

Proposed by Abel Deuring
Status: Merged
Approved by: Abel Deuring
Approved revision: 332
Merged at revision: 331
Proposed branch: lp:~adeuring/charmworld/1206158-dl-count-by-week-half-year
Merge into: lp:~juju-jitsu/charmworld/trunk
Diff against target: 190 lines (+82/-7)
6 files modified
charmworld/jobs/ingest.py (+4/-0)
charmworld/jobs/tests/test_cstat.py (+31/-6)
charmworld/models.py (+16/-0)
charmworld/templates/charm.pt (+11/-1)
charmworld/tests/test_models.py (+18/-0)
charmworld/views/tests/test_charms.py (+2/-0)
To merge this branch: bzr merge lp:~adeuring/charmworld/1206158-dl-count-by-week-half-year
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve
Review via email: mp+178265@code.launchpad.net

Commit message

show downloads in past 7, 30, 180 days on the charm details page.

Description of the change

This brnach fixes bug 1206158. "On manage.jujucharms.com show download breakdown by last 30 days, last week". There was the additional suggestion to also show downloads in the past half year; I added that as well as the total download count.

The changes are straightforward:

- Get the additional download numbers from the charm store;
- add two new properties to class Charm
- show the download numbers in the charm details template.

(I shortly considered to just store all download details provided by the charm store in the MongoDB and to calculate the actually required numbers in Charm.downloads_in_past_7_days etc, but I think that the additional changes and tests needed for such a change are not reasonable, while we have a few other important bugs.)

To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmworld/jobs/ingest.py'
2--- charmworld/jobs/ingest.py 2013-07-31 14:41:29 +0000
3+++ charmworld/jobs/ingest.py 2013-08-02 11:21:27 +0000
4@@ -674,6 +674,10 @@
5 charm['downloads_in_past_30_days'] = count
6 count = store.get_download_counts(charm)
7 charm['downloads'] = count[0][0] if count else 0
8+ count = store.count_downloads_in_days(charm, 7, date.today())
9+ charm['downloads_in_past_7_days'] = count
10+ count = store.count_downloads_in_days(charm, 182, date.today())
11+ charm['downloads_in_past_half_year'] = count
12
13
14 def update_date_created(charm, log):
15
16=== modified file 'charmworld/jobs/tests/test_cstat.py'
17--- charmworld/jobs/tests/test_cstat.py 2013-07-04 18:48:48 +0000
18+++ charmworld/jobs/tests/test_cstat.py 2013-08-02 11:21:27 +0000
19@@ -1,11 +1,15 @@
20 # Copyright 2012, 2013 Canonical Ltd. This software is licensed under the
21 # GNU Affero General Public License version 3 (see the file LICENSE).
22
23+from datetime import datetime
24 import logging
25
26 from pyelasticsearch import ElasticSearch
27 from requests import Response
28-
29+from urlparse import (
30+ parse_qsl,
31+ urlparse,
32+)
33 from charmworld.charmstore import CharmStore
34 from charmworld.jobs.cstat import update_counts
35 from charmworld.models import CharmSource
36@@ -32,9 +36,26 @@
37 @staticmethod
38 def send(request):
39 response = Response()
40- if ('start' in request.url):
41- response._content = ('[["2010-12-24", 4],'
42- ' ["2010-12-25", 1]]')
43+ params = dict(parse_qsl(urlparse(request.url).query))
44+ if ('start' in params):
45+ start = datetime.strptime(params['start'], '%Y-%m-%d')
46+ end = datetime.strptime(params['end'], '%Y-%m-%d')
47+ days = (end - start).days
48+ if days == 7:
49+ response._content = ('[["2010-12-24", 4],'
50+ ' ["2010-12-25", 1]]')
51+ elif days == 30:
52+ response._content = ('[["2010-12-24", 10],'
53+ ' ["2010-12-24", 4],'
54+ ' ["2010-12-25", 1]]')
55+ elif days == 182:
56+ response._content = ('[["2010-12-23", 10],'
57+ ' ["2010-12-24", 4],'
58+ ' ["2010-12-25", 1]]')
59+ response._content = ('[["2010-12-22", 100],'
60+ ' ["2010-12-23", 10],'
61+ ' ["2010-12-24", 4],'
62+ ' ["2010-12-25", 1]]')
63 else:
64 response._content = '[[25]]'
65 return response
66@@ -42,10 +63,14 @@
67 store.session = FakeSession
68 update_counts(CharmSource(self.db, index_client), store, log)
69 db_charm = self.db.charms.find_one({'_id': charm_id})
70- self.assertEqual(5, db_charm['downloads_in_past_30_days'])
71+ self.assertEqual(5, db_charm['downloads_in_past_7_days'])
72+ self.assertEqual(15, db_charm['downloads_in_past_30_days'])
73+ self.assertEqual(115, db_charm['downloads_in_past_half_year'])
74 self.assertEqual(25, db_charm['downloads'])
75 index_charm = index_client.get(charm_id)
76- self.assertEqual(5, index_charm['downloads_in_past_30_days'])
77+ self.assertEqual(5, index_charm['downloads_in_past_7_days'])
78+ self.assertEqual(15, index_charm['downloads_in_past_30_days'])
79+ self.assertEqual(115, index_charm['downloads_in_past_half_year'])
80 self.assertEqual(25, index_charm['downloads'])
81
82 def test_update_no_index(self):
83
84=== modified file 'charmworld/models.py'
85--- charmworld/models.py 2013-07-31 17:02:52 +0000
86+++ charmworld/models.py 2013-08-02 11:21:27 +0000
87@@ -226,7 +226,9 @@
88
89 # Provided by the charm store job.
90 'downloads': 0,
91+ 'downloads_in_past_7_days': 0,
92 'downloads_in_past_30_days': 0,
93+ 'downloads_in_past_half_year': 0,
94 'store_data': {},
95 'store_url': '',
96
97@@ -444,6 +446,13 @@
98 return self._representation['downloads']
99
100 @property
101+ def downloads_in_past_7_days(self):
102+ """The number of times the charm was downloaded in the past 7 days.
103+
104+ The number comes from the store. It does not equate to deploys."""
105+ return self._representation['downloads_in_past_7_days']
106+
107+ @property
108 def downloads_in_past_30_days(self):
109 """The number of times the charm was downloaded in the past 30 days.
110
111@@ -451,6 +460,13 @@
112 return self._representation['downloads_in_past_30_days']
113
114 @property
115+ def downloads_in_past_half_year(self):
116+ """The number of times the charm was downloaded in the past half year.
117+
118+ The number comes from the store. It does not equate to deploys."""
119+ return self._representation['downloads_in_past_half_year']
120+
121+ @property
122 def proof(self):
123 """The dict charm's proof warnings and errors."""
124 return self._representation['proof']
125
126=== modified file 'charmworld/templates/charm.pt'
127--- charmworld/templates/charm.pt 2013-07-08 18:49:08 +0000
128+++ charmworld/templates/charm.pt 2013-08-02 11:21:27 +0000
129@@ -92,7 +92,17 @@
130 <br />
131 lp:${charm.branch_spec}
132 </div>
133-
134+ <div class="field">
135+ <b>Downloads</b><br/>
136+ in past 7 days:
137+ <span tal:replace="charm.downloads_in_past_7_days"/><br/>
138+ in past 30 days:
139+ <span tal:replace="charm.downloads_in_past_30_days"/><br/>
140+ in past half year:
141+ <span tal:replace="charm.downloads_in_past_half_year"/><br/>
142+ all:
143+ <span tal:replace="charm.downloads"/>
144+ </div>
145 </div>
146
147 <div class="span3">
148
149=== modified file 'charmworld/tests/test_models.py'
150--- charmworld/tests/test_models.py 2013-07-31 17:02:52 +0000
151+++ charmworld/tests/test_models.py 2013-08-02 11:21:27 +0000
152@@ -252,6 +252,24 @@
153 charm = Charm({})
154 self.assertEquals(0, charm.downloads_in_past_30_days)
155
156+ def test_downloads_in_past_7_days(self):
157+ # The downloads_in_past_7_days property is an int.
158+ charm_data = {'downloads_in_past_7_days': 7}
159+ charm = Charm(charm_data)
160+ self.assertEqual(7, charm.downloads_in_past_7_days)
161+ # The default is zero.
162+ charm = Charm({})
163+ self.assertEquals(0, charm.downloads_in_past_7_days)
164+
165+ def test_downloads_in_past_half_year(self):
166+ # The downloads_in_past_half_year property is an int.
167+ charm_data = {'downloads_in_past_half_year': 180}
168+ charm = Charm(charm_data)
169+ self.assertEqual(180, charm.downloads_in_past_half_year)
170+ # The default is zero.
171+ charm = Charm({})
172+ self.assertEquals(0, charm.downloads_in_past_half_year)
173+
174 def test_store_url(self):
175 # The store_url property is a string.
176 charm_data = {'store_url': 'cs:~owner/series/name-1'}
177
178=== modified file 'charmworld/views/tests/test_charms.py'
179--- charmworld/views/tests/test_charms.py 2013-07-19 12:51:01 +0000
180+++ charmworld/views/tests/test_charms.py 2013-08-02 11:21:27 +0000
181@@ -64,7 +64,9 @@
182 },
183 'doctype': 'charm',
184 'downloads': 0,
185+ 'downloads_in_past_7_days': 0,
186 'downloads_in_past_30_days': 0,
187+ 'downloads_in_past_half_year': 0,
188 'files': {
189 'readme': {
190 'subdir': '',

Subscribers

People subscribed via source and target branches