From b94373b0c53cc15cd288e72715fd06c0ee287274 Mon Sep 17 00:00:00 2001 From: Florian Scholz Date: Sun, 3 Mar 2019 17:08:29 +0100 Subject: [PATCH 1/6] Add data statistics script --- package.json | 1 + scripts/data-statistics.js | 73 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 scripts/data-statistics.js diff --git a/package.json b/package.json index db840947348369..00f785204975bb 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "scripts": { "confluence": "node ./node_modules/mdn-confluence/main/generate.es6.js --output-dir=. --bcd-module=./index.js", "lint": "node test/lint", + "data-stats": "node scripts/data-statistics", "release-notes": "node scripts/release-notes", "render": "node scripts/render", "show-errors": "npm test 1> /dev/null", diff --git a/scripts/data-statistics.js b/scripts/data-statistics.js new file mode 100644 index 00000000000000..9a26c0717525e1 --- /dev/null +++ b/scripts/data-statistics.js @@ -0,0 +1,73 @@ +'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 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 (JSON.stringify(data.support[browser]).includes('null')) { + stats[browser].null++; + stats.total.null++; + real_value = false; + } + if (JSON.stringify(data.support[browser]).includes('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(); From e5701ee7e89a2375c76e8aef723822e03dbb02fe Mon Sep 17 00:00:00 2001 From: Florian Scholz Date: Tue, 5 Mar 2019 12:23:36 +0100 Subject: [PATCH 2/6] Rename file --- package.json | 2 +- scripts/{data-statistics.js => statistics.js} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename scripts/{data-statistics.js => statistics.js} (100%) diff --git a/package.json b/package.json index 00f785204975bb..ce23493dab48f4 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "scripts": { "confluence": "node ./node_modules/mdn-confluence/main/generate.es6.js --output-dir=. --bcd-module=./index.js", "lint": "node test/lint", - "data-stats": "node scripts/data-statistics", + "stats": "node scripts/statistics", "release-notes": "node scripts/release-notes", "render": "node scripts/render", "show-errors": "npm test 1> /dev/null", diff --git a/scripts/data-statistics.js b/scripts/statistics.js similarity index 100% rename from scripts/data-statistics.js rename to scripts/statistics.js From 4cdbc51b68d572c0ed3a57facad185cec9c22ce6 Mon Sep 17 00:00:00 2001 From: Florian Scholz Date: Tue, 5 Mar 2019 12:25:33 +0100 Subject: [PATCH 3/6] Fix th labels --- scripts/statistics.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/statistics.js b/scripts/statistics.js index 9a26c0717525e1..7eab950ee19676 100644 --- a/scripts/statistics.js +++ b/scripts/statistics.js @@ -54,7 +54,7 @@ for (let data in bcd) { } const printTable = () => { - let table = `| browser | real values | true values | null values | + let table = `| browser | real values | \`true\` values | \`null\` values | | --- | --- | --- | --- | `; From 33f063aab307d9078321425254efc46871e9dcba Mon Sep 17 00:00:00 2001 From: Florian Scholz Date: Tue, 5 Mar 2019 13:10:16 +0100 Subject: [PATCH 4/6] Properly iterate into support --- scripts/statistics.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/statistics.js b/scripts/statistics.js index 7eab950ee19676..7f1af162cfc089 100644 --- a/scripts/statistics.js +++ b/scripts/statistics.js @@ -7,6 +7,18 @@ browsers.forEach(browser => { stats[browser] = { all: 0, true: 0, null: 0, real: 0 } }); +const checkSupport = (supportData, type) => { + if (Array.isArray(supportData)) { + supportData.forEach(item => { + if (item.version_added === type || item.version_removed === type) { + return true; + } + }); + } else if (supportData.version_added === type || supportData.version_removed === type) { + return true; + } +} + const processData = (data) => { if (data.support) { browsers.forEach(function(browser) { @@ -18,12 +30,12 @@ const processData = (data) => { stats.total.null++; real_value = false; } else { - if (JSON.stringify(data.support[browser]).includes('null')) { + if (checkSupport(data.support[browser], null)) { stats[browser].null++; stats.total.null++; real_value = false; } - if (JSON.stringify(data.support[browser]).includes('true')) { + if (checkSupport(data.support[browser], true)) { stats[browser].true++; stats.total.true++; real_value = false; From 56c7eeccb881e6edaf320bfa62746838379a237c Mon Sep 17 00:00:00 2001 From: Florian Scholz Date: Wed, 6 Mar 2019 14:35:33 +0100 Subject: [PATCH 5/6] Update checkSupport semantics again --- scripts/statistics.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/scripts/statistics.js b/scripts/statistics.js index 7f1af162cfc089..2d353f71e47c17 100644 --- a/scripts/statistics.js +++ b/scripts/statistics.js @@ -8,16 +8,19 @@ browsers.forEach(browser => { }); const checkSupport = (supportData, type) => { - if (Array.isArray(supportData)) { - supportData.forEach(item => { - if (item.version_added === type || item.version_removed === type) { - return true; - } - }); - } else if (supportData.version_added === type || supportData.version_removed === type) { - return true; - } -} + let foundType = false; + if (Array.isArray(supportData)) { + supportData.forEach(item => { + // if 'type' occurs once in the array, mark it as found + if (item.version_added === type || item.version_removed === type) { + foundType = true; + } + }); + } else { + foundType = (supportData.version_added === type || supportData.version_removed === type); + } + return foundType; +}; const processData = (data) => { if (data.support) { From 8cd9d5b60ae0bf3a1e0134aa2667debface3190f Mon Sep 17 00:00:00 2001 From: Florian Scholz Date: Mon, 18 Mar 2019 18:57:58 +0100 Subject: [PATCH 6/6] Simplify checkSupport as suggested by foolip --- scripts/statistics.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/scripts/statistics.js b/scripts/statistics.js index 2d353f71e47c17..cc61b47d876f91 100644 --- a/scripts/statistics.js +++ b/scripts/statistics.js @@ -8,18 +8,10 @@ browsers.forEach(browser => { }); const checkSupport = (supportData, type) => { - let foundType = false; - if (Array.isArray(supportData)) { - supportData.forEach(item => { - // if 'type' occurs once in the array, mark it as found - if (item.version_added === type || item.version_removed === type) { - foundType = true; - } - }); - } else { - foundType = (supportData.version_added === type || supportData.version_removed === type); + if (!Array.isArray(supportData)) { + supportData = [supportData]; } - return foundType; + return supportData.some(item => item.version_added === type || item.version_removed === type) }; const processData = (data) => { @@ -54,7 +46,7 @@ const processData = (data) => { const iterateData = (data) => { for (let key in data) { - if (key == '__compat') { + if (key === '__compat') { processData(data[key]); } else { iterateData(data[key]);