Skip to content

Commit

Permalink
feat: updated result parsing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Perrotte committed Nov 6, 2019
1 parent 39c555a commit 9c193b0
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions lib/parse-result.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const dedent = require('dedent')
const prettyMs = require('pretty-ms')

module.exports = function parseResults (latestResults, currentResults) {
const message = dedent`
Expand All @@ -16,7 +17,7 @@ module.exports = function parseResults (latestResults, currentResults) {
</tr>
</thead>
<tbody>
${resultRows(latestResults, currentResults)}
${resultRowsScenario(latestResults, currentResults)}
</tbody>
</table>
`
Expand Down Expand Up @@ -50,21 +51,35 @@ function subTableHeader (results) {
.join('\n')
}

function resultRows (latest, current) {
function resultRowsScenario (latest, current) {
const scenarioKeys = Object.keys(current)
const fixtureKeys = Object.keys(current[scenarioKeys[0]])
return scenarioKeys
.map((scenarioKey) => dedent`
<tr>
<td>${scenarioKey}</td>
${fixtureKeys.map((fixtureKey) => dedent`
<td>${latest[scenarioKey][fixtureKey] / 1000}s</td>
<td>${current[scenarioKey][fixtureKey] / 1000}s</td>
`).join('\n')}
${resultRowFixtures(latest, current, scenarioKey, fixtureKeys)}
</tr>
`)
.join('\n')
}

// style="color: #00B200" // green
// style="color: #A00000" // red
function resultRowFixtures (latest, current, scenarioKey, fixtureKeys) {
return fixtureKeys
.map((fixtureKey) => {
const latestValue = latest[scenarioKey][fixtureKey]
const currentValue = current[scenarioKey][fixtureKey]
return dedent`
<td>${prettyMs(latestValue)}</td>
${colorResult(latestValue, currentValue)}
`
})
.join('\n')
}

function colorResult (latest, current) {
const color = (current <= latest)
? '#00B200'
: '#A00000'
return `<td style="color: ${color}">${prettyMs(current)}</td>`
}

0 comments on commit 9c193b0

Please sign in to comment.