260128_03_ENH: 샘플데이터 랜덤 적용, lg 보급률 하단 카드 + 게이지 테이블 적용
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
'use client'
|
||||
|
||||
import {Button} from "@/components/ui/button";
|
||||
import TopChartTable from "../../../../../components/lge-dashboard/combo/TopChartTable";
|
||||
import {
|
||||
GroupedOverlayBar, GroupedOverlayBarData,
|
||||
signStyleGapRow, TopChartTableRow
|
||||
GaugeCardTable, GaugeColumn,
|
||||
GroupedOverlayBar, GroupedOverlayBarData, LifeStageRow,
|
||||
signStyleGapRow, TopChartTable, TopChartTableRow
|
||||
} from "@/components/lge-dashboard";
|
||||
import {PRODUCT_KEYS, PRODUCTS, YEARS} from "@/const/lgConst";
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {useEffect} from "react";
|
||||
import {apiOwnShareOfTotalPenetration, apiTrendCategories} from "@/config/sample.data";
|
||||
import {useMemo} from "react";
|
||||
import {
|
||||
apiLifeStageByProduct,
|
||||
apiLifeStageByProductForGauge,
|
||||
apiOwnShareOfTotalPenetration,
|
||||
apiTrendCategories
|
||||
} from "@/config/sample.data";
|
||||
|
||||
const LGPenetrationPage = () => {
|
||||
|
||||
@@ -54,6 +57,53 @@ const LGPenetrationPage = () => {
|
||||
focus: focus,
|
||||
}
|
||||
|
||||
const norm = (s: string) => s.replace(/\s+/g, "").toLowerCase();
|
||||
const asNum = (v: unknown): number | null => typeof v === "number" && Number.isFinite(v) ? v : null;
|
||||
|
||||
const LIFE_STAGE_COLUMNS: GaugeColumn<LifeStageRow>[] = [
|
||||
{ key: "item", header: "", rowHead: true, renderLabel: (r) => r.item },
|
||||
|
||||
{ key: "total", header: "전체", max: 100, align: "left", cellType:"number"},
|
||||
{ key: "single", header: "미혼", max: 100 , align: "left"},
|
||||
|
||||
{ key: "noKids", header: "무자녀", group: "기혼", max: 100 , align: "left"},
|
||||
{ key: "preschoolKids", header: "미취학", group: "기혼", max: 100 , align: "left"},
|
||||
{ key: "schoolKids", header: "취학자녀", group: "기혼", max: 100 , align: "left"},
|
||||
{ key: "adultKids", header: "성인자녀", group: "기혼", max: 100 , align: "left"},
|
||||
|
||||
{ key: "independentSenior", header: "독립\n시니어", max: 100 , align: "left"},
|
||||
];
|
||||
|
||||
const LIFE_STAGE_GROUPS = [
|
||||
{ title: "필수가전 군", items: ["냉장고", "세탁기", "에어컨", "TV", "청소기", "김치 냉장고"] },
|
||||
{ title: "케어가전 군", items: ["공기 청정기", "가습기", "제습기"] },
|
||||
{ title: "Must & Best", items: ["건조기", "식기 세척기", "의류 관리기"] },
|
||||
{ title: "신가전 군", items: ["로봇 청소기"] },
|
||||
] as const;
|
||||
|
||||
const lifeStageRowsByGroup = useMemo(() => {
|
||||
const pick = (label: string) => apiLifeStageByProduct.find((r) => norm(r.rowLabel) === norm(label));
|
||||
|
||||
return LIFE_STAGE_GROUPS.map((g) => {
|
||||
const rows: LifeStageRow[] = g.items.map((label) => {
|
||||
const r = pick(label);
|
||||
|
||||
return {
|
||||
item: label,
|
||||
total: asNum((r as any)?.total), // 서버에 all이 없으면 null로 남음
|
||||
single: asNum((r as any)?.single),
|
||||
noKids: asNum((r as any)?.noKids),
|
||||
preschoolKids: asNum((r as any)?.preschoolKids),
|
||||
schoolKids: asNum((r as any)?.schoolKids),
|
||||
adultKids: asNum((r as any)?.adultKids),
|
||||
independentSenior: asNum((r as any)?.independentSenior),
|
||||
};
|
||||
});
|
||||
|
||||
return { title: g.title, rows };
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<TopChartTable
|
||||
@@ -70,6 +120,35 @@ const LGPenetrationPage = () => {
|
||||
}
|
||||
signStyle={signStyleGapRow}
|
||||
/>
|
||||
|
||||
<div className="mt-6">
|
||||
<div className="flex justify-end gap-6 text-xs text-muted-foreground mb-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="inline-block h-3 w-5 border bg-gray-200"/>
|
||||
<span>제품 보유율</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<span
|
||||
className="inline-block h-3 w-5 border"
|
||||
style={{ backgroundColor: "hsl(var(--lg-pink-300) / 0.4)" }}
|
||||
/>
|
||||
<span>시장 기회공간</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
{lifeStageRowsByGroup.map((g) => (
|
||||
<GaugeCardTable
|
||||
key={g.title}
|
||||
title={g.title}
|
||||
columns={LIFE_STAGE_COLUMNS}
|
||||
rows={g.rows}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
'use client'
|
||||
|
||||
import TopChartTable from "../../../../../components/lge-dashboard/combo/TopChartTable";
|
||||
|
||||
import {PRODUCT_KEYS, PRODUCTS, YEARS} from "@/const/lgConst";
|
||||
import {GroupedOverlayBar, GroupedOverlayBarData, signStyleGapRow, TopChartTableRow} from "@/components/lge-dashboard";
|
||||
import {
|
||||
GroupedOverlayBar,
|
||||
GroupedOverlayBarData,
|
||||
signStyleGapRow,
|
||||
TopChartTable,
|
||||
TopChartTableRow
|
||||
} from "@/components/lge-dashboard";
|
||||
import { apiOwnShareOfTotalPurchase, apiTrendBuy} from "@/config/sample.data";
|
||||
|
||||
const LGPurchasePage = () => {
|
||||
|
||||
@@ -5,14 +5,12 @@ import TopChartTable from "@/components/lge-dashboard/combo/TopChartTable";
|
||||
|
||||
import VerticalBar from "@/components/lge-dashboard/chart/VerticalBar";
|
||||
import {
|
||||
AXIS_HIDE_STYLE, ChartData,
|
||||
GRID_X_NOT_PADDING,
|
||||
GroupedStackBar, signStyleGapRow, TopChartTableRow, GroupedStackBarData
|
||||
ChartData, GroupedStackBar, signStyleGapRow, TopChartTableRow, GroupedStackBarData
|
||||
} 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, PRODUCT_KEYS, PRODUCTS, YEARS} from "@/const/lgConst";
|
||||
import {BRAND_LIST, PRODUCT_KEYS, PRODUCTS, YEARS, AXIS_HIDE_STYLE, GRID_X_NOT_PADDING} from "@/const/lgConst";
|
||||
|
||||
|
||||
const PenetrationPage = () => {
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
'use client'
|
||||
|
||||
import {Button} from "@/components/ui/button";
|
||||
import TopChartTable from "../../../../../components/lge-dashboard/combo/TopChartTable";
|
||||
import {PRODUCT_KEYS, PRODUCTS} from "@/const/lgConst";
|
||||
import {PRODUCT_KEYS, PRODUCTS, AXIS_HIDE_STYLE, GRID_X_NOT_PADDING} from "@/const/lgConst";
|
||||
import {
|
||||
AXIS_HIDE_STYLE, ChartData,
|
||||
GRID_X_NOT_PADDING,
|
||||
signStyleGapRow,
|
||||
TopChartTableRow
|
||||
ChartData,
|
||||
signStyleGapRow, TopChartTable,
|
||||
TopChartTableRow, VerticalBar
|
||||
} from "@/components/lge-dashboard";
|
||||
import VerticalBar from "../../../../../components/lge-dashboard/chart/VerticalBar";
|
||||
import {apiTrendBuy} from "@/config/sample.data";
|
||||
|
||||
const PurchasePage = () => {
|
||||
|
||||
@@ -11,8 +11,9 @@ import type {
|
||||
} from "echarts";
|
||||
import BaseEChart from "../BaseEChart";
|
||||
import { buildLgPalette } from "../color";
|
||||
import {AXIS_HIDE_STYLE, GroupedOverlayBarData, ShowLabel} from "../types";
|
||||
import { GroupedOverlayBarData, ShowLabel} from "../types";
|
||||
import {getIsShowLabel, roundedRectIcon} from "@/components/lge-dashboard/chart/utill";
|
||||
import {AXIS_HIDE_STYLE} from "@/const/lgConst";
|
||||
|
||||
type Props = {
|
||||
data: GroupedOverlayBarData;
|
||||
|
||||
@@ -10,9 +10,10 @@ import type {
|
||||
SeriesOption, EChartsOption,
|
||||
} from "echarts";
|
||||
import BaseEChart from "../BaseEChart";
|
||||
import {AXIS_HIDE_STYLE, GroupedStackBarData, ShowLabel} from "../types";
|
||||
import { GroupedStackBarData, ShowLabel} from "../types";
|
||||
import { buildLgPalette } from "@/components/lge-dashboard/color";
|
||||
import {getIsShowLabel, roundedRectIcon} from "@/components/lge-dashboard/chart/utill";
|
||||
import {AXIS_HIDE_STYLE} from "@/const/lgConst";
|
||||
|
||||
type Props = {
|
||||
data: GroupedStackBarData;
|
||||
|
||||
58
src/components/lge-dashboard/combo/GaugeCardTable.tsx
Normal file
58
src/components/lge-dashboard/combo/GaugeCardTable.tsx
Normal file
@@ -0,0 +1,58 @@
|
||||
"use client";
|
||||
|
||||
import React from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import {GaugeColumn, GaugeTable} from "@/components/lge-dashboard";
|
||||
import Card from "@/components/lge-dashboard/card/Card";
|
||||
|
||||
export type GaugeCardTableProps<T> = {
|
||||
/** 카드 제목 */
|
||||
title: string;
|
||||
/** GaugeTable columns */
|
||||
columns: GaugeColumn<T>[];
|
||||
/** GaugeTable rows */
|
||||
rows: T[];
|
||||
|
||||
/** GaugeTable 옵션들 (필요한 것만 노출) */
|
||||
cellHeight?: number;
|
||||
fillColor?: string;
|
||||
trackColor?: string;
|
||||
|
||||
className?: string;
|
||||
cardClassName?: string;
|
||||
tableClassName?: string;
|
||||
};
|
||||
|
||||
const GaugeCardTable = <T extends Record<string, unknown>>(
|
||||
props: GaugeCardTableProps<T>
|
||||
) => {
|
||||
const {
|
||||
title,
|
||||
columns,
|
||||
rows,
|
||||
cellHeight = 26,
|
||||
fillColor,
|
||||
trackColor,
|
||||
className,
|
||||
cardClassName,
|
||||
tableClassName,
|
||||
} = props;
|
||||
|
||||
return (
|
||||
<div className={cn("w-full", className)}>
|
||||
<Card label={title} className={cardClassName}>
|
||||
<div className={cn("w-full", tableClassName)}>
|
||||
<GaugeTable
|
||||
columns={columns}
|
||||
rows={rows}
|
||||
cellHeight={cellHeight}
|
||||
fillColor={fillColor}
|
||||
trackColor={trackColor}
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default GaugeCardTable;
|
||||
@@ -13,5 +13,7 @@ export { default as GaugeTable } from "./table/GaugeTable";
|
||||
|
||||
export { default as TopChartTable } from "./combo/TopChartTable";
|
||||
export { default as LeftChartTable } from "./combo/LeftChartTable";
|
||||
export { default as GaugeCardTable } from "./combo/GaugeCardTable";
|
||||
export { default as CategoryByData } from "./combo/CategoryByData"
|
||||
|
||||
export { default as CardDefault } from "./card/Card";
|
||||
|
||||
@@ -21,7 +21,6 @@ type Props<T extends Record<string, unknown>> = {
|
||||
cellHeight?: number; // 기본 26
|
||||
|
||||
/** 숫자 표시 여부/포맷 */
|
||||
showValue?: boolean; // 기본 true
|
||||
valueFormatter?: (v: number) => string;
|
||||
};
|
||||
|
||||
@@ -40,10 +39,9 @@ const GaugeTable = <T extends Record<string, unknown>>({
|
||||
className,
|
||||
wrapperClassName,
|
||||
scale = 1,
|
||||
fillColor = "hsl(var(--primary) / 0.85)",
|
||||
trackColor = "hsl(var(--lg-gray-200) / 0.85)",
|
||||
fillColor = "hsl(var(--lg-gray-200) / 0.85)",
|
||||
trackColor = "hsl(var(--lg-pink-300) / 0.2)",
|
||||
cellHeight = 26,
|
||||
showValue = true,
|
||||
valueFormatter,
|
||||
}: Props<T>) => {
|
||||
const hasGroup = columns.some((c) => !!c.group);
|
||||
@@ -68,9 +66,23 @@ const GaugeTable = <T extends Record<string, unknown>>({
|
||||
|
||||
const fmt = valueFormatter ?? ((v: number) => String(Math.round(v)));
|
||||
|
||||
const clamp01 = (n: number) => Math.max(0, Math.min(1, n));
|
||||
|
||||
return (
|
||||
<div className={cn("w-full overflow-x-auto", wrapperClassName)}>
|
||||
<table className={cn("lg-table", className)}>
|
||||
<table className={cn("lg-table", className)} style={{minWidth:"100%"}}>
|
||||
<colgroup>
|
||||
{columns.map((c, i) => (
|
||||
<col
|
||||
key={`${String(c.key)}-${i}`}
|
||||
style={{
|
||||
width:
|
||||
c.width ??
|
||||
(c.rowHead ? 50 : 40), // 기본 폭(필요시 숫자 조절)
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</colgroup>
|
||||
<thead>
|
||||
{hasGroup && (
|
||||
<tr className="lg-table__group">
|
||||
@@ -83,7 +95,7 @@ const GaugeTable = <T extends Record<string, unknown>>({
|
||||
)}
|
||||
<tr className={hasGroup ? "lg-table__subhead" : undefined}>
|
||||
{columns.map((c) => (
|
||||
<th key={String(c.key)} style={{ width: c.width }}>
|
||||
<th key={String(c.key)}>
|
||||
{c.header}
|
||||
</th>
|
||||
))}
|
||||
@@ -95,6 +107,7 @@ const GaugeTable = <T extends Record<string, unknown>>({
|
||||
<tr key={rIdx}>
|
||||
{columns.map((c) => {
|
||||
const align = c.align ?? (c.rowHead ? "left" : "center");
|
||||
const cellType = c.cellType ?? "gauge";
|
||||
|
||||
if (c.rowHead) {
|
||||
const raw = row[c.key];
|
||||
@@ -119,35 +132,42 @@ const GaugeTable = <T extends Record<string, unknown>>({
|
||||
const raw = row[c.key];
|
||||
const v = num(raw);
|
||||
const max = c.max ?? 100;
|
||||
const ratio = v === null ? 0 : Math.max(0, Math.min(1, (v * scale) / max));
|
||||
const ratio = v === null ? 0 : clamp01((v * scale) / max);
|
||||
const pct = ratio * 100;
|
||||
|
||||
return (
|
||||
<td key={String(c.key)} style={{ textAlign: align }}>
|
||||
<div
|
||||
className="relative overflow-hidden rounded-md"
|
||||
style={{
|
||||
height: cellHeight,
|
||||
background: trackColor,
|
||||
border: "1px solid hsl(var(--border))",
|
||||
}}
|
||||
const fill = fillColor;
|
||||
const track = trackColor;
|
||||
|
||||
const cellBg =
|
||||
v === null
|
||||
? undefined
|
||||
: `linear-gradient(to right, ${fill} ${pct}%, ${track} 0%)`;
|
||||
console.log(cellBg);
|
||||
if (cellType === "number") {
|
||||
return (
|
||||
<td
|
||||
key={String(c.key)}
|
||||
className="px-2 content-text-sm"
|
||||
style={{ textAlign: align }}
|
||||
>
|
||||
<div
|
||||
className="absolute inset-y-0 left-0"
|
||||
style={{
|
||||
width: `${pct}%`,
|
||||
background: fillColor,
|
||||
}}
|
||||
/>
|
||||
{showValue && (
|
||||
<div
|
||||
className="relative z-10 flex h-full items-center justify-center content-text-sm"
|
||||
style={{ color: "hsl(var(--lg-gray-900))" }}
|
||||
>
|
||||
{v === null ? "-" : fmt(v)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{v === null ? "-" : fmt(v)}
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<td
|
||||
key={String(c.key)}
|
||||
className="px-2 content-text-sm"
|
||||
style={{
|
||||
textAlign: "left",
|
||||
height: cellHeight,
|
||||
whiteSpace: "nowrap",
|
||||
background: cellBg,
|
||||
backgroundClip: "padding-box",
|
||||
}}
|
||||
>
|
||||
{v === null ? "-" : fmt(v)}
|
||||
</td>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -112,6 +112,17 @@ export type ServerBannerRow = ServerBaseRow &
|
||||
[k: string]: number | string;
|
||||
};
|
||||
|
||||
export type LifeStageRow = Record<string, unknown> & {
|
||||
item: string;
|
||||
total: number | null;
|
||||
single: number | null;
|
||||
noKids: number | null;
|
||||
preschoolKids: number | null;
|
||||
schoolKids: number | null;
|
||||
adultKids: number | null;
|
||||
independentSenior: number | null;
|
||||
};
|
||||
|
||||
export type ChartSeries = {
|
||||
/** legend에 노출될 이름 */
|
||||
name: string;
|
||||
@@ -190,6 +201,7 @@ export type GaugeColumn<T> = {
|
||||
/** 게이지 최대값 기준(기본 100) */
|
||||
max?: number;
|
||||
renderLabel?: (row: T) => React.ReactNode; // rowHead에 쓰기 좋음
|
||||
cellType?: "gauge" | "number"; // default: "gauge"
|
||||
};
|
||||
|
||||
export type SignDisplayMode = "number" | "arrow";
|
||||
@@ -233,13 +245,6 @@ export const signStyleGapRow: SignStyle<TopChartTableRow> = {
|
||||
arrowWithNumber: true,
|
||||
paint: "text",
|
||||
};
|
||||
|
||||
/** X 축 패딩 없앤 GridOption*/
|
||||
export const GRID_X_NOT_PADDING = { left: 0, right: 0, top: 50, bottom: 10, containLabel: false } as const;
|
||||
/** T 축 패딩 없앤 GridOption*/
|
||||
export const GRID_Y_NOT_PADDING = { left: 10, right: 10, top: 0, bottom: 0, containLabel: false } as const;
|
||||
/** 축 스타일 감춤 */
|
||||
export const AXIS_HIDE_STYLE = { axisLabel: { show: false }, axisTick: { show: false }, axisLine: { show: false }} as const;
|
||||
/** ChartLabel 보여지는 옵션 */
|
||||
export type ShowLabel = "none" | "all" | "last" | "first";
|
||||
|
||||
|
||||
@@ -9,17 +9,42 @@ import {PRODUCT_KEY_MAP} from "@/components/lge-dashboard";
|
||||
|
||||
const PRODUCT_KEYS = Object.keys(PRODUCT_KEY_MAP) as ProductKey[];
|
||||
|
||||
const randInt = (min: number, max: number) =>
|
||||
Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
const DUMMY_SEED = Number(process.env.NEXT_PUBLIC_DUMMY_SEED ?? 12345);
|
||||
|
||||
// 문자열 → 32bit 해시
|
||||
const hash32 = (s: string) => {
|
||||
let h = 2166136261;
|
||||
for (let i = 0; i < s.length; i++) {
|
||||
h ^= s.charCodeAt(i);
|
||||
h = Math.imul(h, 16777619);
|
||||
}
|
||||
return h >>> 0;
|
||||
};
|
||||
|
||||
// 결정적 PRNG
|
||||
const mulberry32 = (a: number) => {
|
||||
return () => {
|
||||
let t = (a += 0x6d2b79f5);
|
||||
t = Math.imul(t ^ (t >>> 15), t | 1);
|
||||
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
||||
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
||||
};
|
||||
};
|
||||
|
||||
const randInt = (r: () => number, min: number, max: number) =>
|
||||
Math.floor(r() * (max - min + 1)) + min;
|
||||
|
||||
type RandRange = { min: number | null; max: number | null };
|
||||
|
||||
const makeProductDist = (range?: RandRange): Record<ProductKey, number> => {
|
||||
const makeProductDist = (seedKey: string, range?: RandRange): Record<ProductKey, number> => {
|
||||
const min = range?.min ?? 1;
|
||||
const max = range?.max ?? 60;
|
||||
|
||||
const seed = (hash32(seedKey) ^ DUMMY_SEED) >>> 0;
|
||||
const r = mulberry32(seed);
|
||||
|
||||
const out = {} as Record<ProductKey, number>;
|
||||
for (const k of PRODUCT_KEYS) out[k] = randInt(min, max);
|
||||
for (const k of PRODUCT_KEYS) out[k] = randInt(r, min, max);
|
||||
return out;
|
||||
};
|
||||
|
||||
@@ -33,7 +58,7 @@ const productRow = (
|
||||
year,
|
||||
rowLabel,
|
||||
total,
|
||||
...makeProductDist(range),
|
||||
...makeProductDist(`${year}|${rowLabel}|${range.min ?? ""}|${range.max ?? ""}`, range),
|
||||
...(extra ?? {}),
|
||||
});
|
||||
|
||||
@@ -69,71 +94,119 @@ const calcCagrRow = (row24: ServerProductRow, row26: ServerProductRow): ServerPr
|
||||
return out;
|
||||
};
|
||||
|
||||
// 배너(41키) 그룹별 합이 100 되도록 고정 분포
|
||||
const BANNER_DIST_DEFAULT: Record<BannerKey, number> = {
|
||||
// 라이프스테이지(6)
|
||||
single: 20,
|
||||
noKids: 20,
|
||||
preschoolKids: 20,
|
||||
schoolKids: 20,
|
||||
adultKids: 10,
|
||||
independentSenior: 10,
|
||||
const splitTo100 = (r: () => number, n: number, minEach: number, maxEach: number): number[] => {
|
||||
// 불가능한 범위 방어
|
||||
const minSum = n * minEach;
|
||||
const maxSum = n * maxEach;
|
||||
if (minSum > 100) throw new Error(`splitTo100 invalid: minEach too large (n=${n}, minEach=${minEach})`);
|
||||
if (maxSum < 100) throw new Error(`splitTo100 invalid: maxEach too small (n=${n}, maxEach=${maxEach})`);
|
||||
|
||||
// 가구원수(4)
|
||||
hh1: 25,
|
||||
hh2: 35,
|
||||
hh3: 20,
|
||||
hh4Plus: 20,
|
||||
// 1) 최소값으로 깔기
|
||||
const out = Array(n).fill(minEach);
|
||||
const remain = 100 - minSum;
|
||||
|
||||
// 연령(5)
|
||||
age20s: 15,
|
||||
age30s: 25,
|
||||
age40s: 30,
|
||||
age50s: 20,
|
||||
age60s: 10,
|
||||
// 2) 각 슬롯이 추가로 받을 수 있는 상한
|
||||
const caps = Array(n).fill(maxEach - minEach);
|
||||
|
||||
// 점유형태(5)
|
||||
ownerOccupied: 50,
|
||||
jeonse: 25,
|
||||
depositAndMonthly: 10,
|
||||
monthlyNoDeposit: 10,
|
||||
otherTenure: 5,
|
||||
// 3) remain을 cap 내에서 랜덤 분배
|
||||
// (가중치 기반으로 일단 분배 → cap 초과를 다시 재분배)
|
||||
const w = Array.from({ length: n }, () => randInt(r, 1, 100));
|
||||
const wSum = w.reduce((a, b) => a + b, 0);
|
||||
|
||||
// 주거형태(6)
|
||||
apartment: 60,
|
||||
house: 15,
|
||||
officetel: 10,
|
||||
villa: 10,
|
||||
studio: 3,
|
||||
otherHousingType: 2,
|
||||
const add = w.map((wi) => Math.floor((wi / wSum) * remain));
|
||||
const used = add.reduce((a, b) => a + b, 0);
|
||||
const left = remain - used;
|
||||
|
||||
// 평형(5)
|
||||
under19Pyeong: 10,
|
||||
pyeong20s: 20,
|
||||
pyeong30s: 35,
|
||||
pyeong40s: 20,
|
||||
pyeong50Plus: 15,
|
||||
// 남은 left를 가중치 큰 순으로 1씩
|
||||
const order = w
|
||||
.map((wi, i) => ({ wi, i }))
|
||||
.sort((a, b) => b.wi - a.wi)
|
||||
.map((x) => x.i);
|
||||
|
||||
// 권역(6)
|
||||
regionCapital: 45,
|
||||
regionGyeongnamBusanUlsan: 15,
|
||||
regionGyeongbukDaegu: 10,
|
||||
regionJeollaGwangju: 10,
|
||||
regionChungcheongDaejeonSejong: 10,
|
||||
regionGangwonJeju: 10,
|
||||
for (let k = 0; k < left; k++) add[order[k % n]] += 1;
|
||||
|
||||
// 소득(4)
|
||||
incomeUnder299: 20,
|
||||
income300to599: 40,
|
||||
income600to899: 25,
|
||||
income900Plus: 15,
|
||||
// cap 적용(초과분 회수)
|
||||
let overflow = 0;
|
||||
for (let i = 0; i < n; i++) {
|
||||
if (add[i] > caps[i]) {
|
||||
overflow += add[i] - caps[i];
|
||||
add[i] = caps[i];
|
||||
}
|
||||
}
|
||||
|
||||
// 회수한 overflow를 cap 남은 곳에 다시 채우기(랜덤)
|
||||
while (overflow > 0) {
|
||||
const candidates = [];
|
||||
for (let i = 0; i < n; i++) {
|
||||
const room = caps[i] - add[i];
|
||||
if (room > 0) candidates.push({ i, room });
|
||||
}
|
||||
if (candidates.length === 0) break;
|
||||
|
||||
const pick = candidates[randInt(r, 0, candidates.length - 1)];
|
||||
add[pick.i] += 1;
|
||||
overflow -= 1;
|
||||
}
|
||||
|
||||
// 최종 합 100 보장
|
||||
for (let i = 0; i < n; i++) out[i] += add[i];
|
||||
const sum = out.reduce((a, b) => a + b, 0);
|
||||
if (sum !== 100) {
|
||||
// 마지막 보정(이론상 거의 안 탐)
|
||||
out[n - 1] += 100 - sum;
|
||||
}
|
||||
return out;
|
||||
};
|
||||
|
||||
const bannerRow = (year: number, rowLabel: string, total: number, extra?: Record<string, number>): ServerBannerRow => ({
|
||||
/** ✅ 그룹 키 정의(각 그룹 합 100) */
|
||||
const BANNER_GROUPS: Record<string, BannerKey[]> = {
|
||||
lifeStage: ["single", "noKids", "preschoolKids", "schoolKids", "adultKids", "independentSenior"],
|
||||
household: ["hh1", "hh2", "hh3", "hh4Plus"],
|
||||
age: ["age20s", "age30s", "age40s", "age50s", "age60s"],
|
||||
tenure: ["ownerOccupied", "jeonse", "depositAndMonthly", "monthlyNoDeposit", "otherTenure"],
|
||||
housing: ["apartment", "house", "officetel", "villa", "studio", "otherHousingType"],
|
||||
pyeong: ["under19Pyeong", "pyeong20s", "pyeong30s", "pyeong40s", "pyeong50Plus"],
|
||||
region: [
|
||||
"regionCapital",
|
||||
"regionGyeongnamBusanUlsan",
|
||||
"regionGyeongbukDaegu",
|
||||
"regionJeollaGwangju",
|
||||
"regionChungcheongDaejeonSejong",
|
||||
"regionGangwonJeju",
|
||||
],
|
||||
income: ["incomeUnder299", "income300to599", "income600to899", "income900Plus"],
|
||||
};
|
||||
|
||||
/** ✅ 기존 상수 대신: 호출할 때마다 “결정적 랜덤” 분포 생성 */
|
||||
export const makeBannerDistDefault = (seedKey: string, range?: RandRange): Record<BannerKey, number> => {
|
||||
const seed = (hash32(seedKey) ^ DUMMY_SEED) >>> 0;
|
||||
const r = mulberry32(seed);
|
||||
|
||||
const minEach = range?.min ?? 1;
|
||||
const maxEach = range?.max ?? 60;
|
||||
|
||||
const out = {} as Record<BannerKey, number>;
|
||||
|
||||
(Object.keys(BANNER_GROUPS) as Array<keyof typeof BANNER_GROUPS>).forEach((groupName) => {
|
||||
const keys = BANNER_GROUPS[groupName];
|
||||
const parts = splitTo100(r, keys.length, minEach, maxEach); // ✅ min/max 적용
|
||||
for (let i = 0; i < keys.length; i++) out[keys[i]] = parts[i];
|
||||
});
|
||||
|
||||
return out;
|
||||
};
|
||||
|
||||
export const bannerRow = (
|
||||
year: number,
|
||||
rowLabel: string,
|
||||
total: number,
|
||||
range: RandRange = { min: null, max: null },
|
||||
extra?: Partial<Record<BannerKey, number>>,
|
||||
): ServerBannerRow => ({
|
||||
year,
|
||||
rowLabel,
|
||||
total,
|
||||
...BANNER_DIST_DEFAULT,
|
||||
...makeBannerDistDefault(`${year}|${rowLabel}`, range), // ✅ min/max 적용
|
||||
...(extra ?? {}),
|
||||
});
|
||||
|
||||
@@ -197,21 +270,36 @@ export const apiOwnShareOfTotalPurchase: ServerProductRow[] = [
|
||||
];
|
||||
|
||||
export const apiLifeStageByProduct: ServerBannerRow[] = [
|
||||
bannerRow(26, "냉장고", 1200, { single: 18, noKids: 22, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
||||
bannerRow(26, "세탁기", 1100, { single: 18, noKids: 22, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
||||
bannerRow(26, "에어컨", 900, { single: 22, noKids: 18, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
||||
bannerRow(26, "TV", 950, { single: 18, noKids: 22, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
||||
bannerRow(26, "청소기", 1000, { single: 22, noKids: 18, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
||||
bannerRow(26, "김치 냉장고", 700, { single: 22, noKids: 18, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
||||
bannerRow(26, "공기 청정기", 800, { single: 22, noKids: 18, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
||||
bannerRow(26, "가습기", 650, { single: 22, noKids: 18, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
||||
bannerRow(26, "제습기", 600, { single: 18, noKids: 22, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
||||
bannerRow(26, "건조기", 500, { single: 18, noKids: 22, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
||||
bannerRow(26, "식기세척기", 450, { single: 22, noKids: 18, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
||||
bannerRow(26, "의류 관리기", 320, { single: 18, noKids: 22, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
||||
bannerRow(26, "로봇 청소기", 420, { single: 22, noKids: 18, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
||||
bannerRow(26, "냉장고", 1200),
|
||||
bannerRow(26, "세탁기", 1100),
|
||||
bannerRow(26, "에어컨", 900),
|
||||
bannerRow(26, "TV", 950),
|
||||
bannerRow(26, "청소기", 1000),
|
||||
bannerRow(26, "김치 냉장고", 700),
|
||||
bannerRow(26, "공기 청정기", 800),
|
||||
bannerRow(26, "가습기", 650),
|
||||
bannerRow(26, "제습기", 600),
|
||||
bannerRow(26, "건조기", 500),
|
||||
bannerRow(26, "식기세척기", 450),
|
||||
bannerRow(26, "의류 관리기", 320),
|
||||
bannerRow(26, "로봇 청소기", 420),
|
||||
];
|
||||
|
||||
export const apiLifeStageByProductForGauge: ServerBannerRow[] = [
|
||||
bannerRow(26, "냉장고", 1200, {min:10, max:99}),
|
||||
bannerRow(26, "세탁기", 1100, {min:10, max:99}),
|
||||
bannerRow(26, "에어컨", 900, {min:10, max:99}),
|
||||
bannerRow(26, "TV", 950, {min:10, max:99}),
|
||||
bannerRow(26, "청소기", 1000, {min:10, max:99}),
|
||||
bannerRow(26, "김치 냉장고", 700, {min:10, max:99}),
|
||||
bannerRow(26, "공기 청정기", 800, {min:10, max:99}),
|
||||
bannerRow(26, "가습기", 650, {min:10, max:99}),
|
||||
bannerRow(26, "제습기", 600, {min:10, max:99}),
|
||||
bannerRow(26, "건조기", 500, {min:10, max:99}),
|
||||
bannerRow(26, "식기세척기", 450, {min:10, max:99}),
|
||||
bannerRow(26, "의류 관리기", 320, {min:10, max:99}),
|
||||
bannerRow(26, "로봇 청소기", 420, {min:10, max:99}),
|
||||
];
|
||||
/** ---------------------------
|
||||
* API #6
|
||||
* year rowLabel total banner
|
||||
|
||||
@@ -3,4 +3,11 @@ import {PRODUCT_KEY_MAP} from "@/components/lge-dashboard";
|
||||
export const PRODUCT_KEYS = Object.keys(PRODUCT_KEY_MAP) as Array<keyof typeof PRODUCT_KEY_MAP>;
|
||||
export const PRODUCTS = Object.values(PRODUCT_KEY_MAP) as Array<string>;
|
||||
export const YEARS = [24, 25, 26];
|
||||
export const BRAND_LIST = ['Cbrand', 'Samsung', 'LG'];
|
||||
export const BRAND_LIST = ['Cbrand', 'Samsung', 'LG'];
|
||||
|
||||
/** X 축 패딩 없앤 GridOption*/
|
||||
export const GRID_X_NOT_PADDING = { left: 0, right: 0, top: 50, bottom: 10, containLabel: false } as const;
|
||||
/** T 축 패딩 없앤 GridOption*/
|
||||
export const GRID_Y_NOT_PADDING = { left: 10, right: 10, top: 0, bottom: 0, containLabel: false } as const;
|
||||
/** 축 스타일 감춤 */
|
||||
export const AXIS_HIDE_STYLE = { axisLabel: { show: false }, axisTick: { show: false }, axisLine: { show: false }} as const;
|
||||
Reference in New Issue
Block a user