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() + +} +