Skip to content
Snippets Groups Projects
Commit c2a668de authored by Ben Adida's avatar Ben Adida
Browse files

made pretty_results and datatypes more robust in the face of nulls

parent 431a6b33
No related branches found
No related tags found
No related merge requests found
......@@ -171,7 +171,10 @@ class LDObject(object):
self.structured_fields[f] = sub_ld_object
# set the field on the wrapped object too
if sub_ld_object != None:
self._setattr_wrapped(f, sub_ld_object.wrapped_obj)
else:
self._setattr_wrapped(f, None)
else:
# a simple type
new_val = self.process_value_in(f, d[f])
......@@ -203,6 +206,10 @@ class LDObject(object):
@classmethod
def fromDict(cls, d, type_hint=None):
# null objects
if d == None:
return None
# the LD type is either in d or in type_hint
# FIXME: get this from the dictionary itself
ld_type = type_hint
......
......@@ -480,9 +480,12 @@ class Election(HeliosModel):
counts = sorted(enumerate(result), key=lambda(x): x[1])
counts.reverse()
the_max = question['max'] or 1
the_min = question['min'] or 0
# if there's a max > 1, we assume that the top MAX win
if question['max'] > 1:
return [c[0] for c in counts[:question['max']]]
if the_max > 1:
return [c[0] for c in counts[:the_max]]
# if max = 1, then depends on absolute or relative
if question['result_type'] == 'absolute':
......@@ -490,8 +493,8 @@ class Election(HeliosModel):
return [counts[0][0]]
else:
return []
if question['result_type'] == 'relative':
else:
# assumes that anything non-absolute is relative
return [counts[0][0]]
@property
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment