"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const getCaseResult_1 = require("./getCaseResult");
const getSummary = (event) => {
    const currentTarget = event.currentTarget;
    const results = Object.entries(currentTarget)
        .filter(([key]) => !Number.isNaN(Number(key)))
        .map(([_, target]) => getCaseResult_1.default(target));
    const fastestIndex = results.reduce((prev, next, index) => {
        return next.ops > prev.ops ? { ops: next.ops, index } : prev;
    }, { ops: 0, index: 0 }).index;
    const slowestIndex = results.reduce((prev, next, index) => {
        return next.ops < prev.ops ? { ops: next.ops, index } : prev;
    }, { ops: Infinity, index: 0 }).index;
    const resultsWithDiffs = results.map((result, index) => {
        const percentSlower = index === fastestIndex
            ? 0
            : Number(((1 - result.ops / results[fastestIndex].ops) * 100).toFixed(2));
        return Object.assign(Object.assign({}, result), { percentSlower });
    });
    return {
        name: event.currentTarget.name,
        date: new Date(event.timeStamp),
        results: resultsWithDiffs,
        fastest: {
            name: results[fastestIndex].name,
            index: fastestIndex,
        },
        slowest: {
            name: results[slowestIndex].name,
            index: slowestIndex,
        },
    };
};
exports.default = getSummary;
