From 4f0853bab2925f9086e993742ef8193466b9140f Mon Sep 17 00:00:00 2001 From: Ludek Novy <13610612+ludeknovy@users.noreply.github.com> Date: Fri, 8 Sep 2023 11:23:32 +0200 Subject: [PATCH] fix: scenario trends label order (#259) --- .../trends/get-scenario-trends-controller.ts | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/server/controllers/scenario/trends/get-scenario-trends-controller.ts b/src/server/controllers/scenario/trends/get-scenario-trends-controller.ts index 683914e6..93f3c30e 100644 --- a/src/server/controllers/scenario/trends/get-scenario-trends-controller.ts +++ b/src/server/controllers/scenario/trends/get-scenario-trends-controller.ts @@ -18,13 +18,16 @@ export const getScenarioTrendsController = async (req: IGetUserAuthInfoRequest, const responseTimeDegradationCurve = await db.manyOrNone( searchResponseTimeDegradation(projectName, scenarioName, envChecked)) - const labelTrends = labelData.map(data => data.stats.map(value => ({ - percentile90: [data.startDate, value.n0, data.id], - errorRate: [data.startDate, value.errorRate, data.id], - throughput: [data.startDate, value.throughput, data.id], - label: value.label, - }))) + labelData.sort(sortByDateAsc) + const labelTrends = labelData.map(data => data.stats.map(value => { + return { + percentile90: [data.startDate, value.n0, data.id], + errorRate: [data.startDate, value.errorRate, data.id], + throughput: [data.startDate, value.throughput, data.id], + label: value.label, + } + })) const adjusted = {} @@ -39,6 +42,7 @@ export const getScenarioTrendsController = async (req: IGetUserAuthInfoRequest, }) }) + const networkAdjustedData = aggregatedData.map((_) => { const { bytesPerSecond, bytesSentPerSecond } = _.overview const network = bytesPerSecond + bytesSentPerSecond @@ -66,7 +70,7 @@ export const getScenarioTrendsController = async (req: IGetUserAuthInfoRequest, }) res.status(StatusCode.Ok).json({ - aggregatedTrends: networkAdjustedData.sort(sortByDateAsc), + aggregatedTrends: networkAdjustedData.sort(sortAggDataByDateAsc), responseTimeDegradationCurve: responseTimeDegradationCurveSeries, labelTrends: adjusted, userSettings: { @@ -80,7 +84,12 @@ export const getScenarioTrendsController = async (req: IGetUserAuthInfoRequest, }) } -const sortByDateAsc = (a, b): number => { +const sortAggDataByDateAsc = (a, b): number => { return new Date(a.overview.startDate).getTime() - new Date(b.overview.startDate).getTime() } +const sortByDateAsc = (a, b): number => { + return new Date(a.startDate).getTime() - new Date(b.startDate).getTime() + +} +