Skip to content

Commit

Permalink
feat: continue
Browse files Browse the repository at this point in the history
  • Loading branch information
hrenaud committed Nov 28, 2023
1 parent 9d21207 commit a3d7761
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 174 deletions.
2 changes: 1 addition & 1 deletion examples/test-new-input/example-input-file.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"output-path": "./reports/multi",
"output-name": "ecoindex",
"parcours": [
"courses": [
{
"name": "Découvrir ecoindex et l'écoconception",
"urls": [
Expand Down
8 changes: 4 additions & 4 deletions lighthouse-plugin-ecoindex/cli/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ function getFlags(manualArgv, options = {}) {
cliFlags['listAllAudits'] = false

// Save results as reports.
cliFlags['reportName'] = new Date().toISOString()
cliFlags['generationDate'] = new Date().toISOString()

// Prepare statements reports name
if (!cliFlags['input-report']) {
cliFlags['input-report'] = []
}
// if (!cliFlags['input-report']) {
// cliFlags['input-report'] = []
// }

return cliFlags
}
Expand Down
89 changes: 73 additions & 16 deletions lighthouse-plugin-ecoindex/cli/converters.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import { getEcoIndexGrade } from 'ecoindex'

/**
* Convertion base
*/
const base = {
gesToKm: {
label:
Expand All @@ -8,26 +13,78 @@ const base = {
},
}

/**
* Convert GHGs (expressed in eqCo2) into kilometers traveled in a combustion-powered car
* @param number ges
* @returns number
*/
const gesToKm = ges => {
return ges * base.gesToKm.coef
}

const scoreToGrade = score => {
if (score >= 81) {
return 'A'
} else if (score >= 71) {
return 'B'
} else if (score >= 56) {
return 'C'
} else if (score >= 41) {
return 'D'
} else if (score >= 26) {
return 'E'
} else if (score >= 11) {
return 'F'
} else {
return 'G'
function convertCourseResults(flows, course) {
const obj = {
'course-name': course.name || 'not required',
'course-target': course.target || 'not required',
'course-description': course.course || 'not required',
summary: {},
pages: [],
}
// get pages
flows.steps.forEach(flow => {
// 3.1 Add page to course output
obj.pages.push(convertPagesResults(flow.lhr))
})
// calculate summary
obj.summary['eco-index-grade'] = getEcoIndexGrade(
obj.pages.reduce((a, audit) => a + audit['eco-index-score'], 0) /
obj.pages.length,
)
obj.summary['eco-index-score'] = Math.round(
obj.pages.reduce((a, audit) => a + audit['eco-index-score'], 0) /
obj.pages.length,
)
obj.summary['eco-index-water'] = (
(obj.pages.reduce((a, audit) => a + audit['eco-index-water'], 0) /
obj.pages.length) *
10
).toFixed(2)
obj.summary['eco-index-water-equivalent'] = Math.round(
((obj.pages.reduce((a, audit) => a + audit['eco-index-water'], 0) /
obj.pages.length) *
10) /
9,
)
obj.summary['eco-index-ghg'] = (
obj.pages.reduce((a, audit) => a + audit['eco-index-ghg'], 0) /
obj.pages.length
).toFixed(2)
obj.summary['eco-index-ghg-equivalent'] = Math.round(
gesToKm(
obj.pages.reduce((a, audit) => a + audit['eco-index-ghg'], 0) /
obj.pages.length,
),
)

return obj
}

function convertPagesResults(lhr) {
const audits = lhr.audits

return {
requestedUrl: lhr.requestedUrl,
'eco-index-grade': audits['eco-index-grade'].numericValue,
'eco-index-score': Math.round(
Number(audits['eco-index-score'].numericValue) * 100,
2,
),
'eco-index-ghg': Number(audits['eco-index-ghg'].numericValue),
'eco-index-water': Number(audits['eco-index-water'].numericValue),
'eco-index-nodes': Number(audits['eco-index-nodes'].numericValue),
'eco-index-size': Number(audits['eco-index-size'].numericValue),
'eco-index-requests': Number(audits['eco-index-requests'].numericValue),
}
}

export { gesToKm, scoreToGrade }
export { convertCourseResults }
Loading

0 comments on commit a3d7761

Please sign in to comment.