@@ -265,43 +265,55 @@ def save(self, *args, **kwargs):
265265 self .colorcode = "none"
266266
267267 # Save summary in order of priority
268+ # (changes results before trends, averages before individual results)
269+
268270 # Average change
269271 if average_change_color != "none" :
270- #Substitute plus/minus with up/down
271- direction = average_change >= 0 and "+" or "-"
272- self .summary = "Average %s %s%.1f%%" % (
272+ self .summary = "Average %s %s" % (
273273 average_change_units .lower (),
274- direction ,
275- round (abs (average_change ), 1 ))
274+ self .updown (average_change ))
276275 self .colorcode = average_change_color
276+
277277 # Single benchmark change
278- if max_change_color != "none" and self .colorcode != "red" :
279- #Substitute plus/minus with up/down
280- direction = max_change >= 0 and "+" or "-"
281- self .summary = "%s %s%.1f%%" % (
282- max_change_ben , direction , round (abs (max_change ), 1 ))
278+ elif max_change_color != "none" :
279+ self .summary = "%s %s" % (
280+ max_change_ben ,
281+ self .updown (max_change ))
283282 self .colorcode = max_change_color
284283
285284 # Average trend
286- if average_trend_color != "none" and self .colorcode == "none" :
287- #Substitute plus/minus with up/down
288- direction = average_trend >= 0 and "+" or ""
289- self .summary = "Average %s trend %s%.1f%%" % (
290- average_trend_units .lower (), direction , round (average_trend , 1 ))
291- self .colorcode = average_trend_color == "red" \
292- and "yellow" or average_trend_color
285+ elif average_trend_color != "none" :
286+ self .summary = "Average %s trend %s" % (
287+ average_trend_units .lower (),
288+ self .updown (average_trend ))
289+ # use lighter colors for trend results:
290+ if average_trend_color == "red" :
291+ self .colorcode = "yellow"
292+ elif average_trend_color == "green" :
293+ self .colorcode = "lightgreen"
294+
293295 # Single benchmark trend
294- if max_trend_color != "none" and self .colorcode != "red" :
295- if (self .colorcode == "none" or
296- (self .colorcode == "green" and "trend" not in self .summary )):
297- direction = max_trend >= 0 and "+" or ""
298- self .summary = "%s trend %s%.1f%%" % (
299- max_trend_ben , direction , round (max_trend , 1 ))
300- self .colorcode = max_trend_color == "red" \
301- and "yellow" or max_trend_color
296+ elif max_trend_color != "none" :
297+ self .summary = "%s trend %s" % (
298+ max_trend_ben ,
299+ self .updown (max_trend ))
300+ # use lighter colors for trend results:
301+ if max_trend_color == "red" :
302+ self .colorcode = "yellow"
303+ elif max_trend_color == "green" :
304+ self .colorcode = "lightgreen"
302305
303306 super (Report , self ).save (* args , ** kwargs )
304307
308+ def updown (self ,val ):
309+ #Substitute plus/minus with up/down
310+ direction = val >= 0 and "up" or "down"
311+ aval = abs (val )
312+ if aval == float ("inf" ):
313+ return u"%s ∞%%" % direction
314+ else :
315+ return "%s %.1f%%" % (direction , aval )
316+
305317 def is_big_change (self , val , color , current_val , current_color ):
306318 if color == "red" and current_color != "red" :
307319 return True
@@ -316,12 +328,12 @@ def is_big_change(self, val, color, current_val, current_color):
316328 def getcolorcode (self , val , lessisbetter , threshold ):
317329 if lessisbetter :
318330 val = - val
319- colorcode = "none"
320331 if val < - threshold :
321- colorcode = "red"
332+ return "red"
322333 elif val > threshold :
323- colorcode = "green"
324- return colorcode
334+ return "green"
335+ else :
336+ return "none"
325337
326338 def get_changes_table (self , trend_depth = 10 , force_save = False ):
327339 # Determine whether required trend value is the default one
@@ -406,9 +418,22 @@ def get_changes_table(self, trend_depth=10, force_save=False):
406418 change = "-"
407419 if len (change_list ):
408420 c = change_list .filter (benchmark = bench )
409- if c .count () and c [0 ].value and result :
410- change = (result - c [0 ].value ) * 100 / c [0 ].value
411- totals ['change' ].append (result / c [0 ].value )
421+ if c .count () and result is not None :
422+ if c [0 ].value != 0 :
423+ change = (result - c [0 ].value ) * 100 / c [0 ].value
424+ totals ['change' ].append (result / c [0 ].value )
425+ elif c [0 ].value == 0 :
426+ if result == 0 :
427+ # 0/0 = 1, in our world
428+ change = 0
429+ totals ['change' ].append (1 )
430+ else :
431+ # n/0 = ∞
432+ change = float ("inf" )
433+ totals ['change' ].append (float ("inf" ))
434+ else :
435+ # no previous result, no change available
436+ pass
412437
413438 # Calculate trend:
414439 # percentage change relative to average of 3 previous results
0 commit comments