42 lines
2.7 KiB
Python
42 lines
2.7 KiB
Python
"""Synthetic homepage fixtures following the observed BRAIN schemas."""
|
|
from datetime import datetime, timedelta, timezone
|
|
|
|
import httpx
|
|
|
|
|
|
def response(request):
|
|
if request.method != "GET":
|
|
return None
|
|
path = request.url.path
|
|
at = datetime.now(timezone.utc)
|
|
def page(items, next=None):
|
|
return httpx.Response(200, json={"results": items, "count": len(items), "next": next})
|
|
competition = {
|
|
"id": "HOME2026", "name": "跨区域 Alpha 研究挑战赛", "description": "探索不同区域的研究机会。",
|
|
"startDate": (at - timedelta(days=3)).isoformat(), "endDate": (at + timedelta(days=21)).isoformat(),
|
|
"status": "ACCEPTED", "leaderboard": {"user": "TEST_USER", "rank": 128, "alphas": 6, "robustnessScore": 42},
|
|
}
|
|
if path == "/users/self/messages":
|
|
offset = int(request.url.params.get("offset", 0))
|
|
return page([
|
|
{"id": f"news-{offset}", "title": "平台研究工具更新" if offset == 0 else "社区研究分享会回顾", "type": "ANNOUNCEMENT",
|
|
"dateCreated": at.isoformat(), "description": "<p>平台新增数据研究资源,帮助研究员核对字段覆盖范围。</p><p>社区分享会介绍了研究方法与论文线索。</p>"},
|
|
{"id": f"event-{offset}", "title": "全球研究网络研讨会预告", "type": "ANNOUNCEMENT", "dateCreated": at.isoformat(),
|
|
"description": "<p>欢迎查看平台活动页面了解时间与议程。</p>"},
|
|
], "https://api.worldquantbrain.com/users/self/messages?offset=2" if offset == 0 else None)
|
|
if path == "/consultant/boards/leader":
|
|
return page([{"user": "TEST_USER", "dailyOsmosisRank": 246}])
|
|
if path == "/users/TEST_USER/competitions":
|
|
return page([competition, {**competition, "id": "UNKNOWN", "name": "研究方法交流挑战", "endDate": None, "leaderboard": None}])
|
|
if path.startswith("/competitions/") and path.endswith("/agreement"):
|
|
return httpx.Response(200, json={"title": "参赛规则与要求", "lastModified": at.isoformat(), "content": [
|
|
{"type": "TEXT", "value": "<p>Participants must use GLOBAL region. Delay must be 1.</p><p>All submitted work must be original.</p>"}
|
|
]})
|
|
if path.startswith("/competitions/"):
|
|
return httpx.Response(200, json=competition)
|
|
if path == "/events":
|
|
return page([{"id": "webinar", "title": "全球研究网络研讨会", "type": "ONLINE", "timezone": "UTC",
|
|
"start": (at + timedelta(days=2)).isoformat(), "end": (at + timedelta(days=2, hours=1)).isoformat(),
|
|
"description": "讨论数据覆盖、研究方法及比赛准备。"}])
|
|
return None
|