aa669553db
- 네 영역 분리: ① 수집(adapters/ 쇼핑몰 10곳 + sync.py) ② 보안(security/ + credentials.py) ③ 계산·저장(calc.py + db.py) ④ 화면(dashboard.py, router.py, templates, performance.css/js) - 대시보드: 기간(오늘/이번주/이번달/올해/직접선택, 이전·다음), 쇼핑몰 필터, KPI 5개(진행 중 기간은 직전 기간 같은 경과일 대비), 일자×쇼핑몰 표(주간합계, 총매출/수수료/차감매출 전환), 일별 추이· 쇼핑몰 비중(SVG), 월 누적(비중)·연간 누적, 금액 클릭 → 주문 상세 - 설정(관리자): 사용/매출 집계, 수수료율 이력(적용 시작일), 쇼핑몰별 API 인증정보 입력·연결 테스트· 연결 상태, 마스터 키 상태·재암호화, 테스트(모의) 데이터 생성/삭제 - 인증정보: 설정 화면 입력 → AES-256-GCM(키 버전, AAD=쇼핑몰+항목) 암호화 저장, secret 원문은 화면으로 다시 보내지 않음, 오류·로그·raw 는 비밀값 가린 뒤 저장. 마스터 키는 APP_ENCRYPTION_KEY(.env) - 매출 기준일: 결제=결제일, 취소·반품=발생일. 금액 원 단위 정수, 수수료 반올림은 calc.commission 한 곳 - 동기화: 같은 쇼핑몰 동시 실행 차단(running 부분 유니크), 쇼핑몰별 실패 격리, 중복 방지 UNIQUE+UPSERT - 카페24 어댑터는 기존 app/integrations/cafe24 OAuth 토큰 재사용, 나머지는 입력칸만(수집은 다음 단계) - performance_db 초기화 스크립트, 권한키 performance(설정은 is_admin), 문서·.env.example Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
64 lines
3.1 KiB
Python
64 lines
3.1 KiB
Python
"""테스트(모의) 매출 데이터 — 실제 API 연동 전 화면 확인용.
|
|
|
|
같은 (쇼핑몰, 날짜)면 항상 같은 값이 나온다(재현 가능). 결제뿐 아니라 전체 취소·
|
|
부분 반품도 섞어 넣어 음수 반영과 합계를 확인할 수 있게 한다.
|
|
DB 에는 is_sample=TRUE 로 들어가며 설정 화면에서 한 번에 지울 수 있다.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import random
|
|
from datetime import date, timedelta
|
|
|
|
from .base import SaleEvent
|
|
|
|
# 쇼핑몰별 하루 평균 주문 건수(모의값) — 화면에 차이가 보이도록만 다르게 둔다.
|
|
_DAILY_ORDERS = {
|
|
"cafe24": 9, "naver": 14, "coupang": 18, "ohouse": 4, "gmarket": 6,
|
|
"kakao": 3, "gsshop": 2, "elevenst": 4, "lotteon": 2, "toss": 1,
|
|
}
|
|
_PRODUCTS = (
|
|
("스테인리스 냄비 20cm", 39_000), ("프라이팬 28cm", 45_900), ("밀폐용기 5종 세트", 29_800),
|
|
("도마 대형", 19_900), ("칼 블록 세트", 89_000), ("주방 가위", 12_900),
|
|
("냄비 받침", 8_900), ("전골 냄비", 59_000),
|
|
)
|
|
|
|
|
|
def generate(code: str, start: date, end: date) -> list[SaleEvent]:
|
|
events: list[SaleEvent] = []
|
|
base = _DAILY_ORDERS.get(code, 3)
|
|
d = start
|
|
while d <= end:
|
|
rng = random.Random(f"perf-sample:{code}:{d.isoformat()}")
|
|
weekend = d.weekday() >= 5
|
|
n = max(0, int(rng.gauss(base * (0.7 if weekend else 1.0), base * 0.35)))
|
|
for i in range(n):
|
|
name, price = rng.choice(_PRODUCTS)
|
|
qty = 1 if rng.random() < 0.8 else rng.randint(2, 3)
|
|
discount = rng.choice((0, 0, 0, 1000, 2000, 3000))
|
|
amount = max(0, price * qty - discount)
|
|
order_id = f"SAMPLE-{code}-{d:%Y%m%d}-{i:03d}"
|
|
events.append(SaleEvent(
|
|
event_type="SALE", external_event_id=f"{order_id}-S", external_order_id=order_id,
|
|
external_line_id="1", order_date=d, payment_date=d, event_date=d, amount=amount,
|
|
product_name=name, quantity=qty, discount_amount=discount, order_status="결제완료",
|
|
raw={"sample": True},
|
|
))
|
|
roll = rng.random()
|
|
if roll < 0.05: # 전체 취소(당일~2일 뒤)
|
|
cd = min(end, d + timedelta(days=rng.randint(0, 2)))
|
|
events.append(SaleEvent(
|
|
event_type="CANCEL", external_event_id=f"{order_id}-C", external_order_id=order_id,
|
|
external_line_id="1", order_date=d, payment_date=d, event_date=cd, amount=-amount,
|
|
product_name=name, quantity=-qty, order_status="취소완료", raw={"sample": True},
|
|
))
|
|
elif roll < 0.08 and qty > 1: # 부분 반품(1개, 3~7일 뒤)
|
|
rd = min(end, d + timedelta(days=rng.randint(3, 7)))
|
|
events.append(SaleEvent(
|
|
event_type="RETURN", external_event_id=f"{order_id}-R", external_order_id=order_id,
|
|
external_line_id="1", order_date=d, payment_date=d, event_date=rd, amount=-price,
|
|
product_name=name, quantity=-1, order_status="반품완료", raw={"sample": True},
|
|
))
|
|
d += timedelta(days=1)
|
|
return events
|