14 dec data
This commit is contained in:
@@ -137,7 +137,7 @@ exports.kitAlert = async (event, context) => {
|
||||
console.log('Function triggered by change to: ' + resource);
|
||||
// now log the full event object
|
||||
console.log(JSON.stringify(event));
|
||||
const { kitSerial, classificationResult, _id, led1Average, led3Average } = event.value.fields;
|
||||
const { kitSerial, classificationResult, _id, led1Average, led3Average, deviceRatio } = event.value.fields;
|
||||
console.log('kitSerial', kitSerial);
|
||||
console.log('classificationResult', classificationResult);
|
||||
// if (classificationResult?.stringValue?.includes("Trait")) {
|
||||
@@ -204,17 +204,37 @@ exports.kitAlert = async (event, context) => {
|
||||
classification = "Sickle Cell Disease";
|
||||
}
|
||||
|
||||
// device ratio class
|
||||
const devRatio = deviceRatio?.doubleValue;
|
||||
let devRatioClass = "INVALID";
|
||||
if (devRatio > 0 && devRatio <= 0.55) {
|
||||
devRatioClass = "Normal";
|
||||
}
|
||||
if (devRatio > 0.55 && devRatio <= 0.575) {
|
||||
devRatioClass = "Negative Borderline";
|
||||
}
|
||||
if (devRatio > 0.575 && devRatio <= 0.85) {
|
||||
devRatioClass = "Sickle Cell Trait";
|
||||
}
|
||||
if (devRatio > 0.85 && devRatio <= 0.9) {
|
||||
devRatioClass = "Positive Borderline";
|
||||
}
|
||||
if (devRatio > 0.9 && devRatio <= 1) {
|
||||
devRatioClass = "Sickle Cell Disease";
|
||||
}
|
||||
|
||||
console.log(classification);
|
||||
|
||||
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({
|
||||
await admin.firestore().collection("testData").doc(doc.id).update({
|
||||
// abs427: Abs427,
|
||||
// abs555: Abs555,
|
||||
// predictedDenovixRatio: pdr,
|
||||
// prdClassification: classification
|
||||
// // incubationTime: admin.firestore.FieldValue.delete()
|
||||
// });
|
||||
// incubationTime: admin.firestore.FieldValue.delete()
|
||||
deviceRatioClass: devRatioClass,
|
||||
});
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
56
cloud-functions/python/functions/clearusers/main.py
Normal file
56
cloud-functions/python/functions/clearusers/main.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import functions_framework
|
||||
from google.cloud.firestore_v1.base_query import FieldFilter
|
||||
from firebase_admin import initialize_app, credentials, firestore
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
initialize_app()
|
||||
|
||||
@functions_framework.http
|
||||
def clearusers(request):
|
||||
"""HTTP Cloud Function.
|
||||
Args:
|
||||
request (flask.Request): The request object.
|
||||
<https://flask.palletsprojects.com/en/1.1.x/api/#incoming-request-data>
|
||||
Returns:
|
||||
The response text, or any set of values that can be turned into a
|
||||
Response object using `make_response`
|
||||
<https://flask.palletsprojects.com/en/1.1.x/api/#flask.make_response>.
|
||||
"""
|
||||
if request.method == 'OPTIONS':
|
||||
headers = {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET',
|
||||
'Access-Control-Allow-Headers': 'Content-Type',
|
||||
# 'Access-Control-Max-Age': '3600'
|
||||
}
|
||||
|
||||
return ('', 204, headers)
|
||||
|
||||
headers = {
|
||||
'Access-Control-Allow-Origin': '*'
|
||||
}
|
||||
|
||||
db = firestore.client()
|
||||
source_collection = "patientData"
|
||||
|
||||
# Get all documents from the source collection
|
||||
source_docs = db.collection(source_collection).where(filter=FieldFilter("createdAt", ">=", datetime.today().strftime("%Y-%m-%d"))).stream()
|
||||
count = 0
|
||||
for doc in source_docs:
|
||||
# Extract the document ID
|
||||
doc_id = doc.id
|
||||
print(doc_id)
|
||||
|
||||
# Get the document data
|
||||
doc_data = doc.to_dict()
|
||||
|
||||
try:
|
||||
# Delete the document from the source collection
|
||||
db.collection(source_collection).document(doc_id).delete()
|
||||
print(f"Document with ID '{doc_id}' updated")
|
||||
count = count + 1
|
||||
except Exception as e:
|
||||
print(f"Error deleting document with ID '{doc_id}' from the source collection: {e}")
|
||||
|
||||
return ('cleared users: {}!'.format(count), 200, headers)
|
||||
@@ -0,0 +1,6 @@
|
||||
functions-framework==3.*
|
||||
firebase_functions~=0.1.0
|
||||
pandas==2.0.3
|
||||
openpyxl==3.1.2
|
||||
firebase-admin==6.2.0
|
||||
scikit-learn==1.3.1
|
||||
Reference in New Issue
Block a user