-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add data statistics script for MDN 2019 key result goal #3557
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b94373b
Add data statistics script
Elchi3 e5701ee
Rename file
Elchi3 4cdbc51
Fix th labels
Elchi3 33f063a
Properly iterate into support
Elchi3 56c7eec
Update checkSupport semantics again
Elchi3 8cd9d5b
Simplify checkSupport as suggested by foolip
Elchi3 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
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
'use strict'; | ||
const bcd = require('..'); | ||
|
||
const browsers = ['chrome', 'chrome_android', 'edge', 'firefox', 'ie', 'safari', 'safari_ios', 'webview_android']; | ||
let stats = { total: { all: 0, true: 0, null: 0, real: 0 } }; | ||
browsers.forEach(browser => { | ||
stats[browser] = { all: 0, true: 0, null: 0, real: 0 } | ||
}); | ||
|
||
const checkSupport = (supportData, type) => { | ||
if (!Array.isArray(supportData)) { | ||
supportData = [supportData]; | ||
} | ||
return supportData.some(item => item.version_added === type || item.version_removed === type) | ||
}; | ||
|
||
const processData = (data) => { | ||
if (data.support) { | ||
browsers.forEach(function(browser) { | ||
stats[browser].all++; | ||
stats.total.all++; | ||
let real_value = true; | ||
if (!data.support[browser]) { | ||
stats[browser].null++; | ||
stats.total.null++; | ||
real_value = false; | ||
} else { | ||
if (checkSupport(data.support[browser], null)) { | ||
stats[browser].null++; | ||
stats.total.null++; | ||
real_value = false; | ||
} | ||
if (checkSupport(data.support[browser], true)) { | ||
stats[browser].true++; | ||
stats.total.true++; | ||
real_value = false; | ||
} | ||
} | ||
if (real_value) { | ||
stats[browser].real++; | ||
stats.total.real++; | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
const iterateData = (data) => { | ||
for (let key in data) { | ||
if (key === '__compat') { | ||
processData(data[key]); | ||
} else { | ||
iterateData(data[key]); | ||
} | ||
} | ||
}; | ||
|
||
for (let data in bcd) { | ||
if (!(data === 'browsers' || data === 'webextensions')) { | ||
iterateData(bcd[data]); | ||
} | ||
} | ||
|
||
const printTable = () => { | ||
let table = `| browser | real values | \`true\` values | \`null\` values | | ||
| --- | --- | --- | --- | | ||
`; | ||
|
||
Object.keys(stats).forEach(entry => { | ||
table += `| ${entry.replace('_', ' ')} | `; | ||
table += `${((stats[entry].real / stats[entry].all) * 100).toFixed(2)}% | `; | ||
table += `${((stats[entry].true / stats[entry].all) * 100).toFixed(2)}% | `; | ||
table += `${((stats[entry].null / stats[entry].all) * 100).toFixed(2)}% | | ||
`; | ||
}); | ||
|
||
console.log(table); | ||
} | ||
|
||
console.log('Status as of version 0.0.xx (released on xx/xx/2019) for web platform features: \n') | ||
printTable(); |
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.
Note that this will also traverse into strings and arrays, with
key
being 0, 1, 2 and so on.processData
will get called with 1-char strings as arguments and do nothing. This is pretty harmless, just something I was bitten by when writing very similar code with different conditions inprocessData
.