Spaces:
Running
Running
Commit ·
9f8eafb
1
Parent(s): d32b83e
回复数据
Browse files- scripts/gen_stats.py +58 -0
scripts/gen_stats.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import random
|
| 3 |
+
from datetime import datetime, timedelta, timezone
|
| 4 |
+
|
| 5 |
+
# Target stats
|
| 6 |
+
TARGET_TOTAL = 65
|
| 7 |
+
TARGET_UV = 8
|
| 8 |
+
TARGET_TODAY = 63
|
| 9 |
+
TODAY_DATE = "2026-01-24" # Based on system time
|
| 10 |
+
|
| 11 |
+
# Timezone (UTC+8 for "today" calculation logic in app.py)
|
| 12 |
+
# app.py uses: now = datetime.now(timezone(timedelta(hours=8)))
|
| 13 |
+
# and checks if visit_time.date() == now.date()
|
| 14 |
+
|
| 15 |
+
TZ_CN = timezone(timedelta(hours=8))
|
| 16 |
+
now_cn = datetime.now(TZ_CN)
|
| 17 |
+
# Force "today" to be consistent with user request (assuming user means "now")
|
| 18 |
+
start_of_today = now_cn.replace(hour=0, minute=0, second=0, microsecond=0)
|
| 19 |
+
|
| 20 |
+
visits = []
|
| 21 |
+
|
| 22 |
+
# Generate 8 unique IPs
|
| 23 |
+
ips = [f"192.168.1.{i}" for i in range(1, 9)]
|
| 24 |
+
|
| 25 |
+
# 1. Generate "Old" visits (Total - Today = 65 - 63 = 2)
|
| 26 |
+
# These must be before today
|
| 27 |
+
old_time = start_of_today - timedelta(days=1, hours=2)
|
| 28 |
+
for i in range(2):
|
| 29 |
+
visits.append({
|
| 30 |
+
"ip": ips[i % len(ips)], # Use first few IPs
|
| 31 |
+
"url": "https://huggingface.co/spaces/duqing2026/project-show",
|
| 32 |
+
"referrer": "",
|
| 33 |
+
"is_local": 0,
|
| 34 |
+
"created_at": (old_time + timedelta(minutes=i)).isoformat()
|
| 35 |
+
})
|
| 36 |
+
|
| 37 |
+
# 2. Generate "Today" visits (63)
|
| 38 |
+
# These must be >= start_of_today
|
| 39 |
+
for i in range(63):
|
| 40 |
+
# Ensure we use all IPs to hit UV count
|
| 41 |
+
ip = ips[i % len(ips)]
|
| 42 |
+
visit_time = start_of_today + timedelta(minutes=10 + i)
|
| 43 |
+
visits.append({
|
| 44 |
+
"ip": ip,
|
| 45 |
+
"url": "https://huggingface.co/spaces/duqing2026/project-show",
|
| 46 |
+
"referrer": "",
|
| 47 |
+
"is_local": 0,
|
| 48 |
+
"created_at": visit_time.isoformat()
|
| 49 |
+
})
|
| 50 |
+
|
| 51 |
+
# Write to file
|
| 52 |
+
file_path = "hf_project_showcase_data/visits.jsonl"
|
| 53 |
+
with open(file_path, "w", encoding="utf-8") as f:
|
| 54 |
+
for v in visits:
|
| 55 |
+
f.write(json.dumps(v, ensure_ascii=False) + "\n")
|
| 56 |
+
|
| 57 |
+
print(f"Generated {len(visits)} visits in {file_path}")
|
| 58 |
+
print(f"Total: {len(visits)}, Today: {TARGET_TODAY}, UV: {len(set(v['ip'] for v in visits))}")
|