Spaces:
Running
Running
File size: 1,333 Bytes
f2bee8a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
/**
* Report a telemetry event.
* @param {string} event - one of `projectWasCreated`, `projectDidLoad`, `projectDidSave`, `projectWasUploaded`
*/
// TODO make a telemetry HOC and move this stuff there
const collectMetadata = function (vm, projectName = '', locale = '') {
// TODO move most or all of this into a collectMetadata() method on the VM/Runtime
const metadata = {
projectName: projectName,
language: locale,
spriteCount: 0,
blocksCount: 0,
costumesCount: 0,
listsCount: 0,
scriptCount: 0,
soundsCount: 0,
variablesCount: 0
};
for (const target of vm.runtime.targets) {
++metadata.spriteCount;
metadata.blocksCount += Object.keys(target.sprite.blocks._blocks).length;
metadata.costumesCount += target.sprite.costumes_.length;
metadata.scriptCount += target.sprite.blocks._scripts.length;
metadata.soundsCount += target.sprite.sounds.length;
for (const variableName in target.variables) {
const variable = target.variables[variableName];
if (variable.type === 'list') {
++metadata.listsCount;
} else {
++metadata.variablesCount;
}
}
}
return metadata;
};
export default collectMetadata;
|