update coefficients
This commit is contained in:
31
scripts/update_coefficent.py
Normal file
31
scripts/update_coefficent.py
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
# datetime.strptime(end_time, "%Y-%m-%d %H:%M:%S")
|
||||
import firebase_admin
|
||||
from firebase_admin import credentials, firestore
|
||||
import os
|
||||
from google.cloud.firestore_v1.base_query import FieldFilter
|
||||
from datetime import datetime
|
||||
|
||||
key_path = os.getcwd() + '/keys/hpos-prod-firebase-adminsdk.json'
|
||||
cred = credentials.Certificate(key_path)
|
||||
firebase_admin.initialize_app(cred)
|
||||
def update_coefficent(source_collection):
|
||||
db = firestore.client()
|
||||
|
||||
docs = db.collection(source_collection).where(filter = FieldFilter("deviceId", "==", "HC-V1-014")).stream()
|
||||
|
||||
for doc in docs:
|
||||
doc_id = doc.id #doc.to_dict()["_id"]
|
||||
print(doc_id)
|
||||
|
||||
try:
|
||||
db.collection(source_collection).document(doc_id).update({
|
||||
"coefficients": [0.5136, 0.0242],
|
||||
"calibratedAt": datetime.today().strftime("%Y-%m-%d %H:%M:%S")
|
||||
})
|
||||
print(f"Document with ID '{doc_id}' updated")
|
||||
except Exception as e:
|
||||
print(f"Error updating document with ID '{doc_id}' from the source collection: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
update_coefficent("devices")
|
||||
Reference in New Issue
Block a user