Add saved analysis workspace and live dashboard statistics
This commit is contained in:
+23
-3
@@ -30,7 +30,7 @@ from .analytics import pace_text
|
||||
from .display import stored_analysis
|
||||
from .extensions import db, limiter
|
||||
from .history import activity_page, latest_mapped_run, overview, records_for
|
||||
from .models import Activity, Friendship, GarminConnection, User
|
||||
from .models import Activity, Friendship, GarminConnection, SavedAnalysis, User
|
||||
from .services import activity_data, import_cache, import_upload, route_data
|
||||
from .stats import DEFAULT, METRICS, explore, parse_query, period_bounds, query_text
|
||||
from .stats_analysis import EXTRA_UNITS, FUNCTIONS, GROUPS
|
||||
@@ -196,16 +196,34 @@ def dashboard():
|
||||
record_book=records_for(current_user.id, {row.id for row in pagination.items}),
|
||||
mapped_run=latest_mapped_run(filters),
|
||||
pace_text=pace_text,
|
||||
analyses=db.session.scalars(
|
||||
db.select(SavedAnalysis)
|
||||
.filter_by(owner_id=current_user.id, pinned=True)
|
||||
.order_by(SavedAnalysis.position, SavedAnalysis.id)
|
||||
).all(),
|
||||
)
|
||||
|
||||
|
||||
@web.get("/stats")
|
||||
@login_required
|
||||
def stats():
|
||||
from .analysis_library import owned, serialize
|
||||
from .stats_presets import PRESETS
|
||||
|
||||
saved = None
|
||||
if request.args.get("analysis"):
|
||||
try:
|
||||
analysis_id = int(request.args["analysis"])
|
||||
except ValueError:
|
||||
abort(404)
|
||||
saved = owned(analysis_id)
|
||||
args = dict(request.args)
|
||||
if saved and "query" not in args:
|
||||
args["query"] = saved.query
|
||||
error = None
|
||||
results = None
|
||||
try:
|
||||
query = parse_query(request.args)
|
||||
query = parse_query(args)
|
||||
page = int(request.args.get("page", "1"))
|
||||
results = explore(current_user.id, current_user.timezone, query, page)
|
||||
except (ValueError, OverflowError) as exc:
|
||||
@@ -218,7 +236,9 @@ def stats():
|
||||
metrics=METRICS,
|
||||
results=results,
|
||||
error=error,
|
||||
submitted_query=request.args.get("query", ""),
|
||||
submitted_query=args.get("query", ""),
|
||||
selected_analysis=serialize(saved) if saved else None,
|
||||
presets=PRESETS,
|
||||
language={
|
||||
"functions": sorted(FUNCTIONS),
|
||||
"groups": sorted(GROUPS),
|
||||
|
||||
Reference in New Issue
Block a user