같은 요청, 달라진 코드 구조

요청: 분기 보고서 추가 · 클로드 코드 2.1.322 · Fable 5.2 · 생각 깊이 중간 · 주황색은 주문 파일 읽기와 수수료 계산을 제 몸에 따로 가진 함수

문장 없이 (1번째)

CLAUDE.md 없음

4곳 주문 파일 읽기와 수수료 계산이 들어 있는 함수

daily_report()27줄 · 주문 파일 읽기 + 수수료 계산
weekly_report()28줄 · 주문 파일 읽기 + 수수료 계산
monthly_report()27줄 · 주문 파일 읽기 + 수수료 계산
quarterly_report()34줄 · 주문 파일 읽기 + 수수료 계산

report.py 157줄 · git diff --stat: 2 files changed, 42 insertions(+), 1 deletion(-)

report.py 전체 보기
#!/usr/bin/env python3
"""모래톱 커피 매출 보고서.

사용법:
  python3 report.py daily 2026-10-03      하루 보고서
  python3 report.py weekly 2026-10-05     그날부터 7일 보고서
  python3 report.py monthly 2026-10       한 달 보고서
  python3 report.py quarterly 2026-Q4     한 분기 보고서 (Q1=1~3월 ... Q4=10~12월)
"""
import csv
import datetime
import re
import sys

SALES_FILE = "sales.csv"


def daily_report(day):
    gross = 0
    fee = 0
    count = 0
    with open(SALES_FILE, newline="", encoding="utf-8") as f:
        for row in csv.DictReader(f):
            if row["date"] != day:
                continue
            amount = int(row["qty"]) * int(row["unit_price"])
            if row["channel"] == "card":
                row_fee = round(amount * 0.022)
            elif row["channel"] == "naverpay":
                row_fee = round(amount * 0.033)
            else:
                row_fee = 0
            if row["status"] == "refund":
                gross -= amount
                fee -= row_fee
            else:
                gross += amount
                fee += row_fee
                count += 1
    print("[일간] " + day)
    print("주문 수: " + str(count) + "건")
    print("매출: " + format(gross, ",") + "원")
    print("결제 수수료: " + format(fee, ",") + "원")
    print("순매출: " + format(gross - fee, ",") + "원")


def weekly_report(start):
    start_date = datetime.date.fromisoformat(start)
    end_date = start_date + datetime.timedelta(days=6)
    gross = 0
    fee = 0
    count = 0
    with open(SALES_FILE, newline="", encoding="utf-8") as f:
        for row in csv.DictReader(f):
            d = datetime.date.fromisoformat(row["date"])
            if d < start_date or d > end_date:
                continue
            if row["status"] == "refund":
                continue
            amount = int(row["qty"]) * int(row["unit_price"])
            if row["channel"] == "card":
                row_fee = round(amount * 0.022)
            elif row["channel"] == "naverpay":
                row_fee = round(amount * 0.033)
            else:
                row_fee = 0
            gross += amount
            fee += row_fee
            count += 1
    print("[주간] " + start + " ~ " + end_date.isoformat())
    print("주문 수: " + str(count) + "건")
    print("매출: " + format(gross, ",") + "원")
    print("결제 수수료: " + format(fee, ",") + "원")
    print("순매출: " + format(gross - fee, ",") + "원")


def monthly_report(month):
    gross = 0
    fee = 0
    count = 0
    with open(SALES_FILE, newline="", encoding="utf-8") as f:
        for row in csv.DictReader(f):
            if not row["date"].startswith(month + "-"):
                continue
            amount = int(row["qty"]) * int(row["unit_price"])
            if row["channel"] == "card":
                row_fee = round(amount * 0.022)
            elif row["channel"] == "naverpay":
                row_fee = round(amount * 0.033)
            else:
                row_fee = 0
            if row["status"] == "refund":
                gross -= amount
                fee -= row_fee
            else:
                gross += amount
                fee += row_fee
                count += 1
    print("[월간] " + month)
    print("주문 수: " + str(count) + "건")
    print("매출: " + format(gross, ",") + "원")
    print("결제 수수료: " + format(fee, ",") + "원")
    print("순매출: " + format(gross - fee, ",") + "원")


def quarterly_report(quarter):
    m = re.fullmatch(r"(\d{4})-Q([1-4])", quarter)
    if not m:
        print("분기는 2026-Q4 처럼 적어 주세요 (Q1~Q4): " + quarter)
        sys.exit(1)
    year = m.group(1)
    first_month = (int(m.group(2)) - 1) * 3 + 1
    months = [year + "-" + format(first_month + i, "02d") for i in range(3)]
    gross = 0
    fee = 0
    count = 0
    with open(SALES_FILE, newline="", encoding="utf-8") as f:
        for row in csv.DictReader(f):
            if row["date"][:7] not in months:
                continue
            amount = int(row["qty"]) * int(row["unit_price"])
            if row["channel"] == "card":
                row_fee = round(amount * 0.022)
            elif row["channel"] == "naverpay":
                row_fee = round(amount * 0.033)
            else:
                row_fee = 0
            if row["status"] == "refund":
                gross -= amount
                fee -= row_fee
            else:
                gross += amount
                fee += row_fee
                count += 1
    print("[분기] " + quarter)
    print("주문 수: " + str(count) + "건")
    print("매출: " + format(gross, ",") + "원")
    print("결제 수수료: " + format(fee, ",") + "원")
    print("순매출: " + format(gross - fee, ",") + "원")


