Analyze script cleanup
This commit is contained in:
@ -13,8 +13,8 @@ let snippetsArchiveData = require('../snippet_data/snippetsArchive.json');
|
||||
const OUTPUT_PATH = './snippet_data';
|
||||
console.time('Analyzer');
|
||||
// Read data
|
||||
let snippetTokens = {
|
||||
data: snippetsData.data.map(snippet => {
|
||||
let [snippetTokens, snippetArchiveTokens] = [snippetsData, snippetsArchiveData].map(v => ({
|
||||
data: v.data.map(snippet => {
|
||||
let tokens = prism.tokenize(
|
||||
snippet.attributes.codeBlocks[0],
|
||||
prism.languages.javascript,
|
||||
@ -39,34 +39,7 @@ let snippetTokens = {
|
||||
};
|
||||
}),
|
||||
meta: { specification: 'http://jsonapi.org/format/' }
|
||||
};
|
||||
let snippetArchiveTokens = {
|
||||
data: snippetsArchiveData.data.map(snippet => {
|
||||
let tokens = prism.tokenize(
|
||||
snippet.attributes.codeBlocks[0],
|
||||
prism.languages.javascript,
|
||||
'javascript'
|
||||
);
|
||||
return {
|
||||
id: snippet.id,
|
||||
type: 'snippetAnalysis',
|
||||
attributes: {
|
||||
codeLength: snippet.attributes.codeBlocks[0].trim().length,
|
||||
tokenCount: tokens.length,
|
||||
functionCount: tokens.filter(t => t.type === 'function').length,
|
||||
operatorCount: tokens.filter(t => t.type === 'operator').length,
|
||||
keywordCount: tokens.filter(t => t.type === 'keyword').length,
|
||||
distinctFunctionCount: [
|
||||
...new Set(tokens.filter(t => t.type === 'function').map(t => t.content))
|
||||
].length
|
||||
},
|
||||
meta: {
|
||||
hash: snippet.meta.hash
|
||||
}
|
||||
};
|
||||
}),
|
||||
meta: { specification: 'http://jsonapi.org/format/' }
|
||||
};
|
||||
}));
|
||||
// Write data
|
||||
fs.writeFileSync(
|
||||
path.join(OUTPUT_PATH, 'snippetAnalytics.json'),
|
||||
|
||||
Reference in New Issue
Block a user