Skip to content

Commit

Permalink
fix comm grade breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
secondl1ght committed Jan 31, 2024
1 parent 4ae1715 commit 95fba07
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ export type ReportTags = {
outdated_elements: number;
legacy_elements: number;
avg_verification_date: string;
grade: Grade;
};

export type Grade = 1 | 2 | 3 | 4 | 5;
Expand Down Expand Up @@ -200,6 +199,7 @@ export type ProfileLeaderboard = { id: number; total: number };

export interface LeaderboardArea extends Area {
report: Report;
grade: Grade;
}

// tagger
Expand Down
17 changes: 17 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { theme } from '$lib/store';
import { toast } from '@zerodevx/svelte-toast';
import type { Chart } from 'chart.js';
import { get } from 'svelte/store';
import type { Grade } from './types';

export const errToast = (m: string) => {
toast.push(m, {
Expand Down Expand Up @@ -80,3 +81,19 @@ export const formatElementID = (id: string) => {

return elementIdFormatted;
};

export const getGrade = (upToDatePercent: number): Grade => {
switch (true) {
case upToDatePercent >= 95:
return 5;
case upToDatePercent >= 75:
return 4;
case upToDatePercent >= 50:
return 3;
case upToDatePercent >= 25:
return 2;
case upToDatePercent >= 0:
default:
return 1;
}
};
8 changes: 5 additions & 3 deletions src/routes/communities/leaderboard/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
} from '$lib/comp';
import { areaError, areas, reportError, reports, syncStatus, theme } from '$lib/store';
import type { Area, LeaderboardArea, Report } from '$lib/types';
import { detectTheme, errToast } from '$lib/utils';
import { detectTheme, errToast, getGrade } from '$lib/utils';
import tippy from 'tippy.js';
// alert for area errors
Expand Down Expand Up @@ -59,7 +59,9 @@
let communityReport = communityReports.find((report) => report.area_id === community.id);
if (communityReport) {
leaderboard.push({ ...community, report: communityReport });
const grade = getGrade(communityReport.tags.up_to_date_percent);
leaderboard.push({ ...community, report: communityReport, grade });
}
});
Expand Down Expand Up @@ -217,7 +219,7 @@
id={item.id}
upToDate={item.report.tags.up_to_date_percent}
total={item.report.tags.total_elements}
grade={item.report.tags.grade}
grade={item.grade}
/>
{/each}

Expand Down
24 changes: 2 additions & 22 deletions src/routes/community/[area]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
type Leaflet,
type User
} from '$lib/types.js';
import { detectTheme, errToast, formatElementID, updateChartThemes } from '$lib/utils';
import { detectTheme, errToast, formatElementID, getGrade, updateChartThemes } from '$lib/utils';
// @ts-expect-error
import rewind from '@mapbox/geojson-rewind';
import Chart from 'chart.js/auto';
Expand Down Expand Up @@ -345,27 +345,7 @@
legacyPercent = legacy ? (legacy / (total / 100)).toFixed(0) : '0';
const setGrade = () => {
switch (true) {
case Number(upToDatePercent) >= 95:
grade = 5;
break;
case Number(upToDatePercent) >= 75:
grade = 4;
break;
case Number(upToDatePercent) >= 50:
grade = 3;
break;
case Number(upToDatePercent) >= 25:
grade = 2;
break;
case Number(upToDatePercent) >= 0:
grade = 1;
break;
}
};
setGrade();
grade = getGrade(Number(upToDatePercent));
const populateCharts = () => {
const chartsReports = [...communityReports].sort(
Expand Down

0 comments on commit 95fba07

Please sign in to comment.