Add saved analysis workspace and live dashboard statistics
This commit is contained in:
+41
-11
@@ -12,7 +12,7 @@ from waitress import serve
|
||||
from app import create_app
|
||||
from app.display import persist_analysis
|
||||
from app.extensions import db
|
||||
from app.models import Activity, User
|
||||
from app.models import Activity, SavedAnalysis, User
|
||||
from app.records import persist_efforts
|
||||
|
||||
app = create_app(
|
||||
@@ -33,14 +33,20 @@ with app.app_context():
|
||||
)
|
||||
db.session.add(user)
|
||||
db.session.flush()
|
||||
for i in range(5):
|
||||
analysis_preview = "--analysis" in sys.argv
|
||||
for i in range(70 if analysis_preview else 5):
|
||||
effort_hr = 157 + i % 3 if i < 8 else 141 + i % 5
|
||||
samples = [
|
||||
{
|
||||
"point": [51.507 + 0.007 * math.sin(n / 70), -0.14 + n / 25000],
|
||||
"distance": n * 20,
|
||||
"distance": n * (15 if analysis_preview else 20),
|
||||
"time": n * 5,
|
||||
"speed": 2.8 + 0.3 * math.sin(n / 20),
|
||||
"heart_rate": 140 + 12 * math.sin(n / 30),
|
||||
"speed": 3 + 0.02 * math.sin(n / 20)
|
||||
if analysis_preview
|
||||
else 2.8 + 0.3 * math.sin(n / 20),
|
||||
"heart_rate": effort_hr + math.sin(n / 30)
|
||||
if analysis_preview
|
||||
else 140 + 12 * math.sin(n / 30),
|
||||
"elevation": 10 + n / 30,
|
||||
}
|
||||
for n in range(300)
|
||||
@@ -55,12 +61,12 @@ with app.app_context():
|
||||
"Easy Sunday",
|
||||
"Tempo session",
|
||||
"Evening loop",
|
||||
][i],
|
||||
started_at=datetime.now(UTC) - timedelta(days=i * 5),
|
||||
distance_m=6000 + i * 700,
|
||||
duration_s=2100 + i * 200,
|
||||
elevation_m=38 + i * 7,
|
||||
avg_hr=145,
|
||||
][i % 5],
|
||||
started_at=datetime.now(UTC) - timedelta(days=i * (2 if analysis_preview else 5)),
|
||||
distance_m=6000 if analysis_preview else 6000 + i * 700,
|
||||
duration_s=1980 if analysis_preview else 2100 + i * 200,
|
||||
elevation_m=30 if analysis_preview else 38 + i * 7,
|
||||
avg_hr=effort_hr if analysis_preview else 145,
|
||||
sport="running",
|
||||
visibility="friends",
|
||||
samples=samples,
|
||||
@@ -71,6 +77,30 @@ with app.app_context():
|
||||
if isinstance(row, Activity):
|
||||
persist_efforts(row)
|
||||
persist_analysis(row)
|
||||
if analysis_preview:
|
||||
from app.stats_presets import PRESETS
|
||||
|
||||
names = [
|
||||
"HR at comparable pace",
|
||||
"Workload context",
|
||||
"HR in steady segments",
|
||||
"Easy and harder volume",
|
||||
]
|
||||
for position, name in enumerate(names):
|
||||
preset = next(preset for preset in PRESETS if preset["name"] == name)
|
||||
db.session.add(
|
||||
SavedAnalysis(
|
||||
owner_id=user.id,
|
||||
name=name,
|
||||
collection="Effort investigation",
|
||||
query=preset["query"],
|
||||
pinned=True,
|
||||
position=position,
|
||||
width="half",
|
||||
view="chart",
|
||||
notes="Synthetic preview data.",
|
||||
)
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
# Test-only auto-login, isolated to this ephemeral process/database.
|
||||
|
||||
Reference in New Issue
Block a user