File size: 599 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
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;
}