Spaces:
Running
Running
Handle fractional session timestamps on Python 3.10
Browse files
app.py
CHANGED
|
@@ -521,7 +521,18 @@ def results(session_id: UUID, request: Request):
|
|
| 521 |
"postActionMetrics": [], "fullIntervalMetrics": full_interval_metrics,
|
| 522 |
"skeleton": report.get("skeleton_history", []), "rawAnalytics": analytics})
|
| 523 |
created = row.get("created_at")
|
| 524 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
if created_at.tzinfo is None:
|
| 526 |
created_at = created_at.replace(tzinfo=timezone.utc)
|
| 527 |
return {"id": str(session_id), "playerId": row["player_id"], "playerName": "",
|
|
|
|
| 521 |
"postActionMetrics": [], "fullIntervalMetrics": full_interval_metrics,
|
| 522 |
"skeleton": report.get("skeleton_history", []), "rawAnalytics": analytics})
|
| 523 |
created = row.get("created_at")
|
| 524 |
+
if created:
|
| 525 |
+
created_iso = created.replace("Z", "+00:00")
|
| 526 |
+
# Python 3.10's fromisoformat requires a six-digit fractional second,
|
| 527 |
+
# while the API may return a shorter fraction such as `.89`.
|
| 528 |
+
created_iso = re.sub(
|
| 529 |
+
r"(?<=\.)\d+(?=(?:[+-]\d{2}:\d{2})?$)",
|
| 530 |
+
lambda match: match.group(0)[:6].ljust(6, "0"),
|
| 531 |
+
created_iso,
|
| 532 |
+
)
|
| 533 |
+
created_at = datetime.fromisoformat(created_iso)
|
| 534 |
+
else:
|
| 535 |
+
created_at = datetime.now(timezone.utc)
|
| 536 |
if created_at.tzinfo is None:
|
| 537 |
created_at = created_at.replace(tzinfo=timezone.utc)
|
| 538 |
return {"id": str(session_id), "playerId": row["player_id"], "playerName": "",
|