fix(performance): 광고비 구글·메타는 ROAS 계산 안 함(따로 입력 예정)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -41,9 +41,11 @@ CHANNELS: tuple[tuple[str, str], ...] = (
|
||||
)
|
||||
CHANNEL_NAMES = dict(CHANNELS)
|
||||
CHANNEL_CODES = tuple(c for c, _ in CHANNELS)
|
||||
# ROAS(매출 ÷ 광고비 × 100) 의 매출 = 이 쇼핑몰 매출 실적 총매출. 구글·메타는 자체몰(카페24)로 보내는 광고라 카페24 매출.
|
||||
ROAS_SALES_CODE: dict[str, str] = {c: c for c in CHANNEL_CODES}
|
||||
ROAS_SALES_CODE.update({"google": "cafe24", "meta": "cafe24", "coupang_wing": "coupang"})
|
||||
# ROAS(매출 ÷ 광고비 × 100) 의 매출 = 이 쇼핑몰 매출 실적 총매출. 쿠팡(윙)은 매출 쪽 코드가 coupang.
|
||||
# 구글·메타는 ROAS 를 계산하지 않는다 — ROAS 값을 따로 넣는다(2026-10-14 사용자 요청).
|
||||
NO_ROAS = frozenset({"google", "meta"})
|
||||
ROAS_SALES_CODE: dict[str, str] = {c: c for c in CHANNEL_CODES if c not in NO_ROAS}
|
||||
ROAS_SALES_CODE["coupang_wing"] = "coupang"
|
||||
|
||||
|
||||
def roas(sales: int, spend: int) -> int | None:
|
||||
@@ -54,9 +56,14 @@ def roas(sales: int, spend: int) -> int | None:
|
||||
|
||||
|
||||
def roas_basis(code: str) -> str:
|
||||
"""머리글 말풍선 — ROAS 에 쓰는 매출."""
|
||||
sales = ROAS_SALES_CODE[code]
|
||||
return "카페24(자체몰)" if sales == "cafe24" else CHANNEL_NAMES.get(code, code)
|
||||
"""머리글 말풍선 — ROAS 에 쓰는 매출(구글·메타는 빈 값 = 계산 안 함)."""
|
||||
return "" if code not in ROAS_SALES_CODE else CHANNEL_NAMES.get(code, code)
|
||||
|
||||
|
||||
def channel_roas(code: str, sales_of: Callable[[str], int], spend: int) -> int | None:
|
||||
"""채널 칸의 ROAS — 구글·메타는 늘 None(계산 안 함)."""
|
||||
mcode = ROAS_SALES_CODE.get(code)
|
||||
return None if mcode is None else roas(sales_of(mcode), spend)
|
||||
|
||||
ROCKET_DATE_COL = 0 # 1열 날짜
|
||||
ROCKET_AMOUNT_COL = 18 # 19열 청구금액(+부가가치세)
|
||||
@@ -250,11 +257,11 @@ def build_ad_dashboard(store: Any, *, kind: str, anchor: date, today: date,
|
||||
for row in table:
|
||||
s = date.fromisoformat(row["from"]) if row.get("from") else period.start
|
||||
e = date.fromisoformat(row["to"]) if row.get("to") else period.end
|
||||
row["roas"] = {c: roas(sales_sum([ROAS_SALES_CODE[c]], s, e), row["cells"][c]["gross"]) for c in codes}
|
||||
row["roas"] = {c: channel_roas(c, lambda m: sales_sum([m], s, e), row["cells"][c]["gross"]) for c in codes}
|
||||
row["roas_total"] = roas(sales_sum(total_codes, s, e), row["total"]["gross"]) if total_codes else None
|
||||
m_s, m_e = month_period.start, month_period.end
|
||||
for r in month["rows"]:
|
||||
r["roas"] = roas(sales_sum([ROAS_SALES_CODE[r["code"]]], m_s, m_e), r["gross"])
|
||||
r["roas"] = channel_roas(r["code"], lambda m: sales_sum([m], m_s, m_e), r["gross"])
|
||||
month["total"]["roas"] = roas(sales_sum(total_codes, m_s, m_e), month["total"]["gross"]) if total_codes else None
|
||||
year = calc.year_months(year_period.start.year, codes, cells, today=today)
|
||||
for i, r in enumerate(year["rows"], start=1):
|
||||
|
||||
Reference in New Issue
Block a user