Skip to content

Commit

Permalink
Fix system shape
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jan 2, 2022
1 parent 7a1df0f commit 3cd831e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
10 changes: 5 additions & 5 deletions src/history/normalize/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import mapObj from 'map-obj'
// We try to persist everything, so that `show` report the same information.
// We try to only persist what cannot be computed runtime.
export const compressRawResult = function (rawResult) {
const system = compressSystem(rawResult.system)
const system = compressSystem(rawResult.systems)
const combinations = rawResult.combinations.map((combination) =>
compressCombination({ combination }),
)
return { ...rawResult, system, combinations }
}

const compressSystem = function ({ dimensions, ...system }) {
const compressSystem = function ([{ dimensions, ...system }]) {
return Object.keys(dimensions).length === 0
? system
: { dimensions, ...system }
Expand Down Expand Up @@ -53,15 +53,15 @@ const compressBucket = function ({ start, end, frequency }, mean) {

// Restore original rawResults after loading
export const decompressRawResult = function (rawResult) {
const system = decompressSystem(rawResult.system)
const systems = decompressSystem(rawResult.system)
const combinations = rawResult.combinations.map((combination) =>
decompressCombination({ combination }),
)
return { ...rawResult, system, combinations }
return { ...rawResult, systems, combinations }
}

const decompressSystem = function ({ dimensions = {}, ...system }) {
return { ...system, dimensions }
return [{ ...system, dimensions }]
}

const decompressCombination = function ({
Expand Down
3 changes: 1 addition & 2 deletions src/history/normalize/load.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import sortOn from 'sort-on'

import { selectRawResults } from '../../select/main.js'
import { normalizeSystems } from '../../system/merge.js'

import { decompressRawResult } from './compress.js'
import { migrateRawResults } from './migrate.js'

// Normalize rawResults on load
export const loadRawResults = function (rawResults, select) {
const rawResultsA = migrateRawResults(rawResults)
const rawResultsB = rawResultsA.map(decompressRawResult).map(normalizeSystems)
const rawResultsB = rawResultsA.map(decompressRawResult)
const rawResultsC = selectRawResults(rawResultsB, select)
const rawResultsD = sortResults(rawResultsC)
return rawResultsD
Expand Down
7 changes: 5 additions & 2 deletions src/run/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { createSystemInfo } from '../system/create/main.js'
export const createResult = async function (config) {
const combinations = await listCombinations(config)
const previous = await listHistory(config)
const { id, timestamp, system } = await createSystemInfo(combinations, config)
const rawResult = { id, timestamp, system, combinations }
const { id, timestamp, systems } = await createSystemInfo(
combinations,
config,
)
const rawResult = { id, timestamp, systems, combinations }
return { rawResult, previous }
}
12 changes: 6 additions & 6 deletions src/system/create/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import { getSystemVersions } from './versions.js'
// All that information are automatically computed.
// The `versions` are computed by runners.
// A result can only have a single `system`. However, when merging results,
// this becomes several `systems`. We persist the `systems` array directly so
// that all results have the same shape in both our logic and reporters' logic.
// this becomes several `systems`.
// We purposely keep the data as raw as possible to give flexibility to the
// reporters on how to serialize it
// - For example, this allows changing the reporting without changing the
Expand Down Expand Up @@ -49,15 +48,16 @@ export const createSystemInfo = async function (
) {
const id = uuidv4()
const timestamp = getTimestamp()
const system = await getSystem({ dimensions, envInfo, combinations, cwd })
return { id, timestamp, system }
const systems = await getSystems({ dimensions, envInfo, combinations, cwd })
return { id, timestamp, systems }
}

const getSystem = async function ({ dimensions, combinations, cwd }) {
const getSystems = async function ({ dimensions, combinations, cwd }) {
const versions = await getSystemVersions(combinations, cwd)
const machine = getMachine()
const { git, ci } = getEnvInfo(cwd)
return cleanObject({ dimensions, machine, git, ci, versions })
const system = cleanObject({ dimensions, machine, git, ci, versions })
return [system]
}

const getMachine = function () {
Expand Down
4 changes: 0 additions & 4 deletions src/system/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import { setArray } from '../utils/set.js'
// `system` objects should not contain `undefined`, so we can directly merge.
// `git` and `machine` properties should not be deeply merged since their
// properties relate to each other. However, `versions` should.
export const normalizeSystems = function ({ system, ...rawResult }) {
return { ...rawResult, systems: [system] }
}

export const mergeSystems = function (result, previousResult) {
const systems = appendSystem(result, previousResult)
return { ...result, systems }
Expand Down

0 comments on commit 3cd831e

Please sign in to comment.