7675.470.1
by Tom Berger
Add a view for displaying bug heat as four flames; use this view to display the bug heat on the bug index page. |
1 |
= Bug heat view = |
2 |
||
3 |
Bug heat is represented as four flame icons. The quantity of flames that are |
|
7675.554.4
by Tom Berger
Scale the value used for calculating the number of heat flames to display so that it produces a reasonable amount of flames for the hottest bugs. |
4 |
coloured is dependent on the value of the heat field. The function |
5 |
bugtask_heat_html is used to render the flames. |
|
7675.470.1
by Tom Berger
Add a view for displaying bug heat as four flames; use this view to display the bug heat on the bug index page. |
6 |
|
7675.554.1
by Tom Berger
use the bugtask target max_heat to render bug heat |
7 |
>>> MAX_HEAT = 5000.0 |
14600.1.2
by Curtis Hovey
Updated callsites to import from lp.testing, where the code has been for years. |
8 |
>>> from lp.testing import login, logout |
7675.470.1
by Tom Berger
Add a view for displaying bug heat as four flames; use this view to display the bug heat on the bug index page. |
9 |
>>> from zope.security.proxy import removeSecurityProxy |
10 |
>>> from BeautifulSoup import BeautifulSoup |
|
7675.554.2
by Tom Berger
get rid of the bug heat view. it is now redundant |
11 |
>>> from lp.bugs.browser.bugtask import bugtask_heat_html |
7675.568.3
by Tom Berger
When creating the bug heat flames display, compare to the max heat of the current context, not the target of the bugtask. |
12 |
>>> def print_flames(bugtask, target=None): |
13 |
... html = bugtask_heat_html(bugtask, target=target) |
|
7675.470.1
by Tom Berger
Add a view for displaying bug heat as four flames; use this view to display the bug heat on the bug index page. |
14 |
... soup = BeautifulSoup(html) |
10746.1.10
by matthew.revell at canonical
Fixes the failure of bug-heat-view test. |
15 |
... for img in soup.span.a.contents: |
7675.470.1
by Tom Berger
Add a view for displaying bug heat as four flames; use this view to display the bug heat on the bug index page. |
16 |
... print img['src'] |
10372.2.2
by Abel Deuring
use new images for the bug heat icons; add title and alt attributes to the <img> tags for these images |
17 |
... print img['alt'] |
18 |
... print img['title'] |
|
7675.470.1
by Tom Berger
Add a view for displaying bug heat as four flames; use this view to display the bug heat on the bug index page. |
19 |
>>> login('foo.bar@canonical.com') |
20 |
>>> bug = factory.makeBug() |
|
21 |
||
7675.470.3
by Tom Berger
use the MAX_HEAT constant instead of hard-coding |
22 |
The maximum heat is defined as a constant in browser/bug.py. A bug with |
23 |
a heat of half the maximum will result in a display of two coloured flames |
|
24 |
and two black-and-white flames. |
|
25 |
||
7675.553.29
by Deryck Hodge
Global replace max_heat to max_bug_heat. |
26 |
>>> removeSecurityProxy(bug.default_bugtask.target).max_bug_heat = MAX_HEAT |
7675.470.3
by Tom Berger
use the MAX_HEAT constant instead of hard-coding |
27 |
>>> removeSecurityProxy(bug).heat = MAX_HEAT / 2 |
7675.554.2
by Tom Berger
get rid of the bug heat view. it is now redundant |
28 |
>>> print_flames(bug.default_bugtask) |
10372.2.2
by Abel Deuring
use new images for the bug heat icons; add title and alt attributes to the <img> tags for these images |
29 |
/@@/bug-heat-2.png |
30 |
2 out of 4 heat flames |
|
31 |
Heat: 2500 |
|
7675.470.3
by Tom Berger
use the MAX_HEAT constant instead of hard-coding |
32 |
|
33 |
A bug with a maximum heat will display all four flames coloured. |
|
34 |
||
35 |
>>> removeSecurityProxy(bug).heat = MAX_HEAT |
|
7675.554.2
by Tom Berger
get rid of the bug heat view. it is now redundant |
36 |
>>> print_flames(bug.default_bugtask) |
10372.2.2
by Abel Deuring
use new images for the bug heat icons; add title and alt attributes to the <img> tags for these images |
37 |
/@@/bug-heat-4.png |
38 |
4 out of 4 heat flames |
|
39 |
Heat: 5000 |
|
7675.470.3
by Tom Berger
use the MAX_HEAT constant instead of hard-coding |
40 |
|
41 |
A heat of less than a quarter of the maximum will display no coloured flames. |
|
42 |
||
43 |
>>> removeSecurityProxy(bug).heat = 0.1 * MAX_HEAT |
|
7675.554.2
by Tom Berger
get rid of the bug heat view. it is now redundant |
44 |
>>> print_flames(bug.default_bugtask) |
10372.2.2
by Abel Deuring
use new images for the bug heat icons; add title and alt attributes to the <img> tags for these images |
45 |
/@@/bug-heat-0.png |
46 |
0 out of 4 heat flames |
|
47 |
Heat: 500 |
|
7675.470.1
by Tom Berger
Add a view for displaying bug heat as four flames; use this view to display the bug heat on the bug index page. |
48 |
|
7675.568.3
by Tom Berger
When creating the bug heat flames display, compare to the max heat of the current context, not the target of the bugtask. |
49 |
|
50 |
== Specifying the target == |
|
51 |
||
52 |
Some bugs can be viewed in a context different from their task's target. For |
|
53 |
example, bugs with tasks on packages can be viewed in the context of the entire |
|
54 |
distribution. In such cases, we want to explicitly specify the target, rather |
|
55 |
than use the bugtask's. We can do that by passing the target as a keyword |
|
56 |
parameter. |
|
57 |
||
58 |
>>> bug = factory.makeBug() |
|
59 |
>>> distro = factory.makeDistribution() |
|
60 |
>>> dsp = factory.makeDistributionSourcePackage(distribution=distro) |
|
61 |
>>> dsp_task = bug.addTask(bug.owner, dsp) |
|
62 |
>>> removeSecurityProxy(distro).max_bug_heat = MAX_HEAT |
|
63 |
>>> removeSecurityProxy(dsp).max_bug_heat = MAX_HEAT / 2 |
|
64 |
>>> removeSecurityProxy(bug).heat = MAX_HEAT / 4 |
|
65 |
>>> print_flames(dsp_task) |
|
10481.1.2
by Deryck Hodge
Revert the test change. This should be done |
66 |
/@@/bug-heat-2.png |
67 |
2 out of 4 heat flames |
|
68 |
Heat: 1250 |
|
69 |
>>> print_flames(dsp_task, target=distro) |
|
10481.1.1
by Deryck Hodge
Update the test to reflect packages use distro max_heat |
70 |
/@@/bug-heat-0.png |
71 |
0 out of 4 heat flames |
|
72 |
Heat: 1250 |
|
7675.568.3
by Tom Berger
When creating the bug heat flames display, compare to the max heat of the current context, not the target of the bugtask. |
73 |
|
7675.470.1
by Tom Berger
Add a view for displaying bug heat as four flames; use this view to display the bug heat on the bug index page. |
74 |
>>> logout() |
7675.554.4
by Tom Berger
Scale the value used for calculating the number of heat flames to display so that it produces a reasonable amount of flames for the hottest bugs. |
75 |
|
76 |
||
77 |
== Scaling Bug Heat == |
|
78 |
||
79 |
To ensure a reasonable proportion of cold and hot bugs, the number used to |
|
7675.554.5
by Tom Berger
typo |
80 |
calculate the number of flames to display is not a straight-forward ratio. |
7675.554.4
by Tom Berger
Scale the value used for calculating the number of heat flames to display so that it produces a reasonable amount of flames for the hottest bugs. |
81 |
Instead, we transform it by forcing low heat bugs to produce no flames and |
82 |
scaling the hottest bugs logarithmically. |
|
83 |
||
84 |
>>> from lp.bugs.browser.bugtask import calculate_heat_display |
|
85 |
>>> from math import floor |
|
86 |
||
87 |
Heat values less than a third of the maximum heat don't produce any flames. |
|
88 |
||
89 |
>>> print int(floor((300.0 / 1000.0) * 4)) |
|
90 |
1 |
|
91 |
>>> print calculate_heat_display(300.0, 1000.0) |
|
92 |
0 |
|
93 |
||
94 |
Heat values higher than a third of the max but lower than two thirds are treated |
|
95 |
as a straightforward ratio. |
|
96 |
||
97 |
>>> print int(floor((500.0 / 1000.0) * 4)) |
|
98 |
2 |
|
99 |
>>> print calculate_heat_display(500.0, 1000.0) |
|
100 |
2 |
|
101 |
||
102 |
Heat values higher than two thirds of the maximum heat are scaled upwards. |
|
103 |
||
104 |
>>> print int(floor((700.0 / 1000.0) * 4)) |
|
105 |
2 |
|
106 |
>>> print calculate_heat_display(800.0, 1000.0) |
|
107 |
3 |
|
108 |
||
7675.562.1
by Abel Deuring
fix for bug 528374: Flames misplaced on bug report page; also, guard better against pathological cases of max_heat values |
109 |
A max heat value of 1 works too, because we don't divide by |
110 |
log(max_heat) in this case. |
|
111 |
||
112 |
>>> print calculate_heat_display(1, 1) |
|
113 |
4 |
|
7675.562.2
by Abel Deuring
forgotten test for calculate_heat_display() with heat > max_heat added |
114 |
|
115 |
Even if the max heat value is smaller than the heat value itself, |
|
116 |
calculate_heat_display() does not return a value greater than 4. |
|
117 |
||
118 |
>>> print calculate_heat_display(2000, 1000) |
|
119 |
4 |