Skip to content

Commit 61344a6

Browse files
Fix: Scale the radar chart data on a scale of 1-100 (#242)
* Calculate and normalize radar chart data percentages Added logic to calculate the question count per role and survey. Normalized radar chart data by converting scores into percentage values based on the maximum possible score for each role and survey combination. This ensures better data representation on the profile page visualization. * pr comment: refactor questionCounts to use Map
1 parent e30a4b7 commit 61344a6

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

  • src/app/find-the-expert/profile-page

src/app/find-the-expert/profile-page/page.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@ const ProfilePage = async ({
9999
}
100100
const userRoles = user.roles;
101101

102+
const questionCounts: Map<string, Map<string, number>> = new Map<
103+
string,
104+
Map<string, number>
105+
>();
106+
user.questionResults.forEach((questionResult) => {
107+
const surveyName = questionResult.question.survey.surveyName;
108+
questionResult.question.roles.forEach((role) => {
109+
const roleName = role.role;
110+
if (!userRoles.some((userRole) => userRole.role === roleName))
111+
return;
112+
if (!questionCounts.has(roleName)) {
113+
questionCounts.set(roleName, new Map<string, number>());
114+
}
115+
116+
const roleCounts = questionCounts.get(roleName)!;
117+
roleCounts.set(surveyName, (roleCounts.get(surveyName) ?? 0) + 1);
118+
});
119+
});
120+
102121
const surveyNames = new Set<string>();
103122
const radarGraphData = user.questionResults.reduce(
104123
(acc, questionResult) => {
@@ -129,6 +148,18 @@ const ProfilePage = async ({
129148
[] as ProfileRadarChartRoleData[],
130149
);
131150

151+
radarGraphData.forEach((roleData) => {
152+
Object.keys(roleData).forEach((surveyName) => {
153+
if (surveyName === "role") return;
154+
const questionCount =
155+
questionCounts.get(roleData.role)?.get(surveyName) ?? 0;
156+
const maxScore = questionCount * 5; // Max score is number of questions * 5
157+
roleData[surveyName] = Math.round(
158+
((roleData[surveyName] ?? 0) / maxScore) * 100,
159+
);
160+
});
161+
});
162+
132163
const columns: ColumnDef<ProfilePageUserData["questionResults"][0]>[] = [
133164
{
134165
accessorKey: "question.questionText",

0 commit comments

Comments
 (0)