Download src/algorithm/DemographicsPieByGender.ts from nolual/majic: direct link, hf CLI and curl.
- Browser
- Download file 973 Bytes
-
https://huggingface.co/nolual/majic/resolve/main/src/algorithm/DemographicsPieByGender.ts
- Command line
-
hf download hf://nolual/majic/src/algorithm/DemographicsPieByGender.ts
-
curl -L -o DemographicsPieByGender.ts https://huggingface.co/nolual/majic/resolve/main/src/algorithm/DemographicsPieByGender.ts
973 Bytes
| 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; | |
| } | |