@@ -267,41 +267,45 @@ def save(self, *args, **kwargs):
267267 # Save summary in order of priority
268268 # Average change
269269 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%%" % (
270+ self .summary = "Average %s %s" % (
273271 average_change_units .lower (),
274- direction ,
275- round (abs (average_change ), 1 ))
272+ self .updown (average_change ))
276273 self .colorcode = average_change_color
277274 # Single benchmark change
278275 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 ))
276+ self .summary = "%s %s" % (
277+ max_change_ben ,
278+ self .updown (max_change ))
283279 self .colorcode = max_change_color
284280
285281 # Average trend
286282 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 ))
283+ self .summary = "Average %s trend %s" % (
284+ average_trend_units .lower (),
285+ self .updown (average_trend ))
291286 self .colorcode = average_trend_color == "red" \
292287 and "yellow" or average_trend_color
293288 # Single benchmark trend
294289 if max_trend_color != "none" and self .colorcode != "red" :
295290 if (self .colorcode == "none" or
296291 (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 ))
292+ self . summary = "%s trend %s" % (
293+ max_trend_ben ,
294+ self . updown (max_trend ))
300295 self .colorcode = max_trend_color == "red" \
301296 and "yellow" or max_trend_color
302297
303298 super (Report , self ).save (* args , ** kwargs )
304299
300+ def updown (self ,val ):
301+ #Substitute plus/minus with up/down
302+ direction = val >= 0 and "up" or "down"
303+ aval = abs (val )
304+ if aval == float ("inf" ):
305+ return u"%s ∞%%" % direction
306+ else :
307+ return "%s %.1f%%" % (direction , aval )
308+
305309 def is_big_change (self , val , color , current_val , current_color ):
306310 if color == "red" and current_color != "red" :
307311 return True
@@ -316,12 +320,12 @@ def is_big_change(self, val, color, current_val, current_color):
316320 def getcolorcode (self , val , lessisbetter , threshold ):
317321 if lessisbetter :
318322 val = - val
319- colorcode = "none"
320323 if val < - threshold :
321- colorcode = "red"
324+ return "red"
322325 elif val > threshold :
323- colorcode = "green"
324- return colorcode
326+ return "green"
327+ else :
328+ return "none"
325329
326330 def get_changes_table (self , trend_depth = 10 , force_save = False ):
327331 # Determine whether required trend value is the default one
@@ -406,9 +410,16 @@ def get_changes_table(self, trend_depth=10, force_save=False):
406410 change = "-"
407411 if len (change_list ):
408412 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 )
413+ if c .count () and result is not None :
414+ if c [0 ].value != 0 :
415+ change = (result - c [0 ].value ) * 100 / c [0 ].value
416+ totals ['change' ].append (result / c [0 ].value )
417+ elif c [0 ].value == 0 :
418+ change = float ("inf" )
419+ totals ['change' ].append (float ("inf" ))
420+ else :
421+ # no previous result, no change available
422+ pass
412423
413424 # Calculate trend:
414425 # percentage change relative to average of 3 previous results
0 commit comments