Skip to content

Commit 6ab354a

Browse files
authored
Merge pull request #30 from NGO-Algorithm-Audit/feature/bivariate_section_1_3_2_category_vs_category
bivariate category vs category
2 parents f902f6e + a2c4b0e commit 6ab354a

File tree

2 files changed

+91
-1
lines changed

2 files changed

+91
-1
lines changed

src/components/DistributionReport.tsx

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { UnivariateCharts } from './UnivariateCharts';
88
import { Accordion } from './ui/accordion';
99
import { createHeatmapdata } from './createHeatmapdata';
1010
import ViolinChart from './graphs/ViolinChart';
11+
import GroupBarChart from './graphs/GroupBarChart';
1112

1213
interface DistributionReport {
1314
reportType: string;
@@ -82,13 +83,101 @@ export const DistributionReport = (
8283
);
8384
}
8485
if (report.reportType === 'bivariateDistributionRealData') {
86+
/*
87+
for all category colums (main column)
88+
- foreach column that is also a category column (secondary column)
89+
- get all categories of the main column
90+
- foreach category of the main column
91+
- count all the categories of the secondary column
92+
- add this to a data structure
93+
- create a historgram with the data structure
94+
95+
*/
96+
const charts = columnNames.map((column, index) => {
97+
const dataType = dataTypes[column];
98+
return columnNames.map((column2, index2) => {
99+
if (column === column2 || index >= index2) {
100+
return null;
101+
}
102+
const dataType2 = dataTypes[column2];
103+
104+
if (
105+
dataType === 'category' &&
106+
dataType2 === 'category'
107+
) {
108+
const data = realData.reduce(
109+
(
110+
acc: Record<string, any>,
111+
row: Record<string, any>
112+
) => {
113+
const category = row[column];
114+
const category2 = row[column2];
115+
if (!acc[category]) {
116+
acc[category] = {};
117+
}
118+
if (!acc[category][category2]) {
119+
acc[category][category2] = 0;
120+
}
121+
acc[category][category2]++;
122+
return acc;
123+
},
124+
{} as Record<
125+
string,
126+
Record<string, number>
127+
>
128+
);
129+
130+
const categories = Object.keys(data);
131+
const categories2 = new Set<string>();
132+
for (const category in data) {
133+
for (const category2 in data[
134+
category
135+
]) {
136+
categories2.add(category2);
137+
}
138+
}
139+
const categories2Array =
140+
Array.from(categories2);
141+
142+
const histogramData = categories.map(
143+
category => {
144+
const categoryData =
145+
categories2Array.map(
146+
category2 => {
147+
return {
148+
name: category2,
149+
value:
150+
data[category][
151+
category2
152+
] || 0,
153+
};
154+
}
155+
);
156+
return {
157+
name: category,
158+
values: categoryData,
159+
};
160+
}
161+
);
162+
return (
163+
<div key={column + column2}>
164+
<GroupBarChart
165+
data={histogramData}
166+
title={`${column} vs ${column2}`}
167+
/>
168+
</div>
169+
);
170+
}
171+
});
172+
});
173+
85174
return (
86175
<div key={indexReport} className="mb-4">
87176
<Accordion
88177
title={t(
89178
'syntheticData.bivariateDistributionRealData'
90179
)}
91-
content={<p>PLACEHOLDER</p>}
180+
content={<div>{charts}</div>}
92181
/>
93182
</div>
94183
);

src/components/componentMapper.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export default function ComponentMapper({
146146
};
147147
}
148148
);
149+
console.log('histogramData', histogramData);
149150

150151
return (
151152
<ErrorBoundary key={index}>

0 commit comments

Comments
 (0)