Skip to content

Commit

Permalink
Fix fetchMeasurementsByProjectIdRunIdCommitId query and related typing
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Marr <git@stefan-marr.de>
  • Loading branch information
smarr committed Mar 24, 2024
1 parent 9964d97 commit 44554a1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/backend/compare/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ export async function getMeasurements(
name: 'fetchMeasurementsByProjectIdRunIdCommitId',
text: `SELECT
trialId, source.commitId as commitId,
invocation, iteration, warmup,
invocation, warmup,
criterion.name as criterion,
criterion.unit as unit,
value
values
FROM
Measurement
JOIN Trial ON trialId = Trial.id
Expand All @@ -113,7 +113,7 @@ export async function getMeasurements(
WHERE Project.slug = $1
AND runId = $2
AND (source.commitId = $3 OR source.commitId = $4)
ORDER BY trialId, criterion, invocation, iteration;`,
ORDER BY trialId, criterion, invocation;`,
values: [projectSlug, runId, baseCommitId, changeCommitId]
};
const result = await db.query(q);
Expand Down Expand Up @@ -154,7 +154,7 @@ export async function getMeasurements(
critObject.values[r.invocation - 1] = [];
}

critObject.values[r.invocation - 1][r.iteration - 1] = r.value;
critObject.values[r.invocation - 1] = r.values;
}
}

Expand Down
23 changes: 18 additions & 5 deletions src/frontend/plots.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import type { AllResults, PlotData, TimelineResponse } from '../shared/api.js';
import type {
AllResults,
CriterionWithoutData,
PlotData,
TimelineResponse,
ValuesPossiblyMissing
} from '../shared/api.js';
import type { Source } from '../backend/db/types.js';
import { filterCommitMessage } from './render.js';
import uPlot from '/static/uPlot.esm.min.js';
Expand Down Expand Up @@ -411,7 +417,7 @@ export function renderComparisonTimelinePlot(
/**
* Replace `0` with `null` to hide the point in the plot.
*/
function replaceZeroByNull(data: number[]): number[] {
function replaceZeroByNull(data: ValuesPossiblyMissing): ValuesPossiblyMissing {
for (let i = 0; i < data.length; i += 1) {
if (data[i] === 0) {
(<any[]>data)[i] = null;
Expand All @@ -423,7 +429,7 @@ function replaceZeroByNull(data: number[]): number[] {

function addSeries(
critData: WarmupDataPerCriterion,
data: number[][],
data: (ValuesPossiblyMissing | CriterionWithoutData)[],
series: any[],
commitId: string,
colors: readonly string[],
Expand All @@ -435,7 +441,14 @@ function addSeries(
'Do not yet know how to handle multiple.'
);
}
data.push(replaceZeroByNull(critData.values[0]));

const values = critData.values[0];

if (values === null) {
return 0;
}

data.push(replaceZeroByNull(values));

const style = styleMap[critData.criterion];

Expand All @@ -454,7 +467,7 @@ function addSeries(
cfg.points.fill = colors[style.colorIdx];
}

return critData.values[0].length;
return values.length;
}

function collectUnitsAndCriteria(data: WarmupDataForTrial[]): {
Expand Down
9 changes: 7 additions & 2 deletions src/shared/view-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { BenchmarkId, ProfileElement } from './api.js';
import type {
BenchmarkId,
CriterionWithoutData,
ProfileElement,
ValuesPossiblyMissing
} from './api.js';
import type {
CriterionData,
Environment,
Expand Down Expand Up @@ -247,7 +252,7 @@ export type CompareView = CompareViewWithoutData | CompareViewWithData;
export interface WarmupDataPerCriterion {
criterion: string;
unit: string;
values: number[][];
values: (ValuesPossiblyMissing | CriterionWithoutData)[];
}

export interface WarmupDataForTrial {
Expand Down

0 comments on commit 44554a1

Please sign in to comment.