r25159 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25158‎ | r25159 | r25160 >
Date:13:17, 26 August 2007
Author:midom
Status:old
Tags:
Comment:
handle divzero better
Modified paths:
  • /trunk/udpprofile/web/report.py (modified) (history)

Diff [purge]

Index: trunk/udpprofile/web/report.py
@@ -168,20 +168,25 @@
169169 onereal=event["onereal"]
170170
171171 if old:
172 - oldcount=float(old["count"])/oldtotal["count"]
173 - countdiff = (callcount-oldcount)/oldcount
 172+ try:
 173+ oldcount=float(old["count"])/oldtotal["count"]
 174+ countdiff = (callcount-oldcount)/oldcount
174175
175 - oldcpupct = old["cpu"]/oldtotal["cpu"]
176 - cpupctdiff = (cpupct-oldcpupct)/oldcpupct
 176+ oldcpupct = old["cpu"]/oldtotal["cpu"]
 177+ cpupctdiff = (cpupct-oldcpupct)/oldcpupct
177178
178 - onecpudiff = ( onecpu - old["onecpu"] ) / old["onecpu"]
 179+ onecpudiff = ( onecpu - old["onecpu"] ) / old["onecpu"]
179180
180 - oldrealpct = old["real"]/oldtotal["real"]
181 - realpctdiff = (realpct-oldrealpct)/oldrealpct
 181+ oldrealpct = old["real"]/oldtotal["real"]
 182+ realpctdiff = (realpct-oldrealpct)/oldrealpct
182183
183 - o=old["onereal"]
184 - onerealdiff = ( onereal - old["onereal"] ) / old["onereal"]
185 -
 184+ onerealdiff = ( onereal - old["onereal"] ) / old["onereal"]
 185+ except ZeroDivisionError:
 186+ countdiff=0
 187+ cpupctdiff=0
 188+ onecpudiff=0
 189+ realpctdiff=0
 190+ onerealdiff=0
186191 else:
187192 countdiff=0
188193 cpupctdiff=0

Status & tagging log