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

Fix invalid versions by skipping over them #16

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Changes from 1 commit
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
32 changes: 22 additions & 10 deletions app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,16 @@ export function groupByMajor(downloads: DownloadsResponse['downloads']) {
let groups: Record<number, number> = {};

for (let [version, downloadCount] of Object.entries(downloads)) {
let major = getMajor(version);

groups[major] ||= 0;
groups[major] += downloadCount;
try {
let major = getMajor(version);

groups[major] ||= 0;
groups[major] += downloadCount;
} catch (e) {
console.group(`An error occurred and ${version} will be omitted from the dataset`);
console.error(e);
console.groupEnd();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

this works fine, but you could also use Semver.isValid() instead of try/catch.

Copy link
Owner Author

Choose a reason for hiding this comment

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

that's a good point -- would probably allow for less verbose output, too

}

return Object.entries(groups).map(([major, downloadCount]) => {
Expand All @@ -73,12 +79,18 @@ export function groupByMinor(downloads: DownloadsResponse['downloads']): Grouped
let groups: Record<string, number> = {};

for (let [version, downloadCount] of Object.entries(downloads)) {
let major = getMajor(version);
let minor = getMinor(version);
let majorMinor = `${major}.${minor}`;

groups[majorMinor] ||= 0;
groups[majorMinor] += downloadCount;
try {
let major = getMajor(version);
let minor = getMinor(version);
let majorMinor = `${major}.${minor}`;

groups[majorMinor] ||= 0;
groups[majorMinor] += downloadCount;
} catch (e) {
console.group(`An error occurred and ${version} will be omitted from the dataset`);
console.error(e);
console.groupEnd();
}
}

return Object.entries(groups).map(([majorMinor, downloadCount]) => {
Expand Down
Loading