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

Report unmapped non-deprecated, standard keys #2222

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 78 additions & 39 deletions scripts/stats.ts
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,
Copy link
Collaborator

@Elchi3 Elchi3 Nov 13, 2024

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) but compatKeysUnmapped doesn't. I think this is a bit confusing.

Maybe we want to expose something like this?

currentBurndown: toDoKeys.length
compatKeysUnmapped: toDoKeys.length + deprecatedNonStandardKeys.length

Copy link
Collaborator Author

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 data
  • compatKeysUnmapped is toDoKeys.length + deprecatedNonStandardKeys.length
  • currentBurndownSize is the number of standard, non-deprecated keys left to map
  • currentBurndown is the array of standard, non-deprecated keys left to map

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));
}
}