260303_02_ENH: CAGR 관련 수정

This commit is contained in:
2026-03-03 16:58:46 +09:00
parent 1c2dcb6fd5
commit 1159993c62

View File

@@ -423,6 +423,14 @@ export const calcGapBannerRow = (after: BannerRow, before: BannerRow): BannerRow
const round1 = (n: number) => Math.round(n * 10) / 10;
const calcCagr = (after: number, before: number, years:number): string => {
const power = Math.pow(after / before, 1 / years);
const cagr = power - 1;
const cagr100 = cagr * 100;
return String(round1(cagr100));
};
export const calcCagrRow = (after: ProductRow, before: ProductRow): ProductRow => {
const years = 2; // 24 -> 26
const out: ProductRow = {
@@ -433,12 +441,13 @@ export const calcCagrRow = (after: ProductRow, before: ProductRow): ProductRow =
// total은 참고용으로만: (26/24) CAGR %
out.total =
Number(before?.total ?? "0") > 0 ? String(round1((Math.pow(Number(after?.total ?? "0") / Number(before?.total ?? "0"), 1 / years) - 1) * 100)) : "0";
Number(before?.total ?? "0") > 0 ? calcCagr(Number(after?.total ?? "0"), Number(before?.total ?? "0"), years) : "0";
for (const k of PRODUCT_KEYS) {
const vBefore = before? before[k] ?? "0" : "0";
const vAfter = after? after[k] ?? "0" : "0";
out[k] = Number(vBefore) > 0 ? String(round1((Math.pow(Number(vAfter) / Number(vBefore), 1 / years) - 1) * 100)) : "0";
console.log(k, vBefore, vAfter);
out[k] = Number(vBefore) > 0 ? calcCagr(Number(vAfter), Number(vBefore), years) : "0";
}
return out;
};
@@ -478,7 +487,7 @@ export const withCagrRow = <T>(
rows: T[],
calcCagrRow: (last: T, first: T) => T
): T[] => {
const first = rows.at(0);
const first = rows.at(1);
const last = rows.at(-1);
if (!first || !last) return rows;
return [...rows, calcCagrRow(last, first)];