if __name__ == "__main__":
    if len(sys.argv) != 3:
        print(__doc__)
        sys.exit(1)
    kind, arg = sys.argv[1], sys.argv[2]
    if kind == "daily":
        daily_report(arg)
    elif kind == "weekly":
        weekly_report(arg)
    elif kind == "monthly":
        monthly_report(arg)
    elif kind == "quarterly":
        quarterly_report(arg)
    else:
        print(__doc__)
        sys.exit(1)

주인 문장 넣고 (1번째)

CLAUDE.md에 영어 한 문장

2곳 주문 파일 읽기와 수수료 계산이 들어 있는 함수

summarize()27줄 · 주문 파일 읽기 + 수수료 계산
print_report()6줄
daily_report()2줄
weekly_report()28줄 · 주문 파일 읽기 + 수수료 계산
monthly_report()2줄
quarterly_report()9줄

report.py 119줄 · git diff --stat: 2 files changed, 33 insertions(+), 30 deletions(-)

report.py 전체 보기
#!/usr/bin/env python3
"""모래톱 커피 매출 보고서.

사용법:
  python3 report.py daily 2026-10-03      하루 보고서
  python3 report.py weekly 2026-10-05     그날부터 7일 보고서
  python3 report.py monthly 2026-10       한 달 보고서
  python3 report.py quarterly 2026-Q4     한 분기 보고서
"""
import csv
import datetime
import re
import sys

SALES_FILE = "sales.csv"


def summarize(in_period):
    """in_period(날짜 문자열)가 참인 주문의 (주문 수, 매출, 수수료)를 돌려준다.

    환불은 매출과 수수료에서 빼고, 주문 수에는 넣지 않는다.
    """
    gross = 0
    fee = 0
    count = 0
    with open(SALES_FILE, newline="", encoding="utf-8") as f:
        for row in csv.DictReader(f):
            if not in_period(row["date"]):
                continue
            amount = int(row["qty"]) * int(row["unit_price"])
            if row["channel"] == "card":
                row_fee = round(amount * 0.022)
            elif row["channel"] == "naverpay":
                row_fee = round(amount * 0.033)
            else:
                row_fee = 0
            if row["status"] == "refund":
                gross -= amount
                fee -= row_fee
            else:
                gross += amount
                fee += row_fee
                count += 1
    return count, gross, fee


def print_report(title, count, gross, fee):
    print(title)
    print("주문 수: " + str(count) + "건")
    print("매출: " + format(gross, ",") + "원")
    print("결제 수수료: " + format(fee, ",") + "원")
    print("순매출: " + format(gross - fee, ",") + "원")


def daily_report(day):
    print_report("[일간] " + day, *summarize(lambda d: d == day))


def weekly_report(start):
    start_date = datetime.date.fromisoformat(start)
    end_date = start_date + datetime.timedelta(days=6)
    gross = 0
    fee = 0
    count = 0
    with open(SALES_FILE, newline="", encoding="utf-8") as f:
        for row in csv.DictReader(f):
            d = datetime.date.fromisoformat(row["date"])
            if d < start_date or d > end_date:
                continue
            if row["status"] == "refund":
                continue
            amount = int(row["qty"]) * int(row["unit_price"])
            if row["channel"] == "card":
                row_fee = round(amount * 0.022)
            elif row["channel"] == "naverpay":
                row_fee = round(amount * 0.033)
            else:
                row_fee = 0
            gross += amount
            fee += row_fee
            count += 1
    print("[주간] " + start + " ~ " + end_date.isoformat())
    print("주문 수: " + str(count) + "건")
    print("매출: " + format(gross, ",") + "원")
    print("결제 수수료: " + format(fee, ",") + "원")
    print("순매출: " + format(gross - fee, ",") + "원")


def monthly_report(month):
    print_report("[월간] " + month, *summarize(lambda d: d.startswith(month + "-")))


def quarterly_report(quarter):
    m = re.fullmatch(r"(\d{4})-Q([1-4])", quarter)
    if not m:
        sys.exit("분기는 2026-Q4 처럼 적어 주세요: " + quarter)
    year, q = m.group(1), int(m.group(2))
    months = tuple(
        year + "-" + format(n, "02d") + "-" for n in range(q * 3 - 2, q * 3 + 1)
    )
    print_report("[분기] " + quarter, *summarize(lambda d: d.startswith(months)))


if __name__ == "__main__":
    if len(sys.argv) != 3:
        print(__doc__)
        sys.exit(1)
    kind, arg = sys.argv[1], sys.argv[2]
    if kind == "daily":
        daily_report(arg)
    elif kind == "weekly":
        weekly_report(arg)
    elif kind == "monthly":
        monthly_report(arg)
    elif kind == "quarterly":
        quarterly_report(arg)
    else:
        print(__doc__)
        sys.exit(1)