Skip to content

Commit

Permalink
replace zip_choices with strict zip
Browse files Browse the repository at this point in the history
  • Loading branch information
Kakadus committed Nov 6, 2023
1 parent e7d7d9b commit e7cb10f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
6 changes: 6 additions & 0 deletions evap/evaluation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,9 @@ class Choices(NamedTuple):
names: list[StrOrPromise]
is_inverted: bool

def as_name_color_value_tuples(self):
return zip(self.names, self.colors, self.values, strict=True)


class BipolarChoices(NamedTuple):
css_class: str
Expand All @@ -1256,6 +1259,9 @@ class BipolarChoices(NamedTuple):
minus_name: StrOrPromise
is_inverted: bool

def as_name_color_value_tuples(self):
return zip(self.names, self.colors, self.values, strict=True)


NO_ANSWER = 6
BASE_UNIPOLAR_CHOICES = {
Expand Down
5 changes: 0 additions & 5 deletions evap/evaluation/templatetags/evaluation_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ def _zip(a, b):
return zip(a, b)


@register.filter()
def zip_choices(counts, choices):
return zip(counts, choices.names, choices.colors, choices.values)


@register.filter
def ordering_index(evaluation):
if evaluation.state < Evaluation.State.IN_EVALUATION:
Expand Down
2 changes: 1 addition & 1 deletion evap/results/templates/result_widget_tooltip.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{% endif %}
{% with question_result.question.is_bipolar_likert_question as is_bipolar %}
<p>
{% for count, name, color, value in question_result.counts|zip_choices:question_result.choices %}
{% for count, name, color, value in question_result.zipped_choices %}
<span class='vote-text-{{ color }} fas fa-fw-absolute
{% if is_bipolar and value < 0 %}fa-caret-down pole-icon
{% elif is_bipolar and value > 0 %}fa-caret-up pole-icon
Expand Down
8 changes: 5 additions & 3 deletions evap/results/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ def __init__(self, question, answer_counters, additional_text_result=None):
self.additional_text_result = additional_text_result

if answer_counters is not None:
counts = OrderedDict((value, 0) for value in self.choices.values if value != NO_ANSWER)
counts = OrderedDict((value, [0, name, color, value]) for (name, color, value) in self.choices.as_name_color_value_tuples())
counts.pop(NO_ANSWER)
for answer_counter in answer_counters:
counts[answer_counter.answer] = answer_counter.count
self.counts = tuple(counts.values())
counts[answer_counter.answer][0] = answer_counter.count
self.zipped_choices = tuple(counts.values())
self.counts = tuple((count for count, _, _, _ in counts.values()))
else:
self.counts = None

Expand Down

0 comments on commit e7cb10f

Please sign in to comment.