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

misc(compare-runs): category scores, url filter, sort abs.val #10526

Merged
merged 24 commits into from
Apr 13, 2020

Conversation

connorjclark
Copy link
Collaborator

@connorjclark connorjclark commented Mar 30, 2020

More stuff for compare runs script (related: #10519)

@connorjclark connorjclark requested a review from a team as a code owner March 30, 2020 19:07
@connorjclark connorjclark requested review from exterkamp and removed request for a team March 30, 2020 19:07
Copy link
Member

@exterkamp exterkamp left a comment

Choose a reason for hiding this comment

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

LGTM with nits.

const lhr = JSON.parse(lhrJson);
const lhr = lhrJson && JSON.parse(lhrJson);
if (!lhr || !lhr.audits) {
console.warn(`could not parse ${lhrPath}`);
Copy link
Member

Choose a reason for hiding this comment

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

This isn't strictly true, if !lhr was false, but !lhr.audits was true, this just implies that there were no audits parsed. It still may have been parsed fine, might just not have audits. This error might not be specific enough to care the diff, but it is misleading.

const metrics = lhr.audits.metrics ?
if (argv.urlFilter && !lhr.requestedUrl.includes(argv.urlFilter)) continue;

const metrics = lhr.audits.metrics && lhr.audits.metrics.details ?
Copy link
Member

Choose a reason for hiding this comment

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

This is starting to get out of hand. && and a ternary in 1 assignment 😟

Am I too go-thonic to say

const metrics = {}
if (lhr.audits.metrics && lhr.audits.metrics.details) {
    metrics = /** @type {!LH.Audit.Details.Table} */ (lhr.audits.metrics.details).items[0];
}

Honestly curious if it's more readable one way or the other. I think once a ternary becomes complex at all it's time to separate it out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if only lhr.audits.metrics?.details ...

Am I too go-thonic to say

i think it's gooey :P I would prefer it if the ternary were more complex, but as it is it's just a nullability check.

categories: Object.values(lhr.categories).reduce((acc, cur) => {
acc.push([cur.id, (cur.score || 0) * 100]);
return acc;
}, /** @type {Array<[string, number]>} */ ([])),
Copy link
Member

Choose a reason for hiding this comment

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

Seems weird to output this as an array of strings and numbers? And not as a map of strings:numbers? Any reason to output like this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The allEntries object expects this format. Did you see how it's used in the following loop, L241?

The format comes naturally from Object.entries(metrics) -> Array<[kind: string, value: number]>

@connorjclark connorjclark changed the base branch from compare-runs-fixs to master April 8, 2020 03:15
@connorjclark connorjclark changed the title misc(compare-runs): category scores, url filter, sort by absolute value misc(compare-runs): category scores, url filter, sort abs.val Apr 13, 2020
@connorjclark connorjclark merged commit 49c5da5 into master Apr 13, 2020
@connorjclark connorjclark deleted the median-lhr branch April 13, 2020 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants