add sample classfication fun
This commit is contained in:
@@ -208,13 +208,13 @@ exports.kitAlert = async (event, context) => {
|
|||||||
|
|
||||||
const docs = await admin.firestore().collection("testData").where("_id", "==", _id.stringValue).get();
|
const docs = await admin.firestore().collection("testData").where("_id", "==", _id.stringValue).get();
|
||||||
docs?.forEach(async (doc) => {
|
docs?.forEach(async (doc) => {
|
||||||
await admin.firestore().collection("testData").doc(doc.id).update({
|
// await admin.firestore().collection("testData").doc(doc.id).update({
|
||||||
abs427: Abs427,
|
// abs427: Abs427,
|
||||||
abs555: Abs555,
|
// abs555: Abs555,
|
||||||
predictedDenovixRatio: pdr,
|
// predictedDenovixRatio: pdr,
|
||||||
prdClassification: classification
|
// prdClassification: classification
|
||||||
// incubationTime: admin.firestore.FieldValue.delete()
|
// // incubationTime: admin.firestore.FieldValue.delete()
|
||||||
});
|
// });
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -368,3 +368,49 @@ exports.retestMarking = async (event, context) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggered by a change to a Firestore document.
|
||||||
|
*
|
||||||
|
* @param {!Object} event Event payload.
|
||||||
|
* @param {!Object} context Metadata for the event.
|
||||||
|
*/
|
||||||
|
const axios = require('axios');
|
||||||
|
const admin = require("firebase-admin");
|
||||||
|
const moment = require('moment');
|
||||||
|
|
||||||
|
admin.initializeApp();
|
||||||
|
|
||||||
|
exports.sampleClassification = 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 { _id, calculatedRatio, deviceRatio, led1Buffer, led2Buffer, led1Sample, led2Sample} = event.value.fields;
|
||||||
|
const predictionResponse = await axios.post("https://asia-south1-hpos-af3cc.cloudfunctions.net/prediction",
|
||||||
|
{
|
||||||
|
"_id": `${_id.stringValue}`,
|
||||||
|
"calculatedRatio": calculatedRatio.stringValue || calculatedRatio.doubleValue,
|
||||||
|
"deviceRatio": deviceRatio.stringValue || deviceRatio.doubleValue || deviceRatio.integerValue,
|
||||||
|
"led1Buffer": led1Buffer.stringValue || led1Buffer.doubleValue || led1Buffer.integerValue,
|
||||||
|
"led2Buffer": led2Buffer.stringValue || led2Buffer.doubleValue || led2Buffer.integerValue,
|
||||||
|
"led1Sample": led1Sample.stringValue || led1Sample.doubleValue || led1Sample.integerValue,
|
||||||
|
"led2Sample": led2Sample.stringValue || led2Sample.doubleValue || led2Sample.integerValue
|
||||||
|
}, {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"x-client": "e16a1bd15af2ee640f5a7a18c8d8333f5f01f7c66e003bbc21ee52870f1bce27"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const { predictedClass } = predictionResponse.data;
|
||||||
|
console.log("predictedClass", predictedClass);
|
||||||
|
const docs = await admin.firestore().collection("testData").where("_id", "==", _id.stringValue).get();
|
||||||
|
docs?.forEach(async (doc) => {
|
||||||
|
await admin.firestore().collection("testData").doc(doc.id).update({
|
||||||
|
predictedClass: predictedClass,
|
||||||
|
modelId: "1",
|
||||||
|
modelVersion: "1.0.1"
|
||||||
|
});
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user