120
120
You will normally want to get the total count counted in the database
121
rather than waste transmittion time to calculate the rows client side:
121
rather than waste transmittion time to calculate the rows client side.
122
Note that sum() will return None if there are no matching rows, so we
123
need to cope with that:
125
127
... BugSummary.product == prod_a,
126
... BugSummary.tag == None).sum(BugSummary.count)
128
... BugSummary.tag == None).sum(BugSummary.count) or 0
131
133
... BugSummary.product == prod_a,
132
... BugSummary.tag == u't-a').sum(BugSummary.count)
134
... BugSummary.tag == u't-a').sum(BugSummary.count) or 0
135
137
If you neglect to specify the tag clause, you will get an incorrect
168
170
... BugSummary.product == prod_a,
169
171
... BugSummary.status == BugTaskStatus.NEW,
170
172
... BugSummary.milestone == None,
171
... BugSummary.tag == None).sum(BugSummary.count)
173
... BugSummary.tag == None).sum(BugSummary.count) or 0
174
176
Number of bugs targetted to prod_a, grouped by milestone:
216
218
x ps-b x x x x New x 1
222
Distribution Bug Counts
223
-----------------------
225
Querying for Distribution bug count information is similar to querying
226
for Product information. Firstly, of course, you need to match on the
227
distribution column instead of the product column. The second difference
228
is you also have the sourcepackagename column to deal with, which acts
231
>>> distribution = factory.makeDistribution(name='di-a')
232
>>> package = factory.makeDistributionSourcePackage(
233
... distribution=distribution, sourcepackagename='sp-a')
235
>>> bug = factory.makeBug(
236
... distribution=distribution, status=BugTaskStatus.CONFIRMED)
237
>>> bug_task = factory.makeBugTask(target=package) # status is NEW
239
>>> print_find(BugSummary.distribution == distribution)
240
---------------------------------------------------
241
prod ps dist ds spn tag status msto #
242
---------------------------------------------------
243
x x di-a x sp-a x New x 1
244
x x di-a x x x New x 1
245
x x di-a x x x Confirmed x 1
249
How many bugs targetted to a distribution:
253
... BugSummary.distribution == distribution,
254
... BugSummary.sourcepackagename == None,
255
... BugSummary.tag == None).sum(BugSummary.count) or 0
258
How many NEW bugs targetted to a distribution:
262
... BugSummary.distribution == distribution,
263
... BugSummary.sourcepackagename == None,
264
... BugSummary.status == BugTaskStatus.NEW,
265
... BugSummary.tag == None).sum(BugSummary.count) or 0
268
How many bugs targetted to a particular sourcepackage in a distribution.
272
... BugSummary.distribution == distribution,
273
... BugSummary.sourcepackagename == package.sourcepackagename,
274
... BugSummary.tag == None).sum(BugSummary.count) or 0
277
How many Confirmed bugs for a distribution have not been linked to a
278
sourcepackage. This is tricky, as we cannot directly ask for counts
279
not linked to a sourcepackage. We can however ask for counts linked to
280
a sourcepackage, so we subtract this count from the total number of bugs
281
targetted to the distribution:
283
>>> from storm.expr import SQL
286
... BugSummary.distribution == distribution,
287
... BugSummary.status == BugTaskStatus.CONFIRMED,
288
... BugSummary.tag == None).sum(SQL("""
289
... CASE WHEN sourcepackagename IS NULL THEN count ELSE -count END