Skip to content

Commit

Permalink
Support graphing multiple run comparisons
Browse files Browse the repository at this point in the history
When graphing metrics from two runs, the timestamps rarely align; so we add a
`relative` option to convert the absolute metric timestamps into relative
delta seconds from each run's start.
  • Loading branch information
dbutenhof committed Jan 29, 2025
1 parent a6ec6ee commit b156ff3
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions backend/app/services/crucible_svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,21 @@ class GraphList(BaseModel):
omitted if all Graph objects specify a run ID. (This is most useful to
select a set of graphs all for a single run ID.)
Normally the X axis will be the actual sample timestamp values; if you
specify relative=True, the X axis will be the duration from the first
timestamp of the metric series, in seconds. This allows graphs of similar
runs started at different times to be overlaid.
Fields:
run: Specify the (default) run ID
name: Specify a name for the set of graphs
relative: True for relative timescale in seconds
graphs: a list of Graph objects
"""

run: Optional[str] = None
name: str
relative: bool = False
graphs: list[Graph]


Expand Down Expand Up @@ -1208,6 +1215,7 @@ async def get_runs(
"params": iparams,
}
)
run["iterations"].sort(key=lambda i: i["iteration"])
run["params"] = common.render()
try:
run["begin_date"] = self._format_timestamp(run["begin"])
Expand Down Expand Up @@ -1904,10 +1912,19 @@ async def get_metrics_graph(self, graphdata: GraphList) -> dict[str, Any]:
x = []
y = []

first = None

for p in sorted(points, key=lambda a: a.begin):
x.extend(
[self._format_timestamp(p.begin), self._format_timestamp(p.end)]
)
if graphdata.relative:
if not first:
first = p.begin
s = (p.begin - first) / 1000.0
e = (p.end - first) / 1000.0
x.extend([s, e])
else:
x.extend(
[self._format_timestamp(p.begin), self._format_timestamp(p.end)]
)
y.extend([p.value, p.value])
y_max = max(y_max, p.value)

Expand Down

0 comments on commit b156ff3

Please sign in to comment.