File size: 973 Bytes
0c20ea8 |
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 35 36 37 38 39 40 |
interface SocioDemographyItem {
age: string;
gender: string;
percentage: number;
social_group: string;
}
export interface SummaryItem {
label: string;
usage: number;
}
export function generateSummary(data: SocioDemographyItem[]): SummaryItem[] {
const summaryData: SummaryItem[] = [];
function calculateUsage(age: string, gender: string): number {
const filteredData = data.filter(
(item) => item.age === age && item.gender.toUpperCase() === gender
);
const totalPercentage = filteredData.reduce(
(total, item) => total + item.percentage,
0
);
return totalPercentage;
}
const ageGroups = ["15-24", "25-34", "35-49", "50-64", "65-PLUS"];
const genders = ["MALE", "FEMALE"];
for (const gender of genders) {
for (const age of ageGroups) {
const label = `${gender} ${age}`;
const usage = calculateUsage(age, gender);
summaryData.push({ label, usage });
}
}
return summaryData;
}
|