Enforce campaign launch dates in dashboard data

This commit is contained in:
Codex
2026-09-14 16:29:07 +08:00
parent 308fe9d5e9
commit 632a9d2a68
2 changed files with 11 additions and 2 deletions
+10 -1
View File
@@ -56,6 +56,13 @@ if events_path:
events[key] = events.get(key, 0) + num(event_row.get('event_num'))
config = [r for r in json.load(open('campaign_config.json', encoding='utf-8')) if r['status'].lower() == 'active']
def active_on(meta, date):
"""Respect the Campaign info remark such as 0912新上 for historical backfills."""
match = re.search(r'(?<!\d)(\d{2})(\d{2})\s*新上', str(meta.get('remark', '')))
if not match:
return True
return date >= f'{date[:4]}-{match.group(1)}-{match.group(2)}'
experiment = {}
for r in config:
if r['group'] == '实验组':
@@ -83,6 +90,7 @@ for raw_row in matrix[1:] if has_header else matrix:
pkg, source = cell(raw_row, 'pkg').strip(), cell(raw_row, 'source').strip().lower()
campaign = cell(raw_row, 'campaign').strip()
if not pkg or not source or not campaign: continue
date = cell(raw_row, 'date').strip() or target
exp = next((meta for adping, meta in experiment.get((pkg, source), [])
if re.search(r'(?<!\d)' + re.escape(adping) + r'(?!\d)', campaign)), None)
if not exp:
@@ -97,7 +105,8 @@ for raw_row in matrix[1:] if has_header else matrix:
unresolved.append(campaign)
continue
group, shown, adping = '对照组', 'General campaign', ''
date = cell(raw_row, 'date').strip() or target
if not active_on(meta, date):
continue
required = event_names(meta.get('kpi',''))
if not required or (date, source) not in covered_scopes:
event = None