-
Franky Begue authoredFranky Begue authored
getErrors.js 2.03 KiB
//dependencies:
// bucket alias <Users_Bucket>
//local aliases:
// var Users_Bucket = {};
// var log = console.log;
function cstr(ob){console.log(JSON.stringify(ob,null,4))}
//todo: can we flatten some of these arrays to increase speed
//then again, although n^n^n the n's have pretty low upper limits
function OnUpdate(doc, meta) {
try{
log('t')
log('docid', meta.id);
log('updated',Date.now().toISOString())
//log('doc', doc);
var validate = {
doc_date_generated:Date.now().toISOString(),
doc_total:"",
doc_with_errors_total:"",
doc_with_errors_ratio:"",
doc_errors_total:"",
userDataFields:{}
};
for(var sec in doc.userData){
validate.userDataFields[sec] = {};
if(doc.userData[sec].name && doc.userData[sec].name === "error"){
validate.userDataFields[sec] = {routine:doc.userData[sec].routine,severity:doc.userData[sec].severity}
}else{
var atSec = validate.userDataFields[sec] =
{doc_total: doc.userData[sec].length,doc_with_errors_total:0,doc_with_errors_ratio:0,error_types:{}};
doc.userData[sec].forEach(item =>{
validate.doc_total++;
if(item.errors){
item.errors.length ? atSec.doc_with_errors_total++:{};
item.errors.length ? validate.doc_with_errors_total++:{};
item.errors.forEach(e =>{
!(atSec.error_types[e.keyword]) ? atSec.error_types[e.keyword] = 0:{};
atSec.error_types[e.keyword]++;
validate.doc_errors_total++;
})
}
});
atSec.doc_with_errors_ratio = atSec.doc_total / atSec.doc_with_errors_total;
}
}
validate.doc_with_errors_ratio = validate.doc_with_errors_total / validate.doc_total;
doc['validation'] = validate;
Users_Bucket[meta.id] = doc;
log('set validation');
cstr(validate)
}catch(e){
log(e);
}
}function OnDelete(meta) {
}
// var testData = require('../testdata/getErrors_testdata');
// var meta = {cas: 1582920675004055600,
// id: "user_profile::IDM800027799",
// expiration: 0,
// flags: 33554432,
// vb: 689,
// seq: 64,
// }
// OnUpdate(testData.IDM800646917.Users_Bucket,meta);