77a7f568b2
- refresh_daily new_visitors 加 is_bot=False(爬虫不是受众,四指标口径统一) - test_refresh_daily_shanghai_boundary:固定 UTC 时间戳钉死上海自然日界 - test_refresh_daily_excludes_bots:事件/会话/访客 is_bot 均不计入 - refresh_stats 删未使用的 stat = 赋值 Co-Authored-By: Claude Code <noreply@anthropic.com>
25 lines
920 B
Python
25 lines
920 B
Python
from datetime import timedelta
|
||
from django.core.management.base import BaseCommand
|
||
from django.utils import timezone
|
||
from tracker.models import Site
|
||
from tracker.services.stats import refresh_daily
|
||
|
||
|
||
class Command(BaseCommand):
|
||
# 生产调度:1Panel 计划任务每日 00:10 执行
|
||
# docker exec <web容器> python manage.py refresh_stats --days 2
|
||
# (回刷含今天在内的近 N 天,详见 Task 22 README)
|
||
help = "回刷近 N 天日聚合(含今天)"
|
||
|
||
def add_arguments(self, parser):
|
||
parser.add_argument("--days", type=int, default=2)
|
||
|
||
def handle(self, *args, **opts):
|
||
today = timezone.localdate()
|
||
total = 0
|
||
for site in Site.objects.filter(is_active=True):
|
||
for i in range(opts["days"]):
|
||
refresh_daily(site, today - timedelta(days=i))
|
||
total += 1
|
||
self.stdout.write(f"refreshed {total} site-days")
|