Page MenuHomePhabricator
Paste P65115

T342267 example rollup
ActivePublic

Authored by Krinkle on Jun 17 2024, 7:54 PM.
Tags
None
Referenced Files
F55413577: T342267 example rollup
Jun 17 2024, 7:54 PM
Subscribers
None
var input = [
{ os_family: 'Windows', os_version: 10, browser_family: 'Firefox', browser_version: 100, pct: 5 },
{ os_family: 'Windows', os_version: 10, browser_family: 'Firefox', browser_version: 12, pct: 0.05 },
{ os_family: 'Windows', os_version: 10, browser_family: 'Firefox', browser_version: 16, pct: 0.06 },
{ os_family: 'Windows', os_version: 8, browser_family: 'Firefox', browser_version: 100, pct: 10 },
{ os_family: 'Windows', os_version: 7, browser_family: 'Firefox', browser_version: 12, pct: 0.05 },
{ os_family: 'Windows', os_version: 7, browser_family: 'Firefox', browser_version: 14, pct: 0.06 },
{ os_family: 'Windows', os_version: 7, browser_family: 'Iceweasel', browser_version: 19, pct: 0.06 },
{ os_family: 'macOS', os_version: 10, browser_family: 'Firefox', browser_version: 100, pct: 2 },
{ os_family: 'macOS', os_version: 11, browser_family: 'Firefox', browser_version: 12, pct: 0.03 },
{ os_family: 'macOS', os_version: 12, browser_family: 'Firefox', browser_version: 15, pct: 0.04 },
{ os_family: 'macOS', os_version: 13, browser_family: 'Firefox', browser_version: 16, pct: 0.05 },
{ os_family: 'Linux', os_version: '-', browser_family: 'Firefox', browser_version: 100, pct: 0.04 },
{ os_family: 'Linux', os_version: '-', browser_family: 'Firefox', browser_version: 12, pct: 0.02 },
{ os_family: 'Linux', os_version: '-', browser_family: 'Firefox', browser_version: 16, pct: 0.04 },
{ os_family: 'Linux', os_version: '-', browser_family: 'Iceweasel', browser_version: 17, pct: 0.03 },
{ os_family: 'Linux', os_version: '-', browser_family: 'Iceweasel', browser_version: 18, pct: 0.02 },
{ os_family: 'Linux', os_version: '-', browser_family: 'Chrome', browser_version: 80, pct: 0.06 },
];
function groupByInternal(dataset, indexFields, sumField) {
const index = Object.create(null);
for (const row of dataset) {
const key = indexFields.map(field => row[field]);
if (!index[key]) {
index[key] = Object.fromEntries([...indexFields, sumField].map(field => [field, row[field]]));
} else {
index[key][sumField] += row[sumField];
}
}
return Object.values(index);
}
function groupBy(dataset, sumField) {
const index = Object.create(null);
const indexFields = Object.keys(dataset[0]).filter(field => field != sumField);
for (const row of dataset) {
const key = indexFields.map(field => row[field]);
if (!index[key]) {
index[key] = row;
} else {
index[key][sumField] += row[sumField];
}
}
return Object.values(index);
}
function raw(dataset) {
return dataset;
}
function anon_status_quo(dataset) {
const anon = [];
for (const row of dataset) {
if (row.pct < 0.1) {
anon.push({ os_family: 'Other', os_version: '-', browser_family: 'Other', browser_version: '-', pct: row.pct });
} else {
anon.push(row);
}
}
return groupBy(anon, 'pct');
}
function anon_idea1_browserfirst(dataset) {
let tmp = dataset;
tmp = tmp.map(row => {
return (row.pct < 0.1)
? { ...row, browser_version: '-' }
: row;
});
tmp = groupBy(tmp, 'pct');
tmp = tmp.map(row => {
return (row.pct < 0.1)
? { ...row, os_version: '-' }
: row;
});
tmp = groupBy(tmp, 'pct');
tmp = tmp.map(row => {
return (row.pct < 0.1)
? { ...row, browser_family: 'Other' }
: row;
});
tmp = groupBy(tmp, 'pct');
tmp = tmp.map(row => {
return (row.pct < 0.1)
? { os_family: 'Other', os_version: '-', browser_family: 'Other', browser_version: '-', pct: row.pct }
: row;
});
tmp = groupBy(tmp, 'pct');
return tmp;
}
function anon_idea1_osfirst(dataset) {
let tmp = dataset;
tmp = tmp.map(row => {
return (row.pct < 0.1)
? { ...row, os_version: '-' }
: row;
});
tmp = groupBy(tmp, 'pct');
tmp = tmp.map(row => {
return (row.pct < 0.1)
? { ...row, browser_version: '-' }
: row;
});
tmp = groupBy(tmp, 'pct');
tmp = tmp.map(row => {
return (row.pct < 0.1)
? { ...row, os_family: 'Other' }
: row;
});
tmp = groupBy(tmp, 'pct');
tmp = tmp.map(row => {
return (row.pct < 0.1)
? { os_family: 'Other', os_version: '-', browser_family: 'Other', browser_version: '-', pct: row.pct }
: row;
});
tmp = groupBy(tmp, 'pct');
return tmp;
}
for (const fn of [raw, anon_status_quo, anon_idea1_browserfirst, anon_idea1_osfirst]) {
let output = fn(input);
console.log('');
console.log('### ' + fn.name);
console.log('');
if (typeof require === 'function') {
output = require('util').inspect(output, { compact: 5, breakLength: 200 });
}
console.log(output);
// // console.log(fn.name, 'by os', groupByInternal(output, ['os_family'], 'pct'));
// // console.log(fn.name, 'by browser', groupByInternal(output, ['browser_family'], 'pct'));
// // console.log(fn.name, 'by os+version', groupByInternal(output, ['os_family', 'os_version'], 'pct'));
// // console.log(fn.name, 'by browser+version', groupByInternal(output, ['browser_family', 'browser_version'], 'pct'));
}
// for (const fn of [raw, anon_status_quo, anon_idea1_browserfirst, anon_idea1_osfirst]) {
// const output = fn(input);
// console.log(fn.name, 'by os', groupByInternal(output, ['os_family'], 'pct'));
// }
// for (const fn of [raw, anon_status_quo, anon_idea1_browserfirst, anon_idea1_osfirst]) {
// const output = fn(input);
// console.log(fn.name, 'by browser', groupByInternal(output, ['browser_family'], 'pct'));
// }
// for (const fn of [raw, anon_status_quo, anon_idea1_browserfirst, anon_idea1_osfirst]) {
// const output = fn(input);
// console.log(fn.name, 'by os+version', groupByInternal(output, ['os_family', 'os_version'], 'pct'));
// }
// for (const fn of [raw, anon_status_quo, anon_idea1_browserfirst, anon_idea1_osfirst]) {
// const output = fn(input);
// console.log(fn.name, 'by browser+version', groupByInternal(output, ['browser_family', 'browser_version'], 'pct'));
// }

