Merge lp:~wgrant/launchpad/export-basic-binary-download-stats into lp:launchpad/db-devel

Proposed by William Grant
Status: Merged
Approved by: Michael Hudson-Doyle
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~wgrant/launchpad/export-basic-binary-download-stats
Merge into: lp:launchpad/db-devel
Diff against target: 188 lines (+99/-2)
7 files modified
lib/lp/soyuz/doc/archive.txt (+44/-0)
lib/lp/soyuz/doc/publishing.txt (+13/-0)
lib/lp/soyuz/interfaces/archive.py (+3/-0)
lib/lp/soyuz/interfaces/publishing.py (+6/-0)
lib/lp/soyuz/model/archive.py (+11/-1)
lib/lp/soyuz/model/publishing.py (+4/-0)
lib/lp/soyuz/stories/webservice/xx-binary-package-publishing.txt (+18/-1)
To merge this branch: bzr merge lp:~wgrant/launchpad/export-basic-binary-download-stats
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle Approve
Paul Hummer (community) code Needs Fixing
Review via email: mp+21544@code.launchpad.net

Commit message

Allow users to extract basic per-package PPA download counts through the webservice.

Description of the change

This simple branch adds and exports IBinaryPackagePublishingHistory.getDownloadCount(), allowing users to retrieve a simple download total for each package in a PPA. More detailed methods are coming later.

To post a comment you must log in.
Revision history for this message
Paul Hummer (rockstar) wrote :

160 +We can also retrieve the total download count for the binary in this archive.
161 +
162 + >>> webservice.named_get(
163 + ... pubs['entries'][0]['self_link'], 'getDownloadCount').jsonBody()
164 + 0
165 +

I'd feel a bit happier if we also had a case where there was a result to getDownloadCount that resulted in something other than 0. In fact, if it were a either/or, I'd prefer the non-zero test, but since you've already got this one, adding another for non-zero would be preferred.

review: Needs Fixing (code)
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

I'll send this to ec2.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/soyuz/doc/archive.txt'
2--- lib/lp/soyuz/doc/archive.txt 2010-03-15 23:01:48 +0000
3+++ lib/lp/soyuz/doc/archive.txt 2010-03-18 22:52:32 +0000
4@@ -2771,3 +2771,47 @@
5
6 >>> ppa_with_key.signing_key == cprov.archive.signing_key
7 True
8+
9+
10+== Download counts ==
11+
12+Counts of downloads per binary package release, day and country are kept
13+up to date by a log-processing script. Archives have a method to get the
14+total number of downloads for a particular binary package release.
15+
16+ >>> login('mark@example.com')
17+ >>> binaries = test_publisher.getPubBinaries(
18+ ... architecturespecific=True)
19+ >>> archive = binaries[0].archive
20+ >>> binary0, binary1 = (b.binarypackagerelease for b in binaries)
21+
22+The new packages have no downloads yet.
23+
24+ >>> print archive.getPackageDownloadTotal(binary0)
25+ 0
26+ >>> print archive.getPackageDownloadTotal(binary1)
27+ 0
28+
29+We will fake some package downloads.
30+
31+ >>> from datetime import date
32+ >>> from lp.services.worlddata.interfaces.country import ICountrySet
33+ >>> australia = getUtility(ICountrySet)['AU']
34+ >>> uk = getUtility(ICountrySet)['GB']
35+
36+ >>> archive.updatePackageDownloadCount(
37+ ... binary0, date(2010, 2, 21), None, 10)
38+ >>> archive.updatePackageDownloadCount(
39+ ... binary0, date(2010, 2, 22), uk, 5)
40+ >>> archive.updatePackageDownloadCount(
41+ ... binary0, date(2010, 2, 22), australia, 4)
42+
43+ >>> archive.updatePackageDownloadCount(
44+ ... binary1, date(2010, 2, 21), australia, 2)
45+ >>> archive.updatePackageDownloadCount(
46+ ... binary1, date(2010, 2, 21), uk, 1)
47+
48+ >>> print archive.getPackageDownloadTotal(binary0)
49+ 19
50+ >>> print archive.getPackageDownloadTotal(binary1)
51+ 3
52
53=== modified file 'lib/lp/soyuz/doc/publishing.txt'
54--- lib/lp/soyuz/doc/publishing.txt 2010-03-15 17:12:18 +0000
55+++ lib/lp/soyuz/doc/publishing.txt 2010-03-18 22:52:32 +0000
56@@ -949,6 +949,19 @@
57 >>> [pub_file.archive_url for pub_file in bpph.files]
58 [u'http://ftpmaster.internal/debian/pool/universe/m/mozilla-firefox/mozilla-firefox_0.9_i386.deb']
59
60+Binary publishing records also have a download count, which contains
61+the number of downloads of this binary package release in this archive.
62+
63+ >>> print bpph.getDownloadCount()
64+ 0
65+
66+ >>> from datetime import date
67+ >>> bpph.archive.updatePackageDownloadCount(
68+ ... bpph.binarypackagerelease, date(2010, 2, 21), None, 10)
69+
70+ >>> print bpph.getDownloadCount()
71+ 10
72+
73
74 IPublishingSet
75 ==============
76
77=== modified file 'lib/lp/soyuz/interfaces/archive.py'
78--- lib/lp/soyuz/interfaces/archive.py 2010-03-18 19:57:23 +0000
79+++ lib/lp/soyuz/interfaces/archive.py 2010-03-18 22:52:32 +0000
80@@ -662,6 +662,9 @@
81 count of the existing one by the given amount.
82 """
83
84+ def getPackageDownloadTotal(bpr):
85+ """Get the total download count for a given package."""
86+
87
88 class IArchiveView(IHasBuildRecords):
89 """Archive interface for operations restricted by view privilege."""
90
91=== modified file 'lib/lp/soyuz/interfaces/publishing.py'
92--- lib/lp/soyuz/interfaces/publishing.py 2010-02-11 12:47:50 +0000
93+++ lib/lp/soyuz/interfaces/publishing.py 2010-03-18 22:52:32 +0000
94@@ -856,6 +856,12 @@
95 representing the binaries copied to the destination location.
96 """
97
98+ @export_read_operation()
99+ def getDownloadCount():
100+ """Get the download count of this binary package in this archive.
101+
102+ This is currently only meaningful for PPAs."""
103+
104
105 class IBinaryPackagePublishingHistory(IBinaryPackagePublishingHistoryPublic,
106 IPublishingEdit):
107
108=== modified file 'lib/lp/soyuz/model/archive.py'
109--- lib/lp/soyuz/model/archive.py 2010-03-17 17:26:10 +0000
110+++ lib/lp/soyuz/model/archive.py 2010-03-18 22:52:32 +0000
111@@ -15,7 +15,7 @@
112 from sqlobject import (
113 BoolCol, ForeignKey, IntCol, StringCol)
114 from sqlobject.sqlbuilder import SQLConstant
115-from storm.expr import Or, And, Select
116+from storm.expr import Or, And, Select, Sum
117 from storm.locals import Count, Join
118 from storm.store import Store
119 from zope.component import getUtility
120@@ -1342,6 +1342,16 @@
121 else:
122 entry.count += count
123
124+ def getPackageDownloadTotal(self, bpr):
125+ """See `IArchive`."""
126+ store = Store.of(self)
127+ count = store.find(
128+ Sum(BinaryPackageReleaseDownloadCount.count),
129+ BinaryPackageReleaseDownloadCount.archive == self,
130+ BinaryPackageReleaseDownloadCount.binary_package_release == bpr,
131+ ).one()
132+ return count or 0
133+
134 def _setBuildStatuses(self, status):
135 """Update the pending Build Jobs' status for this archive."""
136
137
138=== modified file 'lib/lp/soyuz/model/publishing.py'
139--- lib/lp/soyuz/model/publishing.py 2010-03-15 10:22:34 +0000
140+++ lib/lp/soyuz/model/publishing.py 2010-03-18 22:52:32 +0000
141@@ -857,6 +857,10 @@
142 distroseries.name,
143 self.distroarchseries.architecturetag)
144
145+ def getDownloadCount(self):
146+ """See `IBinaryPackagePublishingHistory`."""
147+ return self.archive.getPackageDownloadTotal(self.binarypackagerelease)
148+
149 def buildIndexStanzaFields(self):
150 """See `IPublishing`."""
151 bpr = self.binarypackagerelease
152
153=== modified file 'lib/lp/soyuz/stories/webservice/xx-binary-package-publishing.txt'
154--- lib/lp/soyuz/stories/webservice/xx-binary-package-publishing.txt 2010-02-26 14:53:55 +0000
155+++ lib/lp/soyuz/stories/webservice/xx-binary-package-publishing.txt 2010-03-18 22:52:32 +0000
156@@ -86,6 +86,24 @@
157 self_link: u'http://.../~cprov/+archive/ppa/+binarypub/30'
158 status: u'Published'
159
160+We can also retrieve the total download count for the binary in this archive.
161+
162+ >>> webservice.named_get(
163+ ... pubs['entries'][0]['self_link'], 'getDownloadCount').jsonBody()
164+ 0
165+
166+ >>> login("foo.bar@canonical.com")
167+ >>> from datetime import date
168+ >>> from lp.soyuz.model.publishing import BinaryPackagePublishingHistory
169+ >>> bpph = BinaryPackagePublishingHistory.get(30)
170+ >>> bpph.archive.updatePackageDownloadCount(
171+ ... bpph.binarypackagerelease, date(2010, 2, 21), None, 10)
172+ >>> logout()
173+
174+ >>> webservice.named_get(
175+ ... pubs['entries'][0]['self_link'], 'getDownloadCount').jsonBody()
176+ 10
177+
178
179 Security
180 ========
181@@ -93,7 +111,6 @@
182 Create a private PPA for Celso with some binaries.
183
184 >>> login("foo.bar@canonical.com")
185-
186 >>> from zope.component import getUtility
187 >>> from lp.registry.interfaces.person import IPersonSet
188 >>> from lp.registry.interfaces.distribution import IDistributionSet

Subscribers

People subscribed via source and target branches

to status/vote changes: