-
Notifications
You must be signed in to change notification settings - Fork 72
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
Report unmapped non-deprecated, standard keys #2222
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,82 @@ | ||
import { Compat } from "compute-baseline/browser-compat-data"; | ||
import { fileURLToPath } from "node:url"; | ||
import yargs from "yargs"; | ||
import { features } from "../index.js"; | ||
|
||
const featureCount = Object.keys(features).length; | ||
|
||
const keys = [...new Compat().walk()] | ||
.filter((f) => !f.id.startsWith("webextensions")) | ||
.map((f) => f.id).length; | ||
|
||
const compatKeys = Object.values(features).flatMap( | ||
(f) => f.compat_features ?? [], | ||
).length; | ||
|
||
const featureSizes = Object.values(features) | ||
.map((feature) => (feature.compat_features ?? []).length) | ||
.sort((a, b) => a - b); | ||
|
||
const stats = { | ||
features: featureCount, | ||
compatKeys, | ||
compatCoverage: compatKeys / keys, | ||
compatKeysPerFeatureMean: compatKeys / featureCount, | ||
compatKeysPerFeatureMedian: (() => { | ||
const sizes = featureSizes; | ||
const middle = Math.floor(sizes.length / 2); | ||
return sizes.length % 2 | ||
? sizes[middle] | ||
: (sizes[middle - 1] + sizes[middle]) / 2; | ||
})(), | ||
compatKeysPerFeatureMode: (() => { | ||
const frequencyMap = new Map<number, number>(); | ||
for (const size of featureSizes) { | ||
frequencyMap.set(size, (frequencyMap.get(size) ?? 0) + 1); | ||
const argv = yargs(process.argv.slice(2)) | ||
.scriptName("stats") | ||
.usage("$0", "Generate statistics") | ||
.option("verbose", { | ||
alias: "v", | ||
describe: "Show more detailed stats", | ||
type: "count", | ||
default: 0, | ||
}).argv; | ||
|
||
export function stats(detailed: boolean = false) { | ||
const featureCount = Object.keys(features).length; | ||
|
||
const keys = []; | ||
const doneKeys = Object.values(features).flatMap( | ||
(f) => f.compat_features ?? [], | ||
); | ||
const toDoKeys = []; | ||
const deprecatedNonStandardKeys = []; | ||
|
||
for (const f of new Compat().walk()) { | ||
if (!f.id.startsWith("webextensions")) { | ||
keys.push(f.id); | ||
|
||
if (!f.deprecated && f.standard_track) { | ||
if (!doneKeys.includes(f.id)) { | ||
toDoKeys.push(f.id); | ||
} | ||
} else { | ||
deprecatedNonStandardKeys.push(f.id); | ||
} | ||
} | ||
return [...frequencyMap.entries()] | ||
.sort( | ||
([sizeA, frequencyA], [sizeB, frequencyB]) => frequencyA - frequencyB, | ||
) | ||
.pop()[0]; | ||
})(), | ||
}; | ||
|
||
console.log(JSON.stringify(stats, undefined, 2)); | ||
} | ||
|
||
const featureSizes = Object.values(features) | ||
.map((feature) => (feature.compat_features ?? []).length) | ||
.sort((a, b) => a - b); | ||
|
||
const result = { | ||
features: featureCount, | ||
compatKeys: doneKeys.length, | ||
compatKeysUnmapped: toDoKeys.length, | ||
compatCoverage: doneKeys.length / keys.length, | ||
compatKeysPerFeatureMean: doneKeys.length / featureCount, | ||
compatKeysPerFeatureMedian: (() => { | ||
const sizes = featureSizes; | ||
const middle = Math.floor(sizes.length / 2); | ||
return sizes.length % 2 | ||
? sizes[middle] | ||
: (sizes[middle - 1] + sizes[middle]) / 2; | ||
})(), | ||
compatKeysPerFeatureMode: (() => { | ||
const frequencyMap = new Map<number, number>(); | ||
for (const size of featureSizes) { | ||
frequencyMap.set(size, (frequencyMap.get(size) ?? 0) + 1); | ||
} | ||
return [...frequencyMap.entries()] | ||
.sort( | ||
([sizeA, frequencyA], [sizeB, frequencyB]) => frequencyA - frequencyB, | ||
) | ||
.pop()[0]; | ||
})(), | ||
toBeMapped: undefined, | ||
}; | ||
|
||
if (detailed) { | ||
result.toBeMapped = toDoKeys; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
if (import.meta.url.startsWith("file:")) { | ||
if (process.argv[1] === fileURLToPath(import.meta.url)) { | ||
console.log(JSON.stringify(stats(argv.verbose), undefined, 2)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, there are two numbers for unmapped keys here:
(1)
toDoKeys.length
(2)
toDoKeys.length
+deprecatedNonStandardKeys.length
The current
compatCoverage
percentage takes into account (2) butcompatKeysUnmapped
doesn't. I think this is a bit confusing.Maybe we want to expose something like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is a good idea. I've changed this a bit based on your comment:
compatKeys
is what we have in the feature datacompatKeysUnmapped
istoDoKeys.length + deprecatedNonStandardKeys.length
currentBurndownSize
is the number of standard, non-deprecated keys left to mapcurrentBurndown
is the array of standard, non-deprecated keys left to map