Event Timeline

Fake input data to better understand "Idea 1" for T342267.

raw
[ { os_family: 'Windows', os_version: 10, browser_family: 'Firefox', browser_version: 100, pct: 5 },
  { os_family: 'Windows', os_version: 10, browser_family: 'Firefox', browser_version: 12, pct: 0.05 },
  { os_family: 'Windows', os_version: 10, browser_family: 'Firefox', browser_version: 16, pct: 0.06 },
  { os_family: 'Windows', os_version: 8, browser_family: 'Firefox', browser_version: 100, pct: 10 },
  { os_family: 'Windows', os_version: 7, browser_family: 'Firefox', browser_version: 12, pct: 0.05 },
  { os_family: 'Windows', os_version: 7, browser_family: 'Firefox', browser_version: 14, pct: 0.06 },
  { os_family: 'Windows', os_version: 7, browser_family: 'Iceweasel', browser_version: 19, pct: 0.06 },
  { os_family: 'macOS', os_version: 10, browser_family: 'Firefox', browser_version: 100, pct: 2 },
  { os_family: 'macOS', os_version: 11, browser_family: 'Firefox', browser_version: 12, pct: 0.03 },
  { os_family: 'macOS', os_version: 12, browser_family: 'Firefox', browser_version: 15, pct: 0.04 },
  { os_family: 'macOS', os_version: 13, browser_family: 'Firefox', browser_version: 16, pct: 0.05 },
  { os_family: 'Linux', os_version: '-', browser_family: 'Firefox', browser_version: 100, pct: 0.04 },
  { os_family: 'Linux', os_version: '-', browser_family: 'Firefox', browser_version: 12, pct: 0.02 },
  { os_family: 'Linux', os_version: '-', browser_family: 'Firefox', browser_version: 16, pct: 0.04 },
  { os_family: 'Linux', os_version: '-', browser_family: 'Iceweasel', browser_version: 17, pct: 0.03 },
  { os_family: 'Linux', os_version: '-', browser_family: 'Iceweasel', browser_version: 18, pct: 0.02 },
  { os_family: 'Linux', os_version: '-', browser_family: 'Chrome', browser_version: 80, pct: 0.06 } ]
anon_status_quo
[ { os_family: 'Windows', os_version: 10, browser_family: 'Firefox', browser_version: 100, pct: 5 },
  { os_family: 'Other', os_version: '-', browser_family: 'Other', browser_version: '-', pct: 0.6100000000000001 },
  { os_family: 'Windows', os_version: 8, browser_family: 'Firefox', browser_version: 100, pct: 10 },
  { os_family: 'macOS', os_version: 10, browser_family: 'Firefox', browser_version: 100, pct: 2 } ]
anon_idea1_browserfirst
[ { os_family: 'Windows', os_version: 10, browser_family: 'Firefox', browser_version: 100, pct: 5 },
  { os_family: 'Windows', os_version: 10, browser_family: 'Firefox', browser_version: '-', pct: 0.11 },
  { os_family: 'Windows', os_version: 8, browser_family: 'Firefox', browser_version: 100, pct: 10 },
  { os_family: 'Windows', os_version: 7, browser_family: 'Firefox', browser_version: '-', pct: 0.11 },
  { os_family: 'Other', os_version: '-', browser_family: 'Other', browser_version: '-', pct: 0.06 },
  { os_family: 'macOS', os_version: 10, browser_family: 'Firefox', browser_version: 100, pct: 2 },
  { os_family: 'macOS', os_version: '-', browser_family: 'Firefox', browser_version: '-', pct: 0.12000000000000001 },
  { os_family: 'Linux', os_version: '-', browser_family: 'Firefox', browser_version: '-', pct: 0.1 },
  { os_family: 'Linux', os_version: '-', browser_family: 'Other', browser_version: '-', pct: 0.11 } ]
anon_idea1_osfirst
[ { os_family: 'Windows', os_version: 10, browser_family: 'Firefox', browser_version: 100, pct: 5 },
  { os_family: 'Windows', os_version: '-', browser_family: 'Firefox', browser_version: 12, pct: 0.1 },
  { os_family: 'Windows', os_version: '-', browser_family: 'Firefox', browser_version: '-', pct: 0.12 },
  { os_family: 'Windows', os_version: 8, browser_family: 'Firefox', browser_version: 100, pct: 10 },
  { os_family: 'Other', os_version: '-', browser_family: 'Iceweasel', browser_version: '-', pct: 0.11 },
  { os_family: 'macOS', os_version: 10, browser_family: 'Firefox', browser_version: 100, pct: 2 },
  { os_family: 'macOS', os_version: '-', browser_family: 'Firefox', browser_version: '-', pct: 0.12000000000000001 },
  { os_family: 'Linux', os_version: '-', browser_family: 'Firefox', browser_version: '-', pct: 0.1 },
  { os_family: 'Other', os_version: '-', browser_family: 'Other', browser_version: '-', pct: 0.06 } ]

query public result by os

raw
[ { os_family: 'Windows', pct: 15.280000000000001 },
  { os_family: 'macOS', pct: 2.1199999999999997 },
  { os_family: 'Linux', pct: 0.21 } ]
anon_status_quo
[ { os_family: 'Windows', pct: 15 },
  { os_family: 'Other', pct: 0.6100000000000001 },
  { os_family: 'macOS', pct: 2 } ]
anon_idea1_browserfirst
[ { os_family: 'Windows', pct: 15.219999999999999 },
  { os_family: 'Other', pct: 0.06 },
  { os_family: 'macOS', pct: 2.12 },
  { os_family: 'Linux', pct: 0.21000000000000002 } ]
anon_idea1_osfirst
[ { os_family: 'Windows', pct: 15.219999999999999 },
  { os_family: 'Other', pct: 0.16999999999999998 },
  { os_family: 'macOS', pct: 2.12 },
  { os_family: 'Linux', pct: 0.1 } ]

query public result by browser

raw
[ { browser_family: 'Firefox', pct: 17.439999999999998 },
  { browser_family: 'Iceweasel', pct: 0.11 },
  { browser_family: 'Chrome', pct: 0.06 } ]
anon_status_quo
[ { browser_family: 'Firefox', pct: 17 },
  { browser_family: 'Other', pct: 0.6100000000000001 } ]
anon_idea1_browserfirst
[ { browser_family: 'Firefox', pct: 17.44 },
  { browser_family: 'Other', pct: 0.16999999999999998 } ]
anon_idea1_osfirst
[ { browser_family: 'Firefox', pct: 17.44 },
  { browser_family: 'Iceweasel', pct: 0.11 },
  { browser_family: 'Other', pct: 0.06 } ]