260225_01_ENH: 실제 Data 통계 API와 연결 및 일부 페이지 축소
This commit is contained in:
@@ -9,62 +9,141 @@ import {
|
||||
type TopChartTableRow,
|
||||
} from "@/components/lge-dashboard";
|
||||
import {
|
||||
LAST_YEAR,
|
||||
CHART_COLOR_BY_YEAR,
|
||||
CHART_FOCUS_COLOR_BY_YEAR,
|
||||
LIFE_STAGE_COLUMNS,
|
||||
LIFE_STAGE_GROUPS,
|
||||
PRODUCT_KEY_MAP,
|
||||
PRODUCT_KEYS,
|
||||
PRODUCTS, SITE_TITLE,
|
||||
SITE_TITLE,
|
||||
YEARS
|
||||
} from "@/const/lgConst";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {apiLifeStageByProduct, apiOwnShareOfTotalPenetration, apiTrendCategories} from "@/config/sample.data";
|
||||
import LifeStageDiv from "@/components/lge-dashboard/combo/LifeStageDiv";
|
||||
import { useLayoutFilter } from "@/components/layout/LayoutFilterContext";
|
||||
import { formatRowLabel } from "@/lib/lg-dashboard";
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {
|
||||
calcGapProductRow, calcTotalBaseRow,
|
||||
formatRowLabel,
|
||||
normalizeFilterCondition,
|
||||
withGapRow, withTotalBaseRow
|
||||
} from "@/lib/lg-dashboard";
|
||||
import {
|
||||
buildHeader_LifeStageColumns,
|
||||
buildHeader_ProductKeyMap,
|
||||
exportDashboardExcel,
|
||||
Section
|
||||
} from "@/lib/lg-export-excel";
|
||||
import {norm} from "@/lib/utils";
|
||||
import {LifeStageGroup, LifeStageRow} from "@/types/lg";
|
||||
import {toNumOr0} from "@/lib/utils";
|
||||
import {LifeStageGroup, LifeStageRow, ProductKey, StatisticsRequest} from "@/types/lg";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {SelectedMap} from "@/types/common";
|
||||
import {useBannerStatisticsQuery, useProductStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
||||
|
||||
const LGPenetrationPage = () => {
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
const {filterValue, registerExcelExporter} = useLayoutFilter();
|
||||
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap, 500);
|
||||
|
||||
//TODO: LG가 0인 제품은 제외시키기
|
||||
const req = useMemo<StatisticsRequest>(() => {
|
||||
return {
|
||||
variableIdMap: {penetration: "KQA1", penetration_lg: "KQA3_3_LG"},
|
||||
bannerIdList: ["product"],
|
||||
filterCondition: normalizeFilterCondition(debouncedFilterValue),
|
||||
option: {useCache: true, lastYear: false, decimalPoint: 0},
|
||||
};
|
||||
}, [debouncedFilterValue]);
|
||||
|
||||
const req_lifestage = useMemo<StatisticsRequest>(() => {
|
||||
const filter = {...debouncedFilterValue, "":""}
|
||||
|
||||
return {
|
||||
variableIdMap: {lifestage_lg: "KQA3_3_LG"},
|
||||
bannerIdList: ["product|lifeStage"],
|
||||
filterCondition: normalizeFilterCondition(filter),
|
||||
option: {useCache: true, lastYear: true, decimalPoint: 0},
|
||||
};
|
||||
}, [debouncedFilterValue]);
|
||||
|
||||
const {data, isError, error} = useProductStatisticsQuery(req);
|
||||
const {
|
||||
data: data_lifestage,
|
||||
isError: isError_lifestage,
|
||||
error: error_lifestage
|
||||
} = useBannerStatisticsQuery(req_lifestage);
|
||||
|
||||
if(isError){
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
if(isError_lifestage){
|
||||
console.error(error_lifestage);
|
||||
}
|
||||
|
||||
const penetrationRows =
|
||||
data?.statisticsDataMap?.penetration
|
||||
.filter((r) => r.rowLabel == `보유`)
|
||||
.map((row) => {
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
const penetrationLGRows =
|
||||
data?.statisticsDataMap?.penetration_lg
|
||||
.filter((row) => row.rowLabel === `보유`)
|
||||
.map((row) => {
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
const lifeStageRows =
|
||||
data_lifestage?.statisticsDataMap?.lifestage_lg
|
||||
.filter((r) => r.rowLabel == `보유`) ?? [];
|
||||
|
||||
const { includeProductKeys, productKeyMap, includeProducts } = useMemo(() => {
|
||||
const included = new Set<ProductKey>();
|
||||
|
||||
for (const row of penetrationLGRows) {
|
||||
for (const k of PRODUCT_KEYS) {
|
||||
if (!included.has(k) && toNumOr0((row as any)[k]) !== 0) included.add(k);
|
||||
}
|
||||
}
|
||||
|
||||
const keys = PRODUCT_KEYS.filter((k) => included.has(k));
|
||||
const map = Object.fromEntries(keys.map((k) => [k, PRODUCT_KEY_MAP[k]])) as Record<string, string>;
|
||||
const products = keys.map((k) => PRODUCT_KEY_MAP[k]);
|
||||
|
||||
return { includeProductKeys: keys, productKeyMap: map, includeProducts: products };
|
||||
}, [penetrationLGRows]);
|
||||
|
||||
const penetrationLGRowsWithGap = useMemo(() => {
|
||||
const withGap = withGapRow(penetrationLGRows, calcGapProductRow);
|
||||
return withTotalBaseRow("보급률",penetrationRows, withGap, calcTotalBaseRow);
|
||||
}, [penetrationRows, penetrationLGRows]);
|
||||
|
||||
const productTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||
return apiOwnShareOfTotalPenetration.map((row) => ({
|
||||
return penetrationLGRowsWithGap.map((row) => ({
|
||||
label: formatRowLabel(row.rowLabel),
|
||||
total: row.total,
|
||||
values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null),
|
||||
values: includeProductKeys.map((k) => (row as any)[k] ?? null),
|
||||
}));
|
||||
}, []);
|
||||
}, [penetrationLGRowsWithGap, includeProductKeys]);
|
||||
|
||||
const productChartData = useMemo<GroupedOverlayBarData>(() => {
|
||||
const total: Array<Array<number>> = YEARS.map(() => Array(PRODUCT_KEYS.length).fill(0));
|
||||
const focus: Array<Array<number>> = YEARS.map(() => Array(PRODUCT_KEYS.length).fill(0));
|
||||
const total: Array<Array<number>> = YEARS.map(() => Array(includeProductKeys.length).fill(0));
|
||||
const focus: Array<Array<number>> = YEARS.map(() => Array(includeProductKeys.length).fill(0));
|
||||
|
||||
const yearIndexMap = new Map<string, number>(YEARS.map((y, i) => [y, i]));
|
||||
|
||||
const totalRows = apiTrendCategories.filter(
|
||||
(r) => YEARS.includes(r.year as any) && r.rowLabel.endsWith("년")
|
||||
);
|
||||
const lgRows = apiOwnShareOfTotalPenetration.filter(
|
||||
(r) => YEARS.includes(r.year as any) && r.rowLabel.endsWith("년")
|
||||
);
|
||||
|
||||
lgRows.forEach((r, ri) => {
|
||||
penetrationLGRows.forEach((r, ri) => {
|
||||
const yi = yearIndexMap.get(r.year);
|
||||
if (yi == null) return;
|
||||
|
||||
for (let ci = 0; ci < PRODUCT_KEYS.length; ci++) {
|
||||
const k = PRODUCT_KEYS[ci];
|
||||
const t = (totalRows[ri] as any)[k];
|
||||
for (let ci = 0; ci < includeProductKeys.length; ci++) {
|
||||
const k = includeProductKeys[ci];
|
||||
const t = (penetrationRows[ri] as any)[k];
|
||||
const v = (r as any)[k];
|
||||
|
||||
total[yi][ci] = Number(t);
|
||||
@@ -73,47 +152,51 @@ const LGPenetrationPage = () => {
|
||||
});
|
||||
|
||||
return {
|
||||
categories: PRODUCTS,
|
||||
categories: includeProducts,
|
||||
years: YEARS,
|
||||
totalName: "전체",
|
||||
focusName: "LG",
|
||||
total,
|
||||
focus,
|
||||
};
|
||||
}, []);
|
||||
}, [penetrationRows, penetrationLGRows, includeProductKeys, includeProducts]);
|
||||
|
||||
const lifeStageRowsByGroup:LifeStageGroup[] = useMemo(() => {
|
||||
const pick = (label: string) => apiLifeStageByProduct.find((r) => norm(r.rowLabel) === norm(label));
|
||||
const lifeStageRowsByGroup: LifeStageGroup[] = useMemo(() => {
|
||||
if(lifeStageRows.length == 0){
|
||||
return [];
|
||||
}
|
||||
|
||||
const lifeStageData = lifeStageRows[0];
|
||||
|
||||
return LIFE_STAGE_GROUPS.map((g) => {
|
||||
const rows: LifeStageRow[] = g.items.map((label) => {
|
||||
const r = pick(label);
|
||||
const rows: LifeStageRow[] = g.items.map((key) => {
|
||||
const label = PRODUCT_KEY_MAP[key];
|
||||
|
||||
return {
|
||||
item: label,
|
||||
total: r?.total ?? "",
|
||||
single: r?.single ?? "",
|
||||
noKids: r?.noKids ?? "",
|
||||
preschoolKids: r?.preschoolKids ?? "",
|
||||
schoolKids: r?.schoolKids ?? "",
|
||||
adultKids: r?.adultKids ?? "",
|
||||
independentSenior: r?.independentSenior ?? "",
|
||||
total: lifeStageData[`${key}`] ?? "",
|
||||
"KLIFEstAGE#1": lifeStageData[`${key}|KLIFEstAGE#1`] ?? "",
|
||||
"KLIFEstAGE#2": lifeStageData[`${key}|KLIFEstAGE#2`] ?? "",
|
||||
"KLIFEstAGE#3": lifeStageData[`${key}|KLIFEstAGE#3`] ?? "",
|
||||
"KLIFEstAGE#4": lifeStageData[`${key}|KLIFEstAGE#4`] ?? "",
|
||||
"KLIFEstAGE#5": lifeStageData[`${key}|KLIFEstAGE#5`] ?? "",
|
||||
"KLIFEstAGE#6": lifeStageData[`${key}|KLIFEstAGE#6`] ?? "",
|
||||
};
|
||||
});
|
||||
|
||||
return { title: g.title, rows };
|
||||
return {title: g.title, rows};
|
||||
});
|
||||
}, []);
|
||||
}, [lifeStageRows]);
|
||||
|
||||
const description = useMemo(() => {
|
||||
return "Q. 다음 중 귀댁에서 보유하고 계신 가전/전자 제품은 무엇입니까? 모두 선택해주세요.<br/>" +
|
||||
"* 구독/렌탈/선물/경품/아파트 내 빌트인 제품을 모두 포함하여 선택해주세요.<br/>" +
|
||||
"Q. 보유하고 계신 (제품)의 브랜드는 어떻게 되십니까?";
|
||||
"* 구독/렌탈/선물/경품/아파트 내 빌트인 제품을 모두 포함하여 선택해주세요.<br/>" +
|
||||
"Q. 보유하고 계신 (제품)의 브랜드는 어떻게 되십니까?";
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async () => {
|
||||
const excelHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP);
|
||||
const excelHeader = buildHeader_ProductKeyMap(productKeyMap);
|
||||
const lifeStageHeader = buildHeader_LifeStageColumns(LIFE_STAGE_COLUMNS);
|
||||
|
||||
type AnyRow = Record<string, any>;
|
||||
@@ -122,7 +205,7 @@ const LGPenetrationPage = () => {
|
||||
{
|
||||
title: "LG제품 보급률",
|
||||
header: excelHeader,
|
||||
rows: apiOwnShareOfTotalPenetration as AnyRow[],
|
||||
rows: penetrationLGRowsWithGap as AnyRow[],
|
||||
rowGap: 1,
|
||||
},
|
||||
|
||||
@@ -141,28 +224,29 @@ const LGPenetrationPage = () => {
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter]);
|
||||
}, [registerExcelExporter, penetrationLGRowsWithGap, lifeStageRowsByGroup, productKeyMap]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<TopChartTable
|
||||
title={"LG제품 보급률"}
|
||||
categories={[...PRODUCTS]}
|
||||
categories={[...includeProducts]}
|
||||
rows={productTableRows}
|
||||
chart={
|
||||
<GroupedOverlayBar
|
||||
data={productChartData}
|
||||
yearTotalColor={{ "24": "--chart-3-t", "25": "--chart-2-t", "26": "--chart-1-t" }}
|
||||
yearFocusColor={{ "24": "--chart-3", "25": "--chart-2", "26": "--chart-1" }}
|
||||
yearTotalColor={CHART_COLOR_BY_YEAR}
|
||||
yearFocusColor={CHART_FOCUS_COLOR_BY_YEAR}
|
||||
showFocusLabel={"last"}
|
||||
height={260}
|
||||
/>
|
||||
}
|
||||
signStyle={signStyleGapRow}
|
||||
/>
|
||||
|
||||
<BottomDescription description={description} />
|
||||
<BottomDescription description={description}/>
|
||||
|
||||
<LifeStageDiv lifeStageRowsByGroup={lifeStageRowsByGroup} />
|
||||
<LifeStageDiv lifeStageRowsByGroup={lifeStageRowsByGroup}/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,70 +1,132 @@
|
||||
"use client";
|
||||
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {LAST_YEAR, PRODUCT_KEY_MAP, PRODUCT_KEYS, PRODUCTS, SITE_TITLE, YEARS} from "@/const/lgConst";
|
||||
import {
|
||||
CHART_COLOR_BY_YEAR, CHART_FOCUS_COLOR_BY_YEAR,
|
||||
PRODUCT_KEY_MAP,
|
||||
PRODUCT_KEYS,
|
||||
SITE_TITLE,
|
||||
YEARS
|
||||
} from "@/const/lgConst";
|
||||
import {
|
||||
BottomDescription,
|
||||
GroupedOverlayBar,
|
||||
type GroupedOverlayBarData,
|
||||
signStyleGapRow,
|
||||
TopChartTable,
|
||||
type TopChartTableRow,
|
||||
} from "@/components/lge-dashboard";
|
||||
import { apiOwnShareOfTotalPurchase, apiTrendBuy } from "@/config/sample.data";
|
||||
import { useLayoutFilter } from "@/components/layout/LayoutFilterContext";
|
||||
import { formatRowLabel } from "@/lib/lg-dashboard";
|
||||
import {
|
||||
calcGapProductRow, calcTotalBaseRow,
|
||||
formatRowLabel,
|
||||
normalizeFilterCondition,
|
||||
withGapRow, withTotalBaseRow
|
||||
} from "@/lib/lg-dashboard";
|
||||
import {buildHeader_ProductKeyMap, exportDashboardExcel} from "@/lib/lg-export-excel";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {SelectedMap} from "@/types/common";
|
||||
import {ProductKey, StatisticsRequest} from "@/types/lg";
|
||||
import {useProductStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
||||
import {toNumOr0} from "@/lib/utils";
|
||||
|
||||
const LGPurchasePage = () => {
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap, 500);
|
||||
|
||||
//TODO: LG가 0인 제품은 제외시키기
|
||||
const req = useMemo<StatisticsRequest>(() => {
|
||||
return {
|
||||
variableIdMap: {purchase: "KQA3_2", purchase_lg: "KQX3_3_LG"},
|
||||
bannerIdList: ["product"],
|
||||
filterCondition: normalizeFilterCondition(debouncedFilterValue),
|
||||
option: {useCache: false, lastYear: false, decimalPoint: 0},
|
||||
};
|
||||
}, [debouncedFilterValue]);
|
||||
|
||||
const {data, isError, error} = useProductStatisticsQuery(req);
|
||||
|
||||
if(isError){
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
const purchaseRows =
|
||||
data?.statisticsDataMap?.purchase
|
||||
.filter((r) => r.rowLabel == `해당년도`)
|
||||
.map((row) => {
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
const purchaseLGRows =
|
||||
data?.statisticsDataMap?.purchase_lg
|
||||
.filter((row) => row.rowLabel === `구입`)
|
||||
.map((row) => {
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
const purchaseLGRowsWithGap = useMemo(() => {
|
||||
const withGap = withGapRow(purchaseLGRows, calcGapProductRow);
|
||||
return withTotalBaseRow("구입율",purchaseRows, withGap, calcTotalBaseRow);
|
||||
}, [purchaseRows, purchaseLGRows]);
|
||||
|
||||
const { includeProductKeys, productKeyMap, includeProducts } = useMemo(() => {
|
||||
const included = new Set<ProductKey>();
|
||||
|
||||
for (const row of purchaseLGRows) {
|
||||
for (const k of PRODUCT_KEYS) {
|
||||
if (!included.has(k) && toNumOr0((row as any)[k]) !== 0) included.add(k);
|
||||
}
|
||||
}
|
||||
|
||||
const keys = PRODUCT_KEYS.filter((k) => included.has(k));
|
||||
const map = Object.fromEntries(keys.map((k) => [k, PRODUCT_KEY_MAP[k]])) as Record<string, string>;
|
||||
const products = keys.map((k) => PRODUCT_KEY_MAP[k]);
|
||||
|
||||
return { includeProductKeys: keys, productKeyMap: map, includeProducts: products };
|
||||
}, [purchaseLGRows]);
|
||||
|
||||
const purchaseTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||
return apiOwnShareOfTotalPurchase.map((row) => ({
|
||||
return purchaseLGRowsWithGap.map((row) => ({
|
||||
label: formatRowLabel(row.rowLabel),
|
||||
total: row.total,
|
||||
values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null),
|
||||
values: includeProductKeys.map((k) => (row as any)[k] ?? null),
|
||||
}));
|
||||
}, []);
|
||||
}, [purchaseLGRowsWithGap, includeProductKeys]);
|
||||
|
||||
const purchaseChartData = useMemo<GroupedOverlayBarData>(() => {
|
||||
const total: Array<Array<number>> = YEARS.map(() => Array(PRODUCT_KEYS.length).fill(0));
|
||||
const focus: Array<Array<number>> = YEARS.map(() => Array(PRODUCT_KEYS.length).fill(0));
|
||||
const total: Array<Array<number>> = YEARS.map(() => Array(includeProductKeys.length).fill(0));
|
||||
const focus: Array<Array<number>> = YEARS.map(() => Array(includeProductKeys.length).fill(0));
|
||||
|
||||
const yearIndexMap = new Map<string, number>(YEARS.map((y, i) => [y, i]));
|
||||
|
||||
const totalRows = apiTrendBuy.filter(
|
||||
(r) => YEARS.includes(r.year as any) && r.rowLabel.endsWith("년")
|
||||
);
|
||||
const lgRows = apiOwnShareOfTotalPurchase.filter(
|
||||
(r) => YEARS.includes(r.year as any) && r.rowLabel.endsWith("년")
|
||||
);
|
||||
|
||||
lgRows.forEach((r, ri) => {
|
||||
purchaseLGRows.forEach((r, ri) => {
|
||||
const yi = yearIndexMap.get(r.year);
|
||||
if (yi == null) return;
|
||||
|
||||
for (let ci = 0; ci < PRODUCT_KEYS.length; ci++) {
|
||||
const k = PRODUCT_KEYS[ci];
|
||||
const t = (totalRows[ri] as any)[k];
|
||||
for (let ci = 0; ci < includeProductKeys.length; ci++) {
|
||||
const k = includeProductKeys[ci];
|
||||
const t = (purchaseRows[ri] as any)[k];
|
||||
const v = (r as any)[k];
|
||||
|
||||
// total은 t 기준으로 체크해야 안전
|
||||
total[yi][ci] = Number(t);
|
||||
focus[yi][ci] = Number(v);
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
categories: PRODUCTS,
|
||||
categories: includeProducts,
|
||||
years: YEARS,
|
||||
totalName: "전체",
|
||||
focusName: "LG",
|
||||
total,
|
||||
focus,
|
||||
};
|
||||
}, []);
|
||||
}, [purchaseRows, purchaseLGRows, includeProducts, includeProductKeys]);
|
||||
|
||||
const description = useMemo(() => {
|
||||
return "Q. 다음 중 귀댁에서 보유하고 계신 가전/전자 제품은 무엇입니까? 모두 선택해주세요.<br/>" +
|
||||
@@ -78,35 +140,38 @@ const LGPurchasePage = () => {
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async () => {
|
||||
const excelHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP);
|
||||
const excelHeader = buildHeader_ProductKeyMap(productKeyMap);
|
||||
|
||||
await exportDashboardExcel({
|
||||
fileName: `${SITE_TITLE}(LG제품 구매율).xlsx`,
|
||||
sheetName: "LG제품 구매율",
|
||||
sections: [
|
||||
{ title: "LG제품 구매율", header: excelHeader, rows: apiOwnShareOfTotalPurchase, rowGap: 1 },
|
||||
{ title: "LG제품 구매율", header: excelHeader, rows: purchaseLGRowsWithGap, rowGap: 1 },
|
||||
],
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter]);
|
||||
}, [registerExcelExporter, purchaseLGRowsWithGap]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<TopChartTable
|
||||
title={"LG제품 구매율"}
|
||||
categories={[...PRODUCTS]}
|
||||
categories={[...includeProducts]}
|
||||
rows={purchaseTableRows}
|
||||
chart={
|
||||
<GroupedOverlayBar
|
||||
data={purchaseChartData}
|
||||
yearTotalColor={{ "24": "--chart-3-t", "25": "--chart-2-t", "26": "--chart-1-t" }}
|
||||
yearFocusColor={{ "24": "--chart-3", "25": "--chart-2", "26": "--chart-1" }}
|
||||
yearTotalColor={CHART_COLOR_BY_YEAR}
|
||||
yearFocusColor={CHART_FOCUS_COLOR_BY_YEAR}
|
||||
showFocusLabel={"last"}
|
||||
height={260}
|
||||
/>
|
||||
}
|
||||
signStyle={signStyleGapRow}
|
||||
/>
|
||||
|
||||
<BottomDescription description={description}/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
type GroupedStackBarData, BottomDescription,
|
||||
} from "@/components/lge-dashboard";
|
||||
import { useLayoutFilter } from "@/components/layout/LayoutFilterContext";
|
||||
import {apiBrandByYearCategories, apiTrendCategories} from "@/config/sample.data";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
BRAND_LIST,
|
||||
@@ -19,40 +18,89 @@ import {
|
||||
PRODUCTS,
|
||||
YEARS,
|
||||
AXIS_HIDE_STYLE,
|
||||
GRID_X_NOT_PADDING, PRODUCT_KEY_MAP, LAST_YEAR, SITE_TITLE,
|
||||
GRID_X_NOT_PADDING, PRODUCT_KEY_MAP, SITE_TITLE
|
||||
} from "@/const/lgConst";
|
||||
import { formatRowLabel } from "@/lib/lg-dashboard";
|
||||
import {
|
||||
calcCagrRow, calcGapProductRow,
|
||||
formatRowLabel,
|
||||
normalizeFilterCondition, withCagrRow, withGapRow
|
||||
} from "@/lib/lg-dashboard";
|
||||
import {buildHeader_ProductKeyMap, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||
import {StatisticsRequest} from "@/types/lg";
|
||||
import {useProductStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {toNumOr0} from "@/lib/utils";
|
||||
import {SelectedMap} from "@/types/common";
|
||||
|
||||
const PenetrationPage = () => {
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap, 500);
|
||||
const [isBrandShare, setIsBrandShare] = useState(false);
|
||||
|
||||
const chartColorByYear = Object.fromEntries(
|
||||
YEARS.map((year, i) => [
|
||||
year,
|
||||
[`--chart-cbrand-${i + 1}`,`--chart-samsung-${i + 1}`,`--chart-lg-${i + 1}`],
|
||||
])
|
||||
) as Record<(typeof YEARS)[number], string[]>;
|
||||
|
||||
const req = useMemo<StatisticsRequest>(() => {
|
||||
return {
|
||||
variableIdMap: { penetration: "KQA1", penetration_brand: "KQA3_3_NET" },
|
||||
bannerIdList: ["product"],
|
||||
filterCondition: normalizeFilterCondition(debouncedFilterValue),
|
||||
option: { useCache: true, lastYear: false, decimalPoint: 0 },
|
||||
};
|
||||
}, [debouncedFilterValue]);
|
||||
|
||||
const { data, isError, error } = useProductStatisticsQuery(req);
|
||||
|
||||
if(isError){
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
const penetrationRows =
|
||||
data?.statisticsDataMap?.penetration
|
||||
.filter((r) => r.rowLabel == `보유`)
|
||||
.map((row) => {
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
const penetrationBrandRows =
|
||||
data?.statisticsDataMap?.penetration_brand
|
||||
.filter((row) => BRAND_LIST.includes(row.rowLabel)) ?? [];
|
||||
|
||||
const penetrationRowsWithGapCagr = useMemo(() => {
|
||||
const withGap = withGapRow(penetrationRows, calcGapProductRow);
|
||||
return withCagrRow(withGap, calcCagrRow);
|
||||
}, [penetrationRows]);
|
||||
|
||||
const productTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||
return apiTrendCategories.map((row) => ({
|
||||
return penetrationRowsWithGapCagr.map((row) => ({
|
||||
label: formatRowLabel(row.rowLabel),
|
||||
total: row.total,
|
||||
values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null),
|
||||
}));
|
||||
}, []);
|
||||
}))
|
||||
}, [penetrationRowsWithGapCagr]);
|
||||
|
||||
const productChartData = useMemo<ChartData>(() => {
|
||||
return {
|
||||
categories: [...PRODUCTS],
|
||||
series: apiTrendCategories
|
||||
.filter((r) => r.rowLabel.endsWith("년"))
|
||||
.map((r) => ({
|
||||
name: r.rowLabel,
|
||||
data: PRODUCT_KEYS.map((k) => (r as any)[k] ?? null),
|
||||
})),
|
||||
series: penetrationRows
|
||||
.map((row) => ({
|
||||
name: row.year,
|
||||
data: PRODUCT_KEYS.map((k) => toNumOr0((row as any)[k])),
|
||||
})),
|
||||
};
|
||||
}, []);
|
||||
}, [penetrationRows]);
|
||||
|
||||
const brandShareChartData = useMemo<GroupedStackBarData>(() => {
|
||||
const rowMap = new Map<string, (typeof apiBrandByYearCategories)[number]>();
|
||||
for (const r of apiBrandByYearCategories) {
|
||||
|
||||
const rowMap = new Map<string, (typeof penetrationBrandRows)[number]>();
|
||||
for (const r of penetrationBrandRows) {
|
||||
rowMap.set(`${r.year}__${r.rowLabel}`, r);
|
||||
}
|
||||
|
||||
@@ -70,7 +118,7 @@ const PenetrationPage = () => {
|
||||
});
|
||||
|
||||
return { categories: PRODUCTS, years: YEARS, brands: BRAND_LIST, values };
|
||||
}, []);
|
||||
}, [penetrationBrandRows]);
|
||||
|
||||
const description = useMemo(() => {
|
||||
if(isBrandShare){
|
||||
@@ -78,7 +126,7 @@ const PenetrationPage = () => {
|
||||
}
|
||||
|
||||
return "Q. 다음 중 귀댁에서 보유하고 계신 가전/전자 제품은 무엇입니까? 모두 선택해주세요.<br/>" +
|
||||
"* 구독/렌탈/선물/경품/아파트 내 빌트인 제품을 모두 포함하여 선택해주세요.";
|
||||
"* 구독/렌탈/선물/경품/아파트 내 빌트인 제품을 모두 포함하여 선택해주세요.";
|
||||
}, [isBrandShare]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -87,12 +135,12 @@ const PenetrationPage = () => {
|
||||
type AnyRow = Record<string, any>;
|
||||
|
||||
const sections: Section<AnyRow>[] = [
|
||||
{ title: "전체 보급률", header: excelHeader, rows: apiTrendCategories, rowGap: 1 },
|
||||
{ title: "전체 보급률", header: excelHeader, rows: penetrationRowsWithGapCagr, rowGap: 1 },
|
||||
...YEARS.map((year) => (
|
||||
{
|
||||
title: `브랜드 별 점유율_${year}년`,
|
||||
header: excelHeader,
|
||||
rows: apiBrandByYearCategories.filter((row) => row.year === year) as AnyRow[],
|
||||
rows: penetrationBrandRows.filter((row) => row.year === year),
|
||||
rowGap: 1,
|
||||
}
|
||||
))
|
||||
@@ -105,7 +153,7 @@ const PenetrationPage = () => {
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter]);
|
||||
}, [registerExcelExporter, penetrationRows, penetrationBrandRows]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -131,11 +179,8 @@ const PenetrationPage = () => {
|
||||
xAxis={{ type: "category", data: PRODUCTS, ...AXIS_HIDE_STYLE }}
|
||||
yAxis={{ type: "value", ...AXIS_HIDE_STYLE }}
|
||||
showFocusLabel={"none"}
|
||||
yearBrandPalette={{
|
||||
"24": ["--chart-cbrand-1", "--chart-samsung-1", "--chart-lg-1"],
|
||||
"25": ["--chart-cbrand-2", "--chart-samsung-2", "--chart-lg-2"],
|
||||
"26": ["--chart-cbrand-3", "--chart-samsung-3", "--chart-lg-3"],
|
||||
}}
|
||||
yearBrandPalette={chartColorByYear}
|
||||
height={260}
|
||||
/>
|
||||
) : (
|
||||
<VerticalBar
|
||||
|
||||
@@ -17,34 +17,65 @@ import {
|
||||
type TopChartTableRow,
|
||||
VerticalBar,
|
||||
} from "@/components/lge-dashboard";
|
||||
import { apiTrendBuy } from "@/config/sample.data";
|
||||
import { useLayoutFilter } from "@/components/layout/LayoutFilterContext";
|
||||
import { formatRowLabel } from "@/lib/lg-dashboard";
|
||||
import {calcGapProductRow, formatRowLabel, normalizeFilterCondition, withGapRow} from "@/lib/lg-dashboard";
|
||||
import {buildHeader_ProductKeyMap, exportDashboardExcel} from "@/lib/lg-export-excel";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {SelectedMap} from "@/types/common";
|
||||
import {StatisticsRequest} from "@/types/lg";
|
||||
import {useProductStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
||||
|
||||
const PurchasePage = () => {
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap, 500);
|
||||
|
||||
const req = useMemo<StatisticsRequest>(() => {
|
||||
return {
|
||||
variableIdMap: { purchase: "KQA3_2"},
|
||||
bannerIdList: ["product"],
|
||||
filterCondition: normalizeFilterCondition(debouncedFilterValue),
|
||||
option: { useCache: true, lastYear: false, decimalPoint: 0 },
|
||||
};
|
||||
}, [debouncedFilterValue]);
|
||||
|
||||
const { data, isError, error } = useProductStatisticsQuery(req);
|
||||
|
||||
if(isError){
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
const purchaseRows =
|
||||
data?.statisticsDataMap?.purchase
|
||||
.filter((r) => r.rowLabel == `해당년도`)
|
||||
.map((row) => {
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
const purchaseRowsWithGap = useMemo(() => {
|
||||
return withGapRow(purchaseRows, calcGapProductRow);
|
||||
}, [purchaseRows]);
|
||||
|
||||
const purchaseTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||
return apiTrendBuy.map((row) => ({
|
||||
return purchaseRowsWithGap.map((row) => ({
|
||||
label: formatRowLabel(row.rowLabel),
|
||||
total: row.total,
|
||||
values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null),
|
||||
}));
|
||||
}, []);
|
||||
}, [purchaseRowsWithGap]);
|
||||
|
||||
const purchaseChartData = useMemo<ChartData>(() => {
|
||||
return {
|
||||
categories: [...PRODUCTS],
|
||||
series: apiTrendBuy
|
||||
.filter((r) => r.rowLabel.endsWith("년"))
|
||||
series: purchaseRows
|
||||
.map((r) => ({
|
||||
name: r.rowLabel,
|
||||
data: PRODUCT_KEYS.map((k) => (r as any)[k] ?? null),
|
||||
})),
|
||||
};
|
||||
}, []);
|
||||
}, [purchaseRows]);
|
||||
|
||||
const description = useMemo(() => {
|
||||
return "Q. 다음 중 귀댁에서 보유하고 계신 가전/전자 제품은 무엇입니까? 모두 선택해주세요.<br/>" +
|
||||
@@ -63,12 +94,12 @@ const PurchasePage = () => {
|
||||
fileName: `${SITE_TITLE}(구매율).xlsx`,
|
||||
sheetName: "구매율",
|
||||
sections: [
|
||||
{ title: "구매율", header: excelHeader, rows: apiTrendBuy, rowGap: 1 },
|
||||
{ title: "구매율", header: excelHeader, rows: purchaseRowsWithGap, rowGap: 1 },
|
||||
],
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter]);
|
||||
}, [registerExcelExporter, purchaseRowsWithGap]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user