-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscorer.ts
More file actions
34 lines (30 loc) · 919 Bytes
/
Copy pathscorer.ts
File metadata and controls
34 lines (30 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import type { Score } from "@/models/Questionnaire";
import type {
QuestionnaireScoreContext,
QuestionnaireScorer,
} from "@/questionnaires/types";
import { cleanDouble } from "@/utils/cleanDouble";
import type { PoliticalCompassOrgData } from "./types";
export function calculatePoliticalCompassScore({
answers,
data,
}: QuestionnaireScoreContext<PoliticalCompassOrgData>): Score {
let sumEconomic = 0;
let sumSocial = 0;
for (const { answer } of answers) {
sumEconomic += Number(answer.economicWeight ?? 0);
sumSocial += Number(answer.socialWeight ?? 0);
}
return {
economic: cleanDouble(
sumEconomic / data.economicScaleDivisor + data.economicOffset,
),
social: cleanDouble(
sumSocial / data.socialScaleDivisor + data.socialOffset,
),
};
}
export const politicalCompassOrgScorer: QuestionnaireScorer<PoliticalCompassOrgData> =
{
calculateScore: calculatePoliticalCompassScore,
};