Skip to content

Commit

Permalink
revert counters logic improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Kakadus committed Nov 6, 2023
1 parent 92d575b commit f857692
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
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.zipped_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
20 changes: 9 additions & 11 deletions evap/results/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from copy import copy
from math import ceil, modf
from numbers import Real
from typing import TypeGuard, cast
from typing import OrderedDict, TypeGuard, cast

from django.conf import settings
from django.core.cache import caches
Expand All @@ -13,8 +13,6 @@
from evap.evaluation.models import (
CHOICES,
NO_ANSWER,
BipolarChoices,
Choices,
ChoicesBase,
Contribution,
Course,
Expand Down Expand Up @@ -54,14 +52,14 @@ def __init__(self, question, answer_counters, additional_text_result=None) -> No
self.counts = None
self.zipped_choices = None
if answer_counters:
answer_indices = {answer: i for i, answer in enumerate(self.choices.values) if answer != NO_ANSWER}
counts = [0] * len(answer_indices)
for counter in answer_counters:
counts[answer_indices[counter.answer]] = counter.count
self.counts = tuple(counts)
self.zipped_choices = list(
(count,) + triple for count in counts for triple in self.choices.as_name_color_value_tuples()
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][0] = answer_counter.count
self.zipped_choices = list(counts.values())
self.counts = tuple((count for count, _, _, _ in counts.values()))

@property
def choices(self) -> ChoicesBase:
Expand Down Expand Up @@ -97,7 +95,7 @@ def average(self) -> float | None:

class _CountedRatingResult(RatingResult):
counts: tuple[int, ...]
zipped_choices: list[tuple[Real, StrOrPromise, str, Real]]
zipped_choices: list[list[Real | StrOrPromise | str | Real]]

count_sum: int
average: float
Expand Down

0 comments on commit f857692

Please sign in to comment.