Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(lhr): make reportCategories shallow; move audit scores to AuditResultJSON #4711

Merged
merged 11 commits into from
Mar 13, 2018

Conversation

paulirish
Copy link
Member

@paulirish paulirish commented Mar 7, 2018

Changes

  • reportCategories no longer contains real auditResults (aka de-dupe all audit results from ☂️ 👣 Things to fix on next breaking change #4333)
    • The categories still keep their .score prop. Eg: reportCategories.performance.score
    • Each audit's score moves from reportCategories.performance['audit-name'] (which now just holds weight and group) over to audits['audit-name']
  • Remove LHR.score, the overallScore

This is a chain of PRs. Landing order is... 1st: newdetails (#4616). 2nd: shallowCategories (#4711). 3rd: scoring2.0 (#4690)

ref #4614

fixes #1999

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! let's keep this chain amovin' we've got lots of #4333 to land :D

if (opts.config.categories) {
report = Runner._scoreAndCategorize(opts, resultsById);
Runner._scoreAndCategorize(opts, resultsById);
// COMPAT: after dropping Node 6, upgrade to use Object.values
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this mean we can do it now? :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do it!

const category = config.categories[categoryId];
category.id = categoryId;

const audits = category.audits.map(audit => {
category.audits.forEach(audit => {
const result = resultsByAuditId[audit.id];
// Cast to number to catch `null` and undefined when audits error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should all of these line just be moved into audit.js then to keep all the score mapping in the same place?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more a comment for #4690 I suppose

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brendankenny
Copy link
Member

smokehouse failures?

@brendankenny brendankenny changed the title core(lhr): make reportCategories shallow. move score to AuditResultJSON core(lhr): make reportCategories shallow. move audit scores to AuditResultJSON Mar 9, 2018
@brendankenny brendankenny changed the title core(lhr): make reportCategories shallow. move audit scores to AuditResultJSON core(lhr): make reportCategories shallow; move audit scores to AuditResultJSON Mar 9, 2018
Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is looking good to me so far. As discussed, we'll want to smoosh the audit results into a copy of the LHR so the canonical one still exists untouched.

something for the future: as we add more typechecking, we may want to split AuditJSON to a version with result (only used inside the report renderer) and a version without (used everywhere else) so that we can more easily reason about which we have at some point in time and so we don’t have to put in a bunch of checks to keep tsc happy :)

if (opts.config.categories) {
report = Runner._scoreAndCategorize(opts, resultsById);
Runner._scoreAndCategorize(opts, resultsById);
// COMPAT: after dropping Node 6, upgrade to use Object.values
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do it!

@paulirish
Copy link
Member Author

As discussed, we'll want to smoosh the audit results into a copy of the LHR so the canonical one still exists untouched.

Done. added a test.

something for the future: as we add more typechecking, we may want to split AuditJSON to a version with result (only used inside the report renderer) and a version without (used everywhere else) so that we can more easily reason about which we have at some point in time and so we don’t have to put in a bunch of checks to keep tsc happy :)

YESSSSSSS. So want this.

Here was my typechecking spike, validating the outgoing LHR against some real types. Works! 95e19a5...typechecking


This and #4690 are updated and ready

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's get this show on the 🚗 💨

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just the merge issue and two questions remaining 🌊➡️🛁

@@ -155,24 +157,39 @@ class ReportRenderer {
perfCategoryRenderer.setTemplateContext(this._templateContext);

const categories = reportSection.appendChild(this._dom.createElement('div', 'lh-categories'));

ReportRenderer.smooshAuditResultsIntoCategories(report.audits, report.reportCategories);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this make more sense up in renderReport before passing into _renderReport? Then internally it'll always be the smooshed version and we won't have to remember not to use reportCategories above this line

* result: (ReportRenderer.AuditResultJSON|undefined)
* }}
*/
ReportRenderer.AuditJSON; // eslint-disable-line no-unused-expressions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defined below (merge conflict, I think)

@@ -108,8 +109,7 @@ class Runner {
audits: resultsById,
artifacts: runResults.artifacts,
runtimeConfig: Runner.getRuntimeConfig(opts.flags),
score: report ? report.score : 0,
reportCategories: report ? report.categories : [],
reportCategories: categories,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before this defaulted to an empty array. Will it cause problems anywhere as undefined (and removed from the JSON) instead?

* @param {!Object<string, {score: ?number|boolean|undefined, notApplicable: boolean, informative: boolean}>} resultsByAuditId
* @return {{score: number, categories: !Array<{audits: !Array<{score: number, result: !Object}>}>}}
*/
static scoreAllCategories(config, resultsByAuditId) {
const categories = Object.keys(config.categories).map(categoryId => {
const category = config.categories[categoryId];
for (const [categoryId, category] of Object.entries(config.categories)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@paulirish
Copy link
Member Author

merge when green.

@paulirish paulirish merged commit 4d5696d into master Mar 13, 2018
@paulirish paulirish deleted the shallowCategories branch April 27, 2018 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reduce size of JSON results: remove duplication
4 participants