Skip to content

Commit

Permalink
Error checking for Westminster diagram
Browse files Browse the repository at this point in the history
I was getting NaN errors if the "cross bench columns" wasn't filled in properly
in the web form. Test for valid number.
  • Loading branch information
slashme committed Jan 14, 2017
1 parent c012f14 commit c6c0295
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion westminster.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@
if (not 'centercols' in optionlist) or optionlist['centercols']==0: #If the number of columns in the cross-bench is not defined, calculate it:
optionlist['centercols']=int(math.ceil(math.sqrt(sumdelegates['center']/4.0)))
else:
optionlist['centercols']=int(optionlist['centercols'])
try:
optionlist['centercols']=int(optionlist['centercols'])
except ValueError: #TODO: This is a hack - I seem to be getting a NaN here for some reason, need to fix it properly.
optionlist['centercols']=int(math.ceil(math.sqrt(sumdelegates['center']/4.0))) #Do the same calculation as above if it's not a number.
try:
centerrows=math.ceil(float(sumdelegates['center'])/optionlist['centercols'])
except ZeroDivisionError:
Expand Down

0 comments on commit c6c0295

Please sign in to comment.