|
export interface SummaryItemSocial { |
|
label: string; |
|
usage: number; |
|
} |
|
|
|
export function summarizeSocialGroups(data: any[]): SummaryItemSocial[] { |
|
const summary: { [key: string]: number } = {}; |
|
|
|
data.forEach((item) => { |
|
const socialGroup = item.social_group; |
|
const percentage = item.percentage; |
|
summary[socialGroup] = (summary[socialGroup] || 0) + percentage; |
|
}); |
|
|
|
const summaryArray: SummaryItemSocial[] = []; |
|
for (const socialGroup in summary) { |
|
summaryArray.push({ |
|
label: `${socialGroup}`, |
|
usage: summary[socialGroup], |
|
}); |
|
} |
|
|
|
return summaryArray; |
|
} |
|
|