Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 12, 2021
1 parent f25f91d commit e307036
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/history/normalize/compress.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import mapObj from 'map-obj'

// Reduce size of results before saving
// We try to persist everything, so that `show` report the same information.
// We try to only persist what cannot be computed runtime.
Expand All @@ -11,24 +13,25 @@ export const compressResult = function ({ combinations, ...result }) {
const compressCombination = function ({
combination,
combination: {
dimensions: {
task: { id: task },
runner: { id: runner },
system: { id: system },
},
dimensions,
stats,
stats: { histogram, quantiles, mean },
},
}) {
const dimensionsA = mapObj(dimensions, compressDimension)
const histogramA = compressHistogram(histogram, mean)
const quantilesA = compressQuantiles(quantiles, mean)
return {
...combination,
dimensions: { task, runner, system },
dimensions: dimensionsA,
stats: { ...stats, histogram: histogramA, quantiles: quantilesA },
}
}

const compressDimension = function (dimension, { id }) {
return [dimension, id]
}

const compressHistogram = function (histogram, mean) {
return histogram.map((bucket) => compressBucket(bucket, mean))
}
Expand All @@ -52,24 +55,25 @@ export const decompressResult = function (result) {
const decompressCombination = function ({
combination,
combination: {
dimensions: { task, runner, system },
dimensions,
stats,
stats: { histogram, quantiles, mean },
},
}) {
const dimensionsA = mapObj(dimensions, decompressDimension)
const histogramA = decompressHistogram(histogram, mean)
const quantilesA = decompressQuantiles(quantiles, mean)
return {
...combination,
dimensions: {
task: { id: task },
runner: { id: runner },
system: { id: system },
},
dimensions: dimensionsA,
stats: { ...stats, histogram: histogramA, quantiles: quantilesA },
}
}

const decompressDimension = function (dimension, id) {
return [dimension, { id }]
}

const decompressHistogram = function (histogram, mean) {
return histogram === undefined
? undefined
Expand Down

0 comments on commit e307036

Please sign in to comment.