Skip to content

Commit

Permalink
Show total time not cumulative time
Browse files Browse the repository at this point in the history
  • Loading branch information
danmindru committed Dec 1, 2023
1 parent afd2412 commit b264a3b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/share/pages/share/[result].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export async function getServerSideProps(context: {

const gql = parsed.item?.properties?.gql;
const stats = parsed.item?.latestResult.logs
? getLogStats(parsed.item.latestResult.logs)
? getLogStats(parsed.item.latestResult.logs, parsed.item.latestResult)
: [];

if (!parsed.item) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/results/ResultStats/ResultStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const getResultStats = (result: ClobbrUIResult) => {
return null;
}

return getLogStats(result.logs);
return getLogStats(result.logs, result);
};

export const ResultStats = ({
Expand Down
20 changes: 17 additions & 3 deletions packages/ui/src/shared/util/getLogStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { mathUtils } from '@clobbr/api';
import { formatNumber } from 'shared/util/numberFormat';
import { getDurationColorClass } from 'shared/util/getDurationColorClass';
import { isNumber } from 'lodash-es';
import { ClobbrUIResult } from 'models/ClobbrUIResult';

const { mean, q5, q95, q99, stdDev } = mathUtils;

Expand All @@ -18,14 +19,27 @@ export const RESULT_STAT_TYPES: {
TOTAL_TIME: 'Total time (s)'
};

export const getLogStats = (logs: Array<ClobbrLogItem>) => {
export const getLogStats = (
logs: Array<ClobbrLogItem>,
result: ClobbrUIResult
) => {
const qualifiedDurations = logs
.filter((log) => !log.failed)
.filter((log) => isNumber(log.metas.duration))
.map((log) => log.metas.duration as number);

const totalDuration = qualifiedDurations.reduce((acc, curr) => acc + curr, 0);
const startUnixTime = result.startDate
? new Date(result.startDate).valueOf()
: 0;
const endUnixTime = result.endDate ? new Date(result.endDate).valueOf() : 0;
const totalDuration = startUnixTime ? endUnixTime - startUnixTime : 0;
const totalDurationInSeconds = totalDuration / 1000;

const cumulativeDuration = qualifiedDurations.reduce(
(acc, curr) => acc + curr,
0
);
const cumulativeDurationInSeconds = cumulativeDuration / 1000;
const meanValue = mean(qualifiedDurations);
const stdDevValue = stdDev(qualifiedDurations);
const q5Value = q5(qualifiedDurations);
Expand Down Expand Up @@ -64,7 +78,7 @@ export const getLogStats = (logs: Array<ClobbrLogItem>) => {
colorClass: getDurationColorClass(q99Value)
},
{
value: formatNumber(totalDurationInSeconds),
value: formatNumber(totalDurationInSeconds, 1),
unit: 's',
label: 'Total time',
colorClass: getDurationColorClass(0) // Always green
Expand Down

0 comments on commit b264a3b

Please sign in to comment.