260330_01_ENH: 26일자 수정사항 반영(라이프스테이지 중분류 제외)
This commit is contained in:
@@ -53,7 +53,7 @@ export function formatRowLabel(
|
||||
|
||||
if (convertSample && t === "사례수") return "(사례수)";
|
||||
if (convertGap && t.toLowerCase() === "gap") return GAP_WORDING;
|
||||
if (convertCagr && t.toUpperCase() === "CAGR") return "CAGR(%p)";
|
||||
if (convertCagr && t.toUpperCase() === "CAGR") return "CAGR(%)";
|
||||
if (convertYear && /^\d{4}$/.test(t)) return `${t.substring(2,4)}년`;
|
||||
if (convertYear && /^\d{2}$/.test(t)) return `${t}년`;
|
||||
if (convertRate && t.endsWith("율")) return `${t.replaceAll('(%)','')}(%)`;
|
||||
@@ -63,7 +63,7 @@ export function formatRowLabel(
|
||||
}
|
||||
|
||||
export const wrapSampleRow = <T extends Record<string, unknown> & { rowLabel: string }>(
|
||||
rows: T[]
|
||||
rows: T[], replaceLabel: boolean = true
|
||||
): T[] => {
|
||||
return rows.map((r) => {
|
||||
if (!isSampleRow(r.rowLabel)) return r;
|
||||
@@ -73,18 +73,23 @@ export const wrapSampleRow = <T extends Record<string, unknown> & { rowLabel: st
|
||||
Object.entries(r).forEach(([k, v]) => {
|
||||
if (k == "year" || v == null) return;
|
||||
|
||||
if (typeof v === "number") {
|
||||
out[k] = `(${formatNumber(v)})`;
|
||||
if (
|
||||
typeof v === "number" ||
|
||||
(typeof v === "string" && v.trim() !== "" && !Number.isNaN(Number(v)))
|
||||
) {
|
||||
out[k] = `(${formatNumber(Number(v))})`;
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof v === "string") {
|
||||
// 이미 괄호면 그대로
|
||||
out[k] = v.startsWith("(") && v.endsWith(")") ? v : `(${v})`;
|
||||
return;
|
||||
}
|
||||
if(replaceLabel){
|
||||
if (typeof v === "string") {
|
||||
// 이미 괄호면 그대로
|
||||
out[k] = v.startsWith("(") && v.endsWith(")") ? v : `(${v})`;
|
||||
return;
|
||||
}
|
||||
|
||||
out[k] = `(${String(v)})`;
|
||||
out[k] = `(${String(v)})`;
|
||||
}
|
||||
});
|
||||
|
||||
return out as T;
|
||||
@@ -390,14 +395,16 @@ export const buildCategoryFilter = (
|
||||
return Object.keys(out).length ? out : undefined;
|
||||
}
|
||||
|
||||
const fixedDecimalPoint = (n: number): string => {
|
||||
return n.toFixed(API_DECIMAL_POINT);
|
||||
const fixedDecimalPoint = (n: number, decimalPoint?: number): string => {
|
||||
decimalPoint ??= API_DECIMAL_POINT;
|
||||
return n.toFixed(decimalPoint);
|
||||
};
|
||||
|
||||
export const roundNumber = (num: number|null) => {
|
||||
export const roundNumber = (num: number|null, decimalPoint?: number) => {
|
||||
if(num == null) return null;
|
||||
|
||||
const factor = 10 ** VIEW_DECIMAL_POINT;
|
||||
decimalPoint ??= VIEW_DECIMAL_POINT;
|
||||
const factor = 10 ** decimalPoint;
|
||||
return Math.round(num * factor) / factor;
|
||||
};
|
||||
|
||||
@@ -447,12 +454,12 @@ export const calcCagrRow = (after: ProductRow, before: ProductRow): ProductRow =
|
||||
|
||||
// total은 참고용으로만: (26/24) CAGR %
|
||||
out.total =
|
||||
fixedDecimalPoint((before?.total ?? "0") > "0" ? calcCagr(Number(after?.total ?? "0"), Number(before?.total ?? "0"), years) : 0);
|
||||
fixedDecimalPoint((before?.total ?? "0") > "0" ? calcCagr(Number(after?.total ?? "0"), Number(before?.total ?? "0"), years) : 0, 1);
|
||||
|
||||
for (const k of PRODUCT_KEYS) {
|
||||
const vBefore = before? before[k] ?? "0" : "0";
|
||||
const vAfter = after? after[k] ?? "0" : "0";
|
||||
out[k] = fixedDecimalPoint(Number(vBefore) > 0 ? calcCagr(Number(vAfter), Number(vBefore), years) : 0);
|
||||
out[k] = fixedDecimalPoint(Number(vBefore) > 0 ? calcCagr(Number(vAfter), Number(vBefore), years) : 0, 1);
|
||||
}
|
||||
return out;
|
||||
};
|
||||
@@ -465,7 +472,7 @@ export const makeTotalBasePct = (t:number|string, f:number|string):number => {
|
||||
export const calcTotalBaseRow = (label:string, totalRow: ProductRow, targetRow: ProductRow): ProductRow => {
|
||||
const out: ProductRow = {
|
||||
year: targetRow?.year ?? "",
|
||||
rowLabel: `조사 년도 ${label} 중 자사제품 비율`,
|
||||
rowLabel: `조사 년도 ${label} 중 자사제품 비율 (LG ${label} ÷ 전체 ${label}) × 100`,
|
||||
total: fixedDecimalPoint(makeTotalBasePct(totalRow.total, targetRow.total))
|
||||
};
|
||||
|
||||
@@ -480,20 +487,24 @@ export const calcTotalBaseRow = (label:string, totalRow: ProductRow, targetRow:
|
||||
|
||||
export const withGapRow = <T>(
|
||||
rows: T[],
|
||||
calcGapRow: (last: T, secondLast: T) => T
|
||||
calcGapRow: (last: T, secondLast: T) => T,
|
||||
lastIndex: number,
|
||||
secondLastIndex: number,
|
||||
): T[] => {
|
||||
const last = rows.at(-1);
|
||||
const secondLast = rows.at(-2);
|
||||
const last = rows.at(lastIndex);
|
||||
const secondLast = rows.at(secondLastIndex);
|
||||
if (!last || !secondLast) return rows;
|
||||
return [calcGapRow(last, secondLast), ...rows];
|
||||
}
|
||||
|
||||
export const withCagrRow = <T>(
|
||||
rows: T[],
|
||||
calcCagrRow: (last: T, first: T) => T
|
||||
calcCagrRow: (last: T, first: T) => T,
|
||||
lastIndex: number,
|
||||
firstIndex: number,
|
||||
): T[] => {
|
||||
const first = rows.at(1);
|
||||
const last = rows.at(-1);
|
||||
const first = rows.at(firstIndex);
|
||||
const last = rows.at(lastIndex);
|
||||
if (!first || !last) return rows;
|
||||
return [...rows, calcCagrRow(last, first)];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user