Commit 298d9d71 by Иван Кубота

stats

parent b3873449
Pipeline #544 canceled with stage
......@@ -507,7 +507,7 @@ data = {tags:[], connections:[], more:[], standardQuestions: {}, standardAnswers
},
index: 'id'
});
debugger
theInc();
data.components = await readCSV({
fileName: path.join(base, moreElement.i),
......@@ -588,6 +588,7 @@ data = {tags:[], connections:[], more:[], standardQuestions: {}, standardAnswers
a.cardInfoID = adishen+a.cardInfoID;
a.qID = adishen+a.qID;
a.category_id = moreElement.q[0]|0;
a.answers = [];
a.multiple = ( a.multiple + '' )[ 0 ].toLowerCase() in { 'д': 1, '1': 1, 'y': '1', 'c': '1' };
a.image = null;
......@@ -605,7 +606,7 @@ data = {tags:[], connections:[], more:[], standardQuestions: {}, standardAnswers
types: {
qID: Number,
title: String,
correct: Number
correct: String
},
postProcess: ( a, inc ) => {
if( a.title.trim() === '' ) return false;
......
......@@ -68,7 +68,7 @@ const standardGenerator = function(random) {
return {
type: q.multiple ? 'checkbox': 'radio',
categoryId: q.category,
categoryId: q.category_id,
productId: q.qID,
question: textFormat(q.title),
answers: shuffle(q.answers.map(a =>
......
......@@ -89,16 +89,18 @@ module.exports = {
seed: {required: false, description: 'initialize random state. Make response determined', type: String},
photo: {required: false, description: 'question with photo', type: Boolean},
type: {required: false, description: '1 - products, 2 - standards', type: Number},
nolog: {required: false, description: 'remove human readable log', type: Boolean}
nolog: {required: false, description: 'remove human readable log', type: Boolean},
stats: {required: false, description: 'aggregate stats and explain questions', type: Boolean},
},
fn: async function(args) {
fn: async function(args, req, res) {
let seed = args.seed || Math.random().toString(36).substr(2);
ctx.seeded.setStringSeed( seed );
let used = {}, generated = 0;
let last = {c:-1},
list = [],
globalMaxTries = args.count*100,
globalMaxTries = args.count*5,
globalTries = 0;
if(args.count>100)args.count = 100;
while(generated<args.count && globalTries < globalMaxTries){
globalTries++;
let cur = {
......@@ -152,6 +154,40 @@ module.exports = {
result.number = generated;
}
}
if(args.stats){
res.header("Content-Type", "text/html; charset=utf-8");
let stats = {};
let statsImage = {};
let statsCategory = {};
let statsType = {};
list.forEach(i=>{
if(i.categoryId === void 0)
debugger;
let key = i.type+', '+(i.image?'image':'no image')+', '+i.categoryId;
stats[key] = (stats[key]||0)+1;
key = i.type+'';
statsType[key] = (statsType[key]||0)+1;
key = (i.image?'image':'no image');
statsImage[key] = (statsImage[key]||0)+1;
key = i.categoryId+'';
statsCategory[key] = (statsCategory[key]||0)+1;
});
return '<HTML><head></head><body>' +
`<h2>Generated: ${list.length}</h2>` +
'<div>'+Object.keys(stats).map(k=>`<b>${k}</b>: <span>${stats[k]}</span>`).join('<br/>')+'</div>'+
'<h2>Image</h2><div>'+Object.keys(statsImage).map(k=>`<b>${k}</b>: <span>${statsImage[k]}</span>`).join('<br/>')+'</div>'+
'<h2>Category</h2><div>'+Object.keys(statsCategory).map(k=>`<b>${k}</b>: <span>${statsCategory[k]}</span>`).join('<br/>')+'</div>'+
'<h2>Type</h2><div>'+Object.keys(statsType).map(k=>`<b>${k}</b>: <span>${statsType[k]}</span>`).join('<br/>')+'</div>'+
'</body></HTML>'
}
return list;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment