Merge branch 'feat/live-calendar-merge'
This commit is contained in:
@@ -19,7 +19,7 @@
|
|||||||
- **달력 보기** `/live/calendar?month=`(`store.build_calendar`, 사용자가 준 화면 참고, 글자도 영어 그대로) — 줄 = 1시간 칸(2026-11-06 `store.SLOT_HOURS` 2 → 1, 06:00~24:00 늘 보임, 그보다 이른 칸은 방송이 있을 때만, 칸은 시작 시간으로 정함), 열 = 날짜, 주말 노랑, 위 달 합계, 맨 아래 날짜별 TOTAL SALES·AD SPEND·HOST FEE·ROAS.
|
- **달력 보기** `/live/calendar?month=`(`store.build_calendar`, 사용자가 준 화면 참고, 글자도 영어 그대로) — 줄 = 1시간 칸(2026-11-06 `store.SLOT_HOURS` 2 → 1, 06:00~24:00 늘 보임, 그보다 이른 칸은 방송이 있을 때만, 칸은 시작 시간으로 정함), 열 = 날짜, 주말 노랑, 위 달 합계, 맨 아래 날짜별 TOTAL SALES·AD SPEND·HOST FEE·ROAS.
|
||||||
카드 머리 = **Tiktok Handle**(없으면 이름, 색 = 호스트 id 순 `HOST_COLORS`), SALES·COM·Fee. 카드 머리를 끌어 빈 칸으로 = 옮기기(`move`, 방송 길이 유지) · 다른 카드 위 = 맞바꾸기(`swap_with`, 날짜·시간 교환). 다시 그린 뒤 가로 위치 유지(sessionStorage). 빈 칸 + = 그 날짜·시간이 채워진 추가 창.
|
카드 머리 = **Tiktok Handle**(없으면 이름, 색 = 호스트 id 순 `HOST_COLORS`), SALES·COM·Fee. 카드 머리를 끌어 빈 칸으로 = 옮기기(`move`, 방송 길이 유지) · 다른 카드 위 = 맞바꾸기(`swap_with`, 날짜·시간 교환). 다시 그린 뒤 가로 위치 유지(sessionStorage). 빈 칸 + = 그 날짜·시간이 채워진 추가 창.
|
||||||
**AD SPEND** = 날짜별 광고비 `live_daily_ad_spend`(마이그레이션 002, `POST /live/ad-spend`, 빈칸 = 지우기), ROAS = 판매금액 ÷ 광고비(광고비 없으면 `-`). 002 미적용이면 0 으로 보이고 저장만 안내.
|
**AD SPEND** = 날짜별 광고비 `live_daily_ad_spend`(마이그레이션 002, `POST /live/ad-spend`, 빈칸 = 지우기), ROAS = 판매금액 ÷ 광고비(광고비 없으면 `-`). 002 미적용이면 0 으로 보이고 저장만 안내.
|
||||||
- **한 화면 맞춤**(2026-11-05) — 달력 보기는 넓은 화면(1101px 이상)에서 페이지 세로 스크롤 없음: `.lv-cal-wrap` 이 남은 높이를 쓰고, 풀HD 브라우저(세로 880px 이상)면 방송이 없는 달은 18개 시간 칸·합계 줄이 표 안 스크롤 없이 들어간다(카드가 있는 줄은 카드 높이만큼 커져서 방송이 많으면 표 안에서 스크롤, 페이지는 안 움직임). 카드는 시작 시간 줄에만 보인다(2시간 방송도 한 줄). 카드·표 글자·칸 크기를 늘리면 `live_calendar.browser.test.js` 로 다시 확인.
|
- **한 화면 맞춤**(2026-11-05) — 달력 보기는 넓은 화면(1101px 이상)에서 페이지 세로 스크롤 없음: `.lv-cal-wrap` 이 남은 높이를 쓰고, 풀HD 브라우저(세로 880px 이상)면 방송이 없는 달은 18개 시간 칸·합계 줄이 표 안 스크롤 없이 들어간다(카드가 있는 줄은 카드 높이만큼 커져서 방송이 많으면 표 안에서 스크롤, 페이지는 안 움직임). **방송이 걸친 칸은 합친다**(2026-11-06, `store._covered_slots` → `rowspan`, 가려진 칸 `skip`) — 2시간 방송 = 두 칸, 끝이 정각이 아니면 그 칸까지, 자정 넘김은 그날 마지막 칸까지. 합친 칸 안에서 시작하는 다른 방송은 같은 칸에 들어가고 칸이 더 늘어난다(겹친 방송). 끌어 놓기는 합친 칸의 첫 시간으로. 카드·표 글자·칸 크기를 늘리면 `live_calendar.browser.test.js` 로 다시 확인.
|
||||||
- **오른쪽 달력**(2026-11-05, 달력 보기만, 세로 2분할 `.lv-split`, 240px = 공용 달력의 80%, 예전 날짜로 이동 줄 대신, 공용 `erp-datepop` `mountRange` + `locale` 옵션으로 영문) — 날짜를 누르면 그 날이 표 맨 왼쪽(마지막 날까지 — `endGap` 이 표 끝에 여백), 다른 달이면 그 달 화면으로 가서 맨 왼쪽(sessionStorage `lv_cal_jump`). 표시만 하고 요금·일수에 안 씀. 글자 굵게, **방송 있는 날 = 숫자 오른쪽 위 초록 점**(2026-11-06, `db.broadcast_days` 보는 달 ±1년 → `#lv-live-days`, 공용 `mountRange` 의 `dayClass` 옵션 → `has-live`). 테스트 `tests/js/live_calendar.browser.test.js`(`render_live.py`).
|
- **오른쪽 달력**(2026-11-05, 달력 보기만, 세로 2분할 `.lv-split`, 240px = 공용 달력의 80%, 예전 날짜로 이동 줄 대신, 공용 `erp-datepop` `mountRange` + `locale` 옵션으로 영문) — 날짜를 누르면 그 날이 표 맨 왼쪽(마지막 날까지 — `endGap` 이 표 끝에 여백), 다른 달이면 그 달 화면으로 가서 맨 왼쪽(sessionStorage `lv_cal_jump`). 표시만 하고 요금·일수에 안 씀. 글자 굵게, **방송 있는 날 = 숫자 오른쪽 위 초록 점**(2026-11-06, `db.broadcast_days` 보는 달 ±1년 → `#lv-live-days`, 공용 `mountRange` 의 `dayClass` 옵션 → `has-live`). 테스트 `tests/js/live_calendar.browser.test.js`(`render_live.py`).
|
||||||
**말레이시아 공휴일 표 = `holidays.py`**(쿠알라룸푸르 기준, 2026·2027, 대체휴일 포함) — 이슬람 명절은 달 관측으로 바뀔 수 있고, 2028 은 공고되면 손으로 추가.
|
**말레이시아 공휴일 표 = `holidays.py`**(쿠알라룸푸르 기준, 2026·2027, 대체휴일 포함) — 이슬람 명절은 달 관측으로 바뀔 수 있고, 2028 은 공고되면 손으로 추가.
|
||||||
- **결과 이미지** — 방송 저장과 한 트랜잭션, JPG·PNG·WebP, 한 장 8MB, 방송당 10장(`store.MAX_IMAGES`). `prepare_photo` 가 실제 이미지 확인·긴 변 2400px·EXIF(GPS 등) 제거. BYTEA 저장.
|
- **결과 이미지** — 방송 저장과 한 트랜잭션, JPG·PNG·WebP, 한 장 8MB, 방송당 10장(`store.MAX_IMAGES`). `prepare_photo` 가 실제 이미지 확인·긴 변 2400px·EXIF(GPS 등) 제거. BYTEA 저장.
|
||||||
|
|||||||
@@ -177,10 +177,22 @@ def _roas(sales: Decimal, ad_spend: Decimal) -> str:
|
|||||||
return f"{sales / ad_spend:.2f}" if ad_spend else "-"
|
return f"{sales / ad_spend:.2f}" if ad_spend else "-"
|
||||||
|
|
||||||
|
|
||||||
|
def _slot_of(hour: int) -> int:
|
||||||
|
return hour // SLOT_HOURS * SLOT_HOURS
|
||||||
|
|
||||||
|
|
||||||
|
def _covered_slots(b: dict[str, Any]) -> list[int]:
|
||||||
|
"""방송이 걸친 칸(시작 칸 ~ 끝 시각 올림 직전 칸). 자정을 넘기거나 00:00 에 끝나면 그날 마지막 칸까지."""
|
||||||
|
s, e = b["start_time"], b["end_time"]
|
||||||
|
end = 24 if e <= s else e.hour + (1 if (e.minute or e.second) else 0)
|
||||||
|
return sorted({_slot_of(h) for h in range(s.hour, max(end, s.hour + 1))})
|
||||||
|
|
||||||
|
|
||||||
def build_calendar(span: dict[str, Any], broadcasts: list[dict[str, Any]], ad_spend: dict[date, Decimal], today: date, lang: str = "ko") -> dict[str, Any]:
|
def build_calendar(span: dict[str, Any], broadcasts: list[dict[str, Any]], ad_spend: dict[date, Decimal], today: date, lang: str = "ko") -> dict[str, Any]:
|
||||||
"""달력 보기 값 — 날짜(열)·SLOT_HOURS 칸(줄)·날짜별 합계·달 합계. 칸은 시작 시간으로 정한다."""
|
"""달력 보기 값 — 날짜(열)·SLOT_HOURS 칸(줄)·날짜별 합계·달 합계. 카드는 시작 칸에, 그 칸은 방송이 걸친 칸만큼 아래로 합친다
|
||||||
|
(rowspan, 2026-11-06). 합친 칸 안에서 시작하는 다른 방송도 같은 칸에 들어가고 더 길면 칸이 더 늘어난다. 가려진 칸 = {"skip": True}."""
|
||||||
views = [(b, broadcast_view(b, lang)) for b in broadcasts]
|
views = [(b, broadcast_view(b, lang)) for b in broadcasts]
|
||||||
used = {b["start_time"].hour // SLOT_HOURS * SLOT_HOURS for b, _ in views}
|
used = {h for b, _ in views for h in _covered_slots(b)}
|
||||||
days = []
|
days = []
|
||||||
day = span["start"]
|
day = span["start"]
|
||||||
while day < span["end"]:
|
while day < span["end"]:
|
||||||
@@ -193,13 +205,28 @@ def build_calendar(span: dict[str, Any], broadcasts: list[dict[str, Any]], ad_sp
|
|||||||
"count": len(mine), "sales": sales, "fee": fee, "spend": spend,
|
"count": len(mine), "sales": sales, "fee": fee, "spend": spend,
|
||||||
"sales_text": fmt_short(sales), "fee_text": fmt_short(fee), "spend_text": fmt_short(spend), "roas": _roas(sales, spend)})
|
"sales_text": fmt_short(sales), "fee_text": fmt_short(fee), "spend_text": fmt_short(spend), "roas": _roas(sales, spend)})
|
||||||
day += timedelta(days=1)
|
day += timedelta(days=1)
|
||||||
|
hours = sorted(set(range(FIRST_SLOT_HOUR, 24, SLOT_HOURS)) | used) # 방송이 걸친 칸은 늘 있음 → 합칠 칸이 이어져 있다
|
||||||
|
columns = []
|
||||||
|
for d in days:
|
||||||
|
mine = [(b, v) for b, v in views if b["broadcast_date"] == d["date"]]
|
||||||
|
col, i = [], 0
|
||||||
|
while i < len(hours):
|
||||||
|
group = [(b, v) for b, v in mine if _slot_of(b["start_time"].hour) == hours[i]]
|
||||||
|
last, j = max((_covered_slots(b)[-1] for b, _ in group), default=hours[i]), i + 1
|
||||||
|
while j < len(hours) and hours[j] <= last:
|
||||||
|
more = [(b, v) for b, v in mine if _slot_of(b["start_time"].hour) == hours[j]]
|
||||||
|
group += more
|
||||||
|
last = max([last] + [_covered_slots(b)[-1] for b, _ in more])
|
||||||
|
j += 1
|
||||||
|
col.append({"iso": d["iso"], "is_weekend": d["is_weekend"], "cards": [v for _, v in group], "rowspan": j - i})
|
||||||
|
col += [{"skip": True}] * (j - i - 1)
|
||||||
|
i = j
|
||||||
|
columns.append(col)
|
||||||
slots = []
|
slots = []
|
||||||
for hour in sorted(set(range(FIRST_SLOT_HOUR, 24, SLOT_HOURS)) | used):
|
for k, hour in enumerate(hours):
|
||||||
end_hour = (hour + SLOT_HOURS) % 24
|
end_hour = (hour + SLOT_HOURS) % 24
|
||||||
cells = [{"iso": d["iso"], "is_weekend": d["is_weekend"],
|
slots.append({"start": f"{hour:02d}:00", "end": f"{end_hour:02d}:00", "label": f"{hour:02d}:00 - {end_hour:02d}:00",
|
||||||
"cards": [v for b, v in views if b["broadcast_date"] == d["date"] and b["start_time"].hour // SLOT_HOURS * SLOT_HOURS == hour]}
|
"cells": [col[k] for col in columns]})
|
||||||
for d in days]
|
|
||||||
slots.append({"start": f"{hour:02d}:00", "end": f"{end_hour:02d}:00", "label": f"{hour:02d}:00 - {end_hour:02d}:00", "cells": cells})
|
|
||||||
sales, fee, spend = (sum((d[k] for d in days), Decimal(0)) for k in ("sales", "fee", "spend"))
|
sales, fee, spend = (sum((d[k] for d in days), Decimal(0)) for k in ("sales", "fee", "spend"))
|
||||||
return {"days": days, "slots": slots, "slot_note": f"{SLOT_HOURS} Hour{'s' if SLOT_HOURS > 1 else ''} (RM{fmt_short(HOURLY_RATE * SLOT_HOURS)} Base)" if lang == "en" else f"{SLOT_HOURS}시간 (기본 RM{fmt_short(HOURLY_RATE * SLOT_HOURS)})",
|
return {"days": days, "slots": slots, "slot_note": f"{SLOT_HOURS} Hour{'s' if SLOT_HOURS > 1 else ''} (RM{fmt_short(HOURLY_RATE * SLOT_HOURS)} Base)" if lang == "en" else f"{SLOT_HOURS}시간 (기본 RM{fmt_short(HOURLY_RATE * SLOT_HOURS)})",
|
||||||
"commission_percent": fmt_short(COMMISSION_PERCENT).split(".")[0],
|
"commission_percent": fmt_short(COMMISSION_PERCENT).split(".")[0],
|
||||||
|
|||||||
@@ -36,8 +36,8 @@
|
|||||||
{% for slot in cal.slots %}
|
{% for slot in cal.slots %}
|
||||||
<tr>
|
<tr>
|
||||||
<th class="lv-cal-time" scope="row">{{ slot.label }}<small>{{ cal.slot_note }}</small></th>
|
<th class="lv-cal-time" scope="row">{{ slot.label }}<small>{{ cal.slot_note }}</small></th>
|
||||||
{% for cell in slot.cells %}
|
{% for cell in slot.cells %}{% if not cell.skip %}{#- skip = 위 칸에 합쳐진 칸(방송이 걸친 시간만큼 rowspan) -#}
|
||||||
<td class="lv-cell{% if cell.is_weekend %} is-weekend{% endif %}" data-drop data-day="{{ cell.iso }}" data-start="{{ slot.start }}">
|
<td class="lv-cell{% if cell.is_weekend %} is-weekend{% endif %}"{% if cell.rowspan > 1 %} rowspan="{{ cell.rowspan }}"{% endif %} data-drop data-day="{{ cell.iso }}" data-start="{{ slot.start }}">
|
||||||
{% for c in cell.cards %}
|
{% for c in cell.cards %}
|
||||||
<article class="lv-card" data-card="{{ c.id }}">
|
<article class="lv-card" data-card="{{ c.id }}">
|
||||||
<header class="lv-card-head" draggable="true" style="background:{{ c.color }}" title="{{ c.host_name }} · {{ c.times }}{% if c.venue %} · {{ c.venue }}{% endif %}">
|
<header class="lv-card-head" draggable="true" style="background:{{ c.color }}" title="{{ c.host_name }} · {{ c.times }}{% if c.venue %} · {{ c.venue }}{% endif %}">
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
<button type="button" class="lv-cell-add" data-new='{{ {"broadcast_date": cell.iso, "start_time": slot.start, "end_time": slot.end} | tojson }}' aria-label="{{ t('{date} {slot} 방송 추가').format(date=cell.iso, slot=slot.label) }}">+</button>
|
<button type="button" class="lv-cell-add" data-new='{{ {"broadcast_date": cell.iso, "start_time": slot.start, "end_time": slot.end} | tojson }}' aria-label="{{ t('{date} {slot} 방송 추가').format(date=cell.iso, slot=slot.label) }}">+</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
{% endfor %}
|
{% endif %}{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -114,6 +114,19 @@ function check(name, cond, extra) {
|
|||||||
await day("2026-11-02").click();
|
await day("2026-11-02").click();
|
||||||
await p.waitForTimeout(150);
|
await p.waitForTimeout(150);
|
||||||
check("앞날로 돌아감", (await gap("2026-11-02")) < 2, await gap("2026-11-02"));
|
check("앞날로 돌아감", (await gap("2026-11-02")) < 2, await gap("2026-11-02"));
|
||||||
|
// 2시간 방송 = 두 칸 합침(rowspan), 22:00~23:30 = 22·23 칸
|
||||||
|
const merged = await p.evaluate(function () {
|
||||||
|
return Array.from(document.querySelectorAll('td[data-day="2026-11-05"]')).map(function (td) { return td.dataset.start + "/" + (td.rowSpan || 1); });
|
||||||
|
});
|
||||||
|
check("2시간 방송 = 두 칸 합침", merged.slice(0, 3).join(",") === "06:00/2,08:00/2,10:00/2" && merged[merged.length - 1] === "22:00/2", merged);
|
||||||
|
const tall = await p.evaluate(function () {
|
||||||
|
const m = document.querySelector('td[data-day="2026-11-05"][data-start="06:00"]').getBoundingClientRect().height;
|
||||||
|
const one = document.querySelector('td[data-day="2026-11-04"][data-start="06:00"]').getBoundingClientRect().height;
|
||||||
|
const two = document.querySelector('td[data-day="2026-11-04"][data-start="07:00"]').getBoundingClientRect().height;
|
||||||
|
return Math.abs(m - one - two);
|
||||||
|
});
|
||||||
|
check("합친 칸 높이 = 두 줄", tall < 2, tall);
|
||||||
|
await p.screenshot({ path: path.join(__dirname, ".out", "live_merge.png") });
|
||||||
|
|
||||||
await p.locator('#lv-side-cal [data-nav="1"]').click();
|
await p.locator('#lv-side-cal [data-nav="1"]').click();
|
||||||
await Promise.all([p.waitForURL(/month=2026-12/), day("2026-12-10").click()]);
|
await Promise.all([p.waitForURL(/month=2026-12/), day("2026-12-10").click()]);
|
||||||
|
|||||||
+20
-2
@@ -192,8 +192,26 @@ class StoreTests(unittest.TestCase):
|
|||||||
self.assertEqual(cal["totals"]["sales"], "48")
|
self.assertEqual(cal["totals"]["sales"], "48")
|
||||||
# 06시보다 이른 칸은 방송이 있을 때만
|
# 06시보다 이른 칸은 방송이 있을 때만
|
||||||
early = store.build_calendar(span, [b(9, date(2026, 11, 1), time(3, 0), time(5, 0))], {}, date(2026, 11, 4))
|
early = store.build_calendar(span, [b(9, date(2026, 11, 1), time(3, 0), time(5, 0))], {}, date(2026, 11, 4))
|
||||||
self.assertEqual(early["slots"][0]["label"], "03:00 - 04:00")
|
self.assertEqual([s["label"] for s in early["slots"]][:3], ["03:00 - 04:00", "04:00 - 05:00", "06:00 - 07:00"]) # 걸친 칸은 늘 있음
|
||||||
self.assertEqual(len(early["slots"]), 19)
|
self.assertEqual(len(early["slots"]), 20)
|
||||||
|
|
||||||
|
# 칸 합치기(rowspan) — 방송이 걸친 시간만큼, 겹쳐 시작하는 방송은 같은 칸, 자정 넘김은 그날 끝까지
|
||||||
|
def col(c, day_index):
|
||||||
|
return [(s["start"], cell.get("rowspan"), [x["id"] for x in cell.get("cards", [])]) for s in c["slots"]
|
||||||
|
for cell in [s["cells"][day_index]] if not cell.get("skip")]
|
||||||
|
self.assertEqual(col(cal, 3)[6:9], [("12:00", 2, [1]), ("14:00", 1, []), ("15:00", 1, [])]) # 12~14 = 두 칸
|
||||||
|
self.assertEqual(col(cal, 3)[-1], ("22:00", 2, [2])) # 22~00 = 22·23 칸
|
||||||
|
self.assertEqual(col(cal, 6)[7], ("13:00", 2, [3])) # 13:30~15:00 = 13·14 칸
|
||||||
|
self.assertEqual(sum(1 for s in cal["slots"] if s["cells"][3].get("skip")), 2)
|
||||||
|
m = store.build_calendar(span, [b(5, date(2026, 11, 2), time(6, 0), time(8, 0)), b(6, date(2026, 11, 2), time(7, 0), time(10, 0)),
|
||||||
|
b(7, date(2026, 11, 2), time(23, 0), time(1, 0)), b(8, date(2026, 11, 2), time(20, 0), time(20, 30))],
|
||||||
|
{}, date(2026, 11, 4))
|
||||||
|
self.assertEqual(col(m, 1)[0], ("06:00", 4, [5, 6])) # 6~8 + 7~10 = 6·7·8·9
|
||||||
|
self.assertEqual(col(m, 1)[1][0], "10:00")
|
||||||
|
self.assertIn(("20:00", 1, [8]), col(m, 1)) # 30분 = 한 칸
|
||||||
|
self.assertEqual(col(m, 1)[-1], ("23:00", 1, [7])) # 자정 넘김 = 그날 마지막 칸까지
|
||||||
|
for s in m["slots"]: # 날짜마다 칸 수(합친 칸 포함) = 줄 수
|
||||||
|
self.assertEqual(len(s["cells"]), 30)
|
||||||
|
|
||||||
def test_thumbnail(self):
|
def test_thumbnail(self):
|
||||||
for mode, fmt in (("RGB", "JPEG"), ("RGBA", "PNG")):
|
for mode, fmt in (("RGB", "JPEG"), ("RGBA", "PNG")):
|
||||||
|
|||||||
Reference in New Issue
Block a user