Replace fixed DSL fields with parameterized metric expressions
This commit is contained in:
+6
-6
@@ -71,7 +71,6 @@ DEFAULT = {
|
||||
"source": "runs",
|
||||
"cohorts": [],
|
||||
"reduce": None,
|
||||
"long_run": 10.0,
|
||||
"route": None,
|
||||
"comparison": "period",
|
||||
}
|
||||
@@ -137,12 +136,11 @@ def query_text(q):
|
||||
lines = [q["source"], " " + period]
|
||||
if q["reduce"]:
|
||||
lines.append(f" reduce by run min {number_text(q['reduce'])} min")
|
||||
if q["long_run"] != 10:
|
||||
lines.append(f" long run distance >= {number_text(q['long_run'])} km")
|
||||
if q["route"]:
|
||||
lines.append(f" route similar to {q['route']}")
|
||||
for spec in q["derived"]:
|
||||
lines.append(f" let {spec['name']} = {spec['expression']}")
|
||||
if not spec.get("inline"):
|
||||
lines.append(f" let {spec['name']} = {spec['expression']}")
|
||||
if q["end"] and not q["start"]:
|
||||
lines.append(f" ending {q['end']}")
|
||||
if not q["filter_groups"] or q["minimum"]:
|
||||
@@ -154,7 +152,7 @@ def query_text(q):
|
||||
):
|
||||
if q[key] is not None:
|
||||
lines.append(f" and {clause} {number_text(q[key])} {unit}")
|
||||
units = {**UNITS, **EXTRA_UNITS, **{spec["name"]: {spec["unit"]: 1} for spec in q["derived"]}}
|
||||
units = {**UNITS, **EXTRA_UNITS, **{spec["name"]: ({"s": 1, "min": 60} if spec["unit"] == "time" else {spec["unit"]: 1}) for spec in q["derived"]}}
|
||||
|
||||
def clause(condition, prefix="and"):
|
||||
field, op = condition["field"], condition["op"]
|
||||
@@ -252,7 +250,9 @@ def query_text(q):
|
||||
lines.append(
|
||||
f" cohort {json.dumps(cohort['name'], ensure_ascii=False)} where {cohort['source']}"
|
||||
)
|
||||
return "\n".join(lines)
|
||||
from .stats_expressions import render
|
||||
|
||||
return render("\n".join(lines), q["derived"])
|
||||
|
||||
|
||||
def query_metrics(q):
|
||||
|
||||
Reference in New Issue
Block a user