Skip to content

Commit

Permalink
fix(text): fix gender diversity threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
withSang committed Nov 29, 2023
1 parent 1b1a8b9 commit 4018af0
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 33 deletions.
3 changes: 0 additions & 3 deletions src/components/molecules/LocalCouncilReportText/AgeText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ export const AgeText = ({
{getNameFromId(ageHistogramParagraph.uniArea.localId)?.join(" ")}
</Text>
예요.
<br />
<br />
이전 정보를 확인하려면 아래의 슬라이더를 밀어 보세요.
</Paragraph>
);
return <Paragraph>존재하지 않는 템플릿입니다.</Paragraph>;
Expand Down
32 changes: 22 additions & 10 deletions src/components/molecules/LocalCouncilReportText/GenderText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ function calculatePercentage(a: number, b: number) {
return Math.round((a / (a + b)) * 100);
}

function calculateGenderRatio(a: number, b: number) {
function calculateGenderDiversity(a: number, b: number) {
return Math.max(a / b, b / a);
}

function calculateFemaleRatio(femalePop: number, malePop: number) {
return femalePop / (femalePop + malePop);
}

export const GenderText = ({
variation = 1,
data = defaultData,
Expand All @@ -66,31 +70,39 @@ export const GenderText = ({
const localName = getNameFromId(localId)?.join(" ");
const nowPercentage = calculatePercentage(current.femalePop, current.malePop);
const meanPercentage = calculatePercentage(meanFemalePop, meanMalePop);
const nowGenderRatio = calculateGenderRatio(
const nowGenderDiversity = calculateGenderDiversity(
current.femalePop,
current.malePop,
);
const prevGenderDiversity = calculateGenderDiversity(
prev.femalePop,
prev.malePop,
);
const nowGenderRatio = calculateFemaleRatio(
current.femalePop,
current.malePop,
);
const prevGenderRatio = calculateGenderRatio(prev.femalePop, prev.malePop);
const meanGenderRatio = calculateFemaleRatio(meanFemalePop, meanMalePop);

if (variation === 1)
return (
<Paragraph>
{current.year}년 지방선거 당선자의 성비는{" "}
<Text strong>
{nowGenderRatio > prevGenderRatio
{nowGenderDiversity > prevGenderDiversity
? "퇴보했습니다."
: nowGenderRatio === prevGenderRatio
? "변화하지 않았습니다"
: nowGenderDiversity === prevGenderDiversity
? "변화하지 않았습니다."
: "나아졌습니다."}
</Text>{" "}
<br /> <br />
{current.year}년 지방선거에서 {localName}의 당선자의 성별은 남성{" "}
<Text strong>
{current.malePop}명({100 - nowPercentage}%){" "}
{current.malePop}명({100 - nowPercentage}%)
</Text>
, 여성{" "}
<Text strong>
{current.femalePop}명({nowPercentage}%){" "}
{current.femalePop}명({nowPercentage}%)
</Text>
입니다. <br /> <br /> 전국 지역 의회는 평균적으로 남성이{" "}
<Text strong>{100 - meanPercentage}%</Text>, 여성이{" "}
Expand All @@ -100,9 +112,9 @@ export const GenderText = ({
<Text strong>{Math.round(nowPercentage / 10)}</Text>명인 정도이기
때문에,{" "}
<Text strong>
{nowGenderRatio > prevGenderRatio
{nowGenderRatio < meanGenderRatio
? "전국 대비 성별 다양성이 충분하다고 보기는 어렵습니다."
: nowGenderRatio === prevGenderRatio
: nowGenderRatio === meanGenderRatio
? "전국 평균 수준입니다."
: "전국 평균 대비 높은 수준입니다."}
</Text>
Expand Down
3 changes: 0 additions & 3 deletions src/components/molecules/MetroCouncilReportText/AgeText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ export const AgeText = ({
{getNameFromId(ageHistogramParagraph.uniArea.localId)?.join(" ")}
</Text>
예요.
<br />
<br />
이전 정보를 확인하려면 아래의 슬라이더를 밀어 보세요.
</Paragraph>
);
return <Paragraph>존재하지 않는 템플릿입니다.</Paragraph>;
Expand Down
32 changes: 22 additions & 10 deletions src/components/molecules/MetroCouncilReportText/GenderText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,41 +47,53 @@ function calculatePercentage(a: number, b: number) {
return Math.round((a / (a + b)) * 100);
}

function calculateGenderRatio(a: number, b: number) {
function calculateGenderDiversity(a: number, b: number) {
return Math.max(a / b, b / a);
}

function calculateFemaleRatio(femalePop: number, malePop: number) {
return femalePop / (femalePop + malePop);
}

export const GenderText = ({ variation = 1, data = defaultData }: Props) => {
if (!data) return <Paragraph>데이터를 불러오는 중입니다..</Paragraph>;

const { current, prev, meanMalePop, meanFemalePop } = data;
const nowPercentage = calculatePercentage(current.femalePop, current.malePop);
const meanPercentage = calculatePercentage(meanFemalePop, meanMalePop);
const nowGenderRatio = calculateGenderRatio(
const nowGenderDiversity = calculateGenderDiversity(
current.femalePop,
current.malePop,
);
const prevGenderDiversity = calculateGenderDiversity(
prev.femalePop,
prev.malePop,
);
const nowGenderRatio = calculateFemaleRatio(
current.femalePop,
current.malePop,
);
const prevGenderRatio = calculateGenderRatio(prev.femalePop, prev.malePop);
const meanGenderRatio = calculateFemaleRatio(meanFemalePop, meanMalePop);

if (variation === 1)
return (
<Paragraph>
{current.year}년 지방선거 당선자의 성비는{" "}
<Text strong>
{nowGenderRatio > prevGenderRatio
{nowGenderDiversity > prevGenderDiversity
? "퇴보했습니다."
: nowGenderRatio === prevGenderRatio
? "변화하지 않았습니다"
: nowGenderDiversity === prevGenderDiversity
? "변화하지 않았습니다."
: "나아졌습니다."}
</Text>{" "}
<br /> <br />
{current.year}년 지방선거에서 당선자의 성별은 남성{" "}
<Text strong>
{current.malePop}명({100 - nowPercentage}%){" "}
{current.malePop}명({100 - nowPercentage}%)
</Text>
, 여성{" "}
<Text strong>
{current.femalePop}명({nowPercentage}%){" "}
{current.femalePop}명({nowPercentage}%)
</Text>
입니다. <br /> <br /> 전국 지역 의회는 평균적으로 남성이{" "}
<Text strong>{100 - meanPercentage}%</Text>, 여성이{" "}
Expand All @@ -91,9 +103,9 @@ export const GenderText = ({ variation = 1, data = defaultData }: Props) => {
<Text strong>{Math.round(nowPercentage / 10)}</Text>명인 정도이기
때문에,{" "}
<Text strong>
{nowGenderRatio > prevGenderRatio
{nowGenderRatio < meanGenderRatio
? "전국 대비 성별 다양성이 충분하다고 보기는 어렵습니다."
: nowGenderRatio === prevGenderRatio
: nowGenderRatio === meanGenderRatio
? "전국 평균 수준입니다."
: "전국 평균 대비 높은 수준입니다."}
</Text>
Expand Down
7 changes: 3 additions & 4 deletions src/components/organisms/LocalCouncilReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ const LocalCouncilReport = ({
const newGenderPieChartColorMap = new Map<string, string>();
const genderColors = [
{
type: "",
type: "남성",
color: "#289FD4",
},
{
type: "",
type: "여성",
color: "#AE2D6C",
},
];
Expand Down Expand Up @@ -177,7 +177,6 @@ const LocalCouncilReport = ({
binMax: maxAge,
count,
colorGroup: colorGroupMap.get(ageGroup as ColorGroup) || 0,
// colorGroup: ageGroup as ColorGroup,
});
});
setAgeHistogramData(newAgeHistogramData);
Expand All @@ -193,7 +192,7 @@ const LocalCouncilReport = ({
const newGenderPieChartData: PieChartData[] = [];
data.forEach(({ gender, count }) => {
newGenderPieChartData.push({
type: gender,
type: `${gender}성`,
value: count,
});
});
Expand Down
6 changes: 3 additions & 3 deletions src/components/organisms/MetroCouncilReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ const MetroCouncilReport = ({
const newGenderPieChartColorMap = new Map<string, string>();
const genderColors = [
{
type: "",
type: "남성",
color: "#289FD4",
},
{
type: "",
type: "여성",
color: "#AE2D6C",
},
];
Expand Down Expand Up @@ -189,7 +189,7 @@ const MetroCouncilReport = ({
const newGenderPieChartData: PieChartData[] = [];
data.forEach(({ gender, count }) => {
newGenderPieChartData.push({
type: gender,
type: `${gender}성`,
value: count,
});
});
Expand Down

0 comments on commit 4018af0

Please sign in to comment.