Skip to content

Commit

Permalink
use LH v6 computeLogNormalScore
Browse files Browse the repository at this point in the history
  • Loading branch information
alekseykulikov committed May 26, 2020
1 parent 3141a83 commit fef6c16
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
12 changes: 7 additions & 5 deletions src/utils/audit-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ exports.getLoadingExperience = async (artifacts, context, isUrl = true) => {
*
* @param {MetricValue} metricValue
* @param {string} timeUnit
* @param {{ scorePODR: number, scoreMedian: number }} options
* @param {{ p10: number, median: number }} options
* @return {Object}
*/

exports.createValueResult = (metricValue, timeUnit, options) => {
let displayValue
const numericValue = metricValue.percentile
const score = Audit.computeLogNormalScore(numericValue, options.scorePODR, options.scoreMedian)
const score = Audit.computeLogNormalScore(options, numericValue)

if (isMs(timeUnit)) {
displayValue = `${formatValue(numericValue, { isMs: true })} ms`
Expand All @@ -69,7 +69,9 @@ exports.createValueResult = (metricValue, timeUnit, options) => {

return {
score,
scoreDisplayMode: 'numeric',
numericValue,
numericUnit: 'millisecond',
displayValue,
details: createDistributionsTable(metricValue, timeUnit),
}
Expand Down Expand Up @@ -135,11 +137,11 @@ function createDistributionsTable({ distributions }, timeUnit) {
const normMax = formatValue(max, { isMs: isMs(timeUnit) })

if (min === 0) {
item.category = `Fast (faster than ${normMax} ${timeUnit})`
item.category = `Good (faster than ${normMax} ${timeUnit})`
} else if (max && min === distributions[index - 1].max) {
item.category = `Average (from ${normMin} ${timeUnit} to ${normMax} ${timeUnit})`
item.category = `Needs improvement (from ${normMin} ${timeUnit} to ${normMax} ${timeUnit})`
} else {
item.category = `Slow (longer than ${normMin} ${timeUnit})`
item.category = `Poor (longer than ${normMin} ${timeUnit})`
}

item.distribution = `${(proportion * 100).toFixed()} %`
Expand Down
34 changes: 19 additions & 15 deletions test/snapshots/test/index.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1
{
description: 'First Contentful Paint marks the time at which the first text or image painted. The value represents the 90th percentile of the page traffic. [Learn More](https://developers.google.com/speed/docs/insights/v5/about#faq)',
description: 'First Contentful Paint marks the time at which the first text or image painted. The value represents the 75th percentile of the page traffic. [Learn More](https://developers.google.com/speed/docs/insights/v5/about#faq)',
id: 'field-fcp',
numericUnit: 'millisecond',
scoreDisplayMode: 'numeric',
title: 'First Contentful Paint (URL)',
}
Expand All @@ -32,13 +33,13 @@ Generated by [AVA](https://avajs.dev).
],
items: [
{
category: 'Fast (faster than 1 s)',
category: 'Good (faster than 1 s)',
},
{
category: 'Average (from 1 s to 3 s)',
category: 'Needs improvement (from 1 s to 3 s)',
},
{
category: 'Slow (longer than 3 s)',
category: 'Poor (longer than 3 s)',
},
],
type: 'table',
Expand All @@ -49,6 +50,7 @@ Generated by [AVA](https://avajs.dev).
{
description: 'First Input Delay indicates how fast UI responded after the first interaction. The value represents the 95th percentile of the page traffic. [Learn More](https://developers.google.com/speed/docs/insights/v5/about#faq)',
id: 'field-fid',
numericUnit: 'millisecond',
scoreDisplayMode: 'numeric',
title: 'First Input Delay (URL)',
}
Expand All @@ -70,13 +72,13 @@ Generated by [AVA](https://avajs.dev).
],
items: [
{
category: 'Fast (faster than 100 ms)',
category: 'Good (faster than 100 ms)',
},
{
category: 'Average (from 100 ms to 300 ms)',
category: 'Needs improvement (from 100 ms to 300 ms)',
},
{
category: 'Slow (longer than 300 ms)',
category: 'Poor (longer than 300 ms)',
},
],
type: 'table',
Expand All @@ -87,6 +89,7 @@ Generated by [AVA](https://avajs.dev).
{
description: 'First Contentful Paint marks the time at which the first text or image painted. The value represents the 90th percentile of all origin traffic. [Learn More](https://developers.google.com/speed/docs/insights/v5/about#faq)',
id: 'field-fcp-origin',
numericUnit: 'millisecond',
scoreDisplayMode: 'numeric',
title: 'First Contentful Paint (Origin)',
}
Expand All @@ -108,13 +111,13 @@ Generated by [AVA](https://avajs.dev).
],
items: [
{
category: 'Fast (faster than 1 s)',
category: 'Good (faster than 1 s)',
},
{
category: 'Average (from 1 s to 3 s)',
category: 'Needs improvement (from 1 s to 3 s)',
},
{
category: 'Slow (longer than 3 s)',
category: 'Poor (longer than 3 s)',
},
],
type: 'table',
Expand All @@ -125,6 +128,7 @@ Generated by [AVA](https://avajs.dev).
{
description: 'First Input Delay indicates how fast UI responded after the first interaction. The value represents the 95th percentile of all origin traffic. [Learn More](https://developers.google.com/speed/docs/insights/v5/about#faq)',
id: 'field-fid-origin',
numericUnit: 'millisecond',
scoreDisplayMode: 'numeric',
title: 'First Input Delay (Origin)',
}
Expand All @@ -146,13 +150,13 @@ Generated by [AVA](https://avajs.dev).
],
items: [
{
category: 'Fast (faster than 100 ms)',
category: 'Good (faster than 100 ms)',
},
{
category: 'Average (from 100 ms to 300 ms)',
category: 'Needs improvement (from 100 ms to 300 ms)',
},
{
category: 'Slow (longer than 300 ms)',
category: 'Poor (longer than 300 ms)',
},
],
type: 'table',
Expand Down Expand Up @@ -185,7 +189,7 @@ Generated by [AVA](https://avajs.dev).
],
description: 'These metrics show the performance of the page for real-world Chrome users over the last 30 days. Data is collected anonymously in the "field" and provided by Chrome UX Report. [Learn More](https://developers.google.com/web/tools/chrome-user-experience-report/)',
id: 'lighthouse-plugin-field-performance',
score: 0.74,
score: 0.83,
title: 'Field Performance',
}

Expand All @@ -194,7 +198,7 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1
{
description: 'First Contentful Paint marks the time at which the first text or image painted. The value represents the 90th percentile of the page traffic. [Learn More](https://developers.google.com/speed/docs/insights/v5/about#faq)',
description: 'First Contentful Paint marks the time at which the first text or image painted. The value represents the 75th percentile of the page traffic. [Learn More](https://developers.google.com/speed/docs/insights/v5/about#faq)',
explanation: `The Chrome User Experience Report ␊
does not have sufficient real-world First Contentful Paint (URL) data for this page.`,
id: 'field-fcp',
Expand Down
Binary file modified test/snapshots/test/index.js.snap
Binary file not shown.

0 comments on commit fef6c16

Please sign in to comment.