add data regularity function
This commit is contained in:
@@ -160,3 +160,43 @@ exports.kitAlert = async (event, context) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggered by a change to a Firestore document.
|
||||||
|
*
|
||||||
|
* @param {!Object} event Event payload.
|
||||||
|
* @param {!Object} context Metadata for the event.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// const functions = require("firebase-functions");
|
||||||
|
// const admin = require("firebase-admin");
|
||||||
|
// const moment = require('moment');
|
||||||
|
|
||||||
|
// admin.initializeApp();
|
||||||
|
|
||||||
|
exports.dataRegularity = async (event, context) => {
|
||||||
|
const resource = context.resource;
|
||||||
|
// log out the resource string that triggered the function
|
||||||
|
console.log('Function triggered by change to: ' + resource);
|
||||||
|
// now log the full event object
|
||||||
|
console.log(JSON.stringify(event));
|
||||||
|
const { kitSerial, classificationResult, _id, deviceId, led1Buffer, led2Buffer, led1Sample, led2Sample } = event.value.fields;
|
||||||
|
console.log('_id', _id?.stringValue);
|
||||||
|
if (led1Buffer?.stringValue > 27000 || led2Buffer?.stringValue > 28000 || led1Sample?.stringValue ) {
|
||||||
|
const currentKitTests = await admin.firestore().collection("testData").where("kitSerial", "==", kitSerial.stringValue).get();
|
||||||
|
let traitCount = 0;
|
||||||
|
currentKitTests?.docs.forEach((x) => {
|
||||||
|
if (x.data().classificationResult?.includes("Trait")) {
|
||||||
|
traitCount++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await admin.firestore().collection("alerts").add({
|
||||||
|
name: 'Data Regularity',
|
||||||
|
kit: kitSerial.stringValue,
|
||||||
|
deviceId: deviceId,
|
||||||
|
message: `${_id.stringValue} has some irregularity in data`,
|
||||||
|
createdAt: moment().utcOffset("+05:30").format("YYYY-MM-DD HH:mm:ss")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user