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
=== modified file 'lib/lp/soyuz/doc/archive.txt'
--- lib/lp/soyuz/doc/archive.txt 2010-03-15 23:01:48 +0000
+++ lib/lp/soyuz/doc/archive.txt 2010-03-18 22:52:32 +0000
@@ -2771,3 +2771,47 @@
27712771
2772 >>> ppa_with_key.signing_key == cprov.archive.signing_key2772 >>> ppa_with_key.signing_key == cprov.archive.signing_key
2773 True2773 True
2774
2775
2776== Download counts ==
2777
2778Counts of downloads per binary package release, day and country are kept
2779up to date by a log-processing script. Archives have a method to get the
2780total number of downloads for a particular binary package release.
2781
2782 >>> login('mark@example.com')
2783 >>> binaries = test_publisher.getPubBinaries(
2784 ... architecturespecific=True)
2785 >>> archive = binaries[0].archive
2786 >>> binary0, binary1 = (b.binarypackagerelease for b in binaries)
2787
2788The new packages have no downloads yet.
2789
2790 >>> print archive.getPackageDownloadTotal(binary0)
2791 0
2792 >>> print archive.getPackageDownloadTotal(binary1)
2793 0
2794
2795We will fake some package downloads.
2796
2797 >>> from datetime import date
2798 >>> from lp.services.worlddata.interfaces.country import ICountrySet
2799 >>> australia = getUtility(ICountrySet)['AU']
2800 >>> uk = getUtility(ICountrySet)['GB']
2801
2802 >>> archive.updatePackageDownloadCount(
2803 ... binary0, date(2010, 2, 21), None, 10)
2804 >>> archive.updatePackageDownloadCount(
2805 ... binary0, date(2010, 2, 22), uk, 5)
2806 >>> archive.updatePackageDownloadCount(
2807 ... binary0, date(2010, 2, 22), australia, 4)
2808
2809 >>> archive.updatePackageDownloadCount(
2810 ... binary1, date(2010, 2, 21), australia, 2)
2811 >>> archive.updatePackageDownloadCount(
2812 ... binary1, date(2010, 2, 21), uk, 1)
2813
2814 >>> print archive.getPackageDownloadTotal(binary0)
2815 19
2816 >>> print archive.getPackageDownloadTotal(binary1)
2817 3
27742818
=== modified file 'lib/lp/soyuz/doc/publishing.txt'
--- lib/lp/soyuz/doc/publishing.txt 2010-03-15 17:12:18 +0000
+++ lib/lp/soyuz/doc/publishing.txt 2010-03-18 22:52:32 +0000
@@ -949,6 +949,19 @@
949 >>> [pub_file.archive_url for pub_file in bpph.files]949 >>> [pub_file.archive_url for pub_file in bpph.files]
950 [u'http://ftpmaster.internal/debian/pool/universe/m/mozilla-firefox/mozilla-firefox_0.9_i386.deb']950 [u'http://ftpmaster.internal/debian/pool/universe/m/mozilla-firefox/mozilla-firefox_0.9_i386.deb']
951951
952Binary publishing records also have a download count, which contains
953the number of downloads of this binary package release in this archive.
954
955 >>> print bpph.getDownloadCount()
956 0
957
958 >>> from datetime import date
959 >>> bpph.archive.updatePackageDownloadCount(
960 ... bpph.binarypackagerelease, date(2010, 2, 21), None, 10)
961
962 >>> print bpph.getDownloadCount()
963 10
964
952965
953IPublishingSet966IPublishingSet
954==============967==============
955968
=== modified file 'lib/lp/soyuz/interfaces/archive.py'
--- lib/lp/soyuz/interfaces/archive.py 2010-03-18 19:57:23 +0000
+++ lib/lp/soyuz/interfaces/archive.py 2010-03-18 22:52:32 +0000
@@ -662,6 +662,9 @@
662 count of the existing one by the given amount.662 count of the existing one by the given amount.
663 """663 """
664664
665 def getPackageDownloadTotal(bpr):
666 """Get the total download count for a given package."""
667
665668
666class IArchiveView(IHasBuildRecords):669class IArchiveView(IHasBuildRecords):
667 """Archive interface for operations restricted by view privilege."""670 """Archive interface for operations restricted by view privilege."""
668671
=== modified file 'lib/lp/soyuz/interfaces/publishing.py'
--- lib/lp/soyuz/interfaces/publishing.py 2010-02-11 12:47:50 +0000
+++ lib/lp/soyuz/interfaces/publishing.py 2010-03-18 22:52:32 +0000
@@ -856,6 +856,12 @@
856 representing the binaries copied to the destination location.856 representing the binaries copied to the destination location.
857 """857 """
858858
859 @export_read_operation()
860 def getDownloadCount():
861 """Get the download count of this binary package in this archive.
862
863 This is currently only meaningful for PPAs."""
864
859865
860class IBinaryPackagePublishingHistory(IBinaryPackagePublishingHistoryPublic,866class IBinaryPackagePublishingHistory(IBinaryPackagePublishingHistoryPublic,
861 IPublishingEdit):867 IPublishingEdit):
862868
=== modified file 'lib/lp/soyuz/model/archive.py'
--- lib/lp/soyuz/model/archive.py 2010-03-17 17:26:10 +0000
+++ lib/lp/soyuz/model/archive.py 2010-03-18 22:52:32 +0000
@@ -15,7 +15,7 @@
15from sqlobject import (15from sqlobject import (
16 BoolCol, ForeignKey, IntCol, StringCol)16 BoolCol, ForeignKey, IntCol, StringCol)
17from sqlobject.sqlbuilder import SQLConstant17from sqlobject.sqlbuilder import SQLConstant
18from storm.expr import Or, And, Select18from storm.expr import Or, And, Select, Sum
19from storm.locals import Count, Join19from storm.locals import Count, Join
20from storm.store import Store20from storm.store import Store
21from zope.component import getUtility21from zope.component import getUtility
@@ -1342,6 +1342,16 @@
1342 else:1342 else:
1343 entry.count += count1343 entry.count += count
13441344
1345 def getPackageDownloadTotal(self, bpr):
1346 """See `IArchive`."""
1347 store = Store.of(self)
1348 count = store.find(
1349 Sum(BinaryPackageReleaseDownloadCount.count),
1350 BinaryPackageReleaseDownloadCount.archive == self,
1351 BinaryPackageReleaseDownloadCount.binary_package_release == bpr,
1352 ).one()
1353 return count or 0
1354
1345 def _setBuildStatuses(self, status):1355 def _setBuildStatuses(self, status):
1346 """Update the pending Build Jobs' status for this archive."""1356 """Update the pending Build Jobs' status for this archive."""
13471357
13481358
=== modified file 'lib/lp/soyuz/model/publishing.py'
--- lib/lp/soyuz/model/publishing.py 2010-03-15 10:22:34 +0000
+++ lib/lp/soyuz/model/publishing.py 2010-03-18 22:52:32 +0000
@@ -857,6 +857,10 @@
857 distroseries.name,857 distroseries.name,
858 self.distroarchseries.architecturetag)858 self.distroarchseries.architecturetag)
859859
860 def getDownloadCount(self):
861 """See `IBinaryPackagePublishingHistory`."""
862 return self.archive.getPackageDownloadTotal(self.binarypackagerelease)
863
860 def buildIndexStanzaFields(self):864 def buildIndexStanzaFields(self):
861 """See `IPublishing`."""865 """See `IPublishing`."""
862 bpr = self.binarypackagerelease866 bpr = self.binarypackagerelease
863867
=== modified file 'lib/lp/soyuz/stories/webservice/xx-binary-package-publishing.txt'
--- lib/lp/soyuz/stories/webservice/xx-binary-package-publishing.txt 2010-02-26 14:53:55 +0000
+++ lib/lp/soyuz/stories/webservice/xx-binary-package-publishing.txt 2010-03-18 22:52:32 +0000
@@ -86,6 +86,24 @@
86 self_link: u'http://.../~cprov/+archive/ppa/+binarypub/30'86 self_link: u'http://.../~cprov/+archive/ppa/+binarypub/30'
87 status: u'Published'87 status: u'Published'
8888
89We can also retrieve the total download count for the binary in this archive.
90
91 >>> webservice.named_get(
92 ... pubs['entries'][0]['self_link'], 'getDownloadCount').jsonBody()
93 0
94
95 >>> login("foo.bar@canonical.com")
96 >>> from datetime import date
97 >>> from lp.soyuz.model.publishing import BinaryPackagePublishingHistory
98 >>> bpph = BinaryPackagePublishingHistory.get(30)
99 >>> bpph.archive.updatePackageDownloadCount(
100 ... bpph.binarypackagerelease, date(2010, 2, 21), None, 10)
101 >>> logout()
102
103 >>> webservice.named_get(
104 ... pubs['entries'][0]['self_link'], 'getDownloadCount').jsonBody()
105 10
106
89107
90Security108Security
91========109========
@@ -93,7 +111,6 @@
93Create a private PPA for Celso with some binaries.111Create a private PPA for Celso with some binaries.
94112
95 >>> login("foo.bar@canonical.com")113 >>> login("foo.bar@canonical.com")
96
97 >>> from zope.component import getUtility114 >>> from zope.component import getUtility
98 >>> from lp.registry.interfaces.person import IPersonSet115 >>> from lp.registry.interfaces.person import IPersonSet
99 >>> from lp.registry.interfaces.distribution import IDistributionSet116 >>> from lp.registry.interfaces.distribution import IDistributionSet

Subscribers

People subscribed via source and target branches

to status/vote changes: