Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Percentage Calculation on Quiz Page #1081

Closed
26samaahmed opened this issue May 4, 2024 · 3 comments · Fixed by #1132
Closed

Incorrect Percentage Calculation on Quiz Page #1081

26samaahmed opened this issue May 4, 2024 · 3 comments · Fixed by #1132
Assignees
Labels
bug Something isn't working

Comments

@26samaahmed
Copy link
Collaborator

What happened?

The calculation for the quiz results is miscalculated after adding the data for OSS, Game Dev, and ICPC. The Game Dev results are always 0 as well.

Screenshot 2024-05-04 131342

@26samaahmed 26samaahmed added the bug Something isn't working label May 4, 2024
@26samaahmed 26samaahmed self-assigned this May 4, 2024
@26samaahmed
Copy link
Collaborator Author

Reference #1059

@tmbkoren
Copy link
Collaborator

tmbkoren commented Oct 7, 2024

Game dev results in 0 because in src/lib/public/quiz/questions/types.ts TeamMatch, GAMEDEV is defined as 'Game Dev' with a space, thus being recorded as 'Game Dev' in responses. When calculating matches, match = match?.toLowerCase() as TeamMatch; is used, resulting in 'game dev' string. But in src/lib/public/board/data/teams.json, Game Dev team Id is "gamedev" without a space.

When displaying quiz results, team data such as progress bar color is accessed using TEAMS[match].

<h2 class="match-title" style={`--team-color: ${TEAMS[match].color}`}>
      {match} <span>Team</span>
    </h2>
    <p>Click the teams below to see your next step</p>
    <div class="result-grid">
      <div
        class="result-grid-box"
        on:click|preventDefault|stopPropagation={() => showTeamDetails(TEAMS[match])}
        on:keydown|preventDefault|stopPropagation={() => showTeamDetails(TEAMS[match])}
        style={`--border-color: ${TEAMS[match].color}`}
        role="button"
        tabindex="0"
      >

Since it's trying to access TEAMS['game dev'], it returns nothing.

Also, as a result of this, whenever you get game dev as your match, page simply doesn't render.
image

Proposed solution :

in src/lib/public/quiz/questions/types.ts TeamMatch, change GAMEDEV = 'Game Dev', to GAMEDEV = 'GameDev',
After doing the said change and making choices to get gamedev match:
image

I don't see src/lib/public/quiz/questions/types.ts being used outside of quiz module, so there shouldn't be a problem.
image

@tmbkoren
Copy link
Collaborator

tmbkoren commented Oct 7, 2024

As for progress bar, issue is with the formula that calculates percentage. It is {(talliedResponses[match] / data.questions.length) * 100}.
data.questions.length is a number of questions, which is always 13, while talliedResponses stores amount of matches for each team, which varies depending on the responses chosen, and the sum is variable, resulting in percentages being off.

My proposal:

change the formula to {(talliedResponses[match] / sumOfTallies) * 100}, where sumOfTallies is calculated by a function

 function totalTallies(tallies: Record<string, number>) {
    let totalTallies = 0;
    Object.values(tallies).forEach(value => totalTallies += value);
    return totalTallies;
  }

After doing the said change:
image
Unfortunately, because of rounding it adds up to 99% sometimes. I have no fix for that(yet), and would take suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants