Display first run data on pageSummary. (#2886)

This commit is contained in:
Peter Hedenskog 2020-02-21 22:52:09 +01:00 committed by GitHub
parent b1d40bec16
commit c4e1ac6169
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 30 deletions

View File

@ -19,6 +19,7 @@ module.exports = {
'utf8'
);
this.aggregator = new Aggregator(options);
this.firstRunsData = {};
context.filterRegistry.registerFilterForType(
DEFAULT_METRICS_PAGE_SUMMARY,
'sustainable.pageSummary'
@ -96,6 +97,13 @@ module.exports = {
? this.sustainableOptions.pageViews * co2PerPageView
: co2PerPageView;
if (message.iteration === 1) {
this.firstRunsData[message.url] = {
co2PerDomain,
hostingGreenCheck,
dirtiestResources
};
}
// We get data per run, so we want to aggregate that per page (multiple runs per page)
// and per group/domain
aggregator.addStats(
@ -139,6 +147,8 @@ module.exports = {
// and push that info on the queue
const summaries = aggregator.summarize();
for (let summary of summaries) {
const extras = this.firstRunsData[summary.url];
summary.data.firstRun = extras;
queue.postMessage(
make(
'sustainable.pageSummary',

View File

@ -1,6 +1,6 @@
h1 Sustainable Web
- const sustainable = pageInfo.data.sustainable.run ? pageInfo.data.sustainable.run : pageInfo.data.sustainable.pageSummary
- let sustainable = pageInfo.data.sustainable.run ? pageInfo.data.sustainable.run : pageInfo.data.sustainable.pageSummary
p Sending data over the wire uses electricity, and because the internet still mostly runs on fossil fuels, the more data we send, the more fossil fuels we burn, which is bad news for our climate.
@ -44,36 +44,40 @@ table
td #{options.sustainable.pageViews} page views
td #{(sustainable.totalCO2.median/1000) || Number(sustainable.totalCO2/1000).toFixed(3)} kg
if sustainable.co2PerDomain
h2 Per domain
table(data-sortable)
thead
tr
th Domain
th Estimated CO2 emissions
th Transfer Size
each data in sustainable.co2PerDomain
tr
td #{data.domain}
- if (sustainable.hostingGreenCheck.indexOf(data.domain) > -1)
span(class='label normal ok') green
td.number(data-value= data.co2)= data.co2
td.number(data-value= data.transferSize)= h.size.format(data.transferSize)
- sustainable = pageInfo.data.sustainable.pageSummary ? pageInfo.data.sustainable.pageSummary.firstRun : sustainable
if sustainable.dirtiestResources
h2 Dirtiest assets
table(data-sortable)
thead
tr
th Asset
th Estimated CO2 emissions
th Transfer Size
each resource in sustainable.dirtiestResources
tr
td.url.assetsurl(data-title='URL')
a(href=resource.url)= h.shortAsset(resource.url)
td.number= resource.co2
td.number= h.size.format(resource.transferSize)
h2 Per domain
if pageInfo.data.sustainable.pageSummary
| (first run)
table(data-sortable)
thead
tr
th Domain
th Estimated CO2 emissions
th Transfer Size
each data in sustainable.co2PerDomain
tr
td #{data.domain}
- if (sustainable.hostingGreenCheck.indexOf(data.domain) > -1)
span(class='label normal ok') green
td.number(data-value= data.co2)= data.co2
td.number(data-value= data.transferSize)= h.size.format(data.transferSize)
h2 Dirtiest assets
if pageInfo.data.sustainable.pageSummary
| (first run)
table(data-sortable)
thead
tr
th Asset
th Estimated CO2 emissions
th Transfer Size
each resource in sustainable.dirtiestResources
tr
td.url.assetsurl(data-title='URL')
a(href=resource.url)= h.shortAsset(resource.url)
td.number= resource.co2
td.number= h.size.format(resource.transferSize)