Add requirement
Browse files- requirements.txt +5 -0
- well_status_utils.py +98 -0
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
paho-mqtt
|
| 3 |
+
pandas
|
| 4 |
+
pymongo
|
| 5 |
+
prefect
|
well_status_utils.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#from lambda_mongo_utils import send_data_to_mongodb
|
| 2 |
+
from pymongo import MongoClient
|
| 3 |
+
from prefect import task
|
| 4 |
+
import pandas as pd
|
| 5 |
+
#import os
|
| 6 |
+
|
| 7 |
+
#MONGODB_PASSWORD = os.getenv("MONGODB_PASSWORD")
|
| 8 |
+
|
| 9 |
+
MONGODB_PASSWORD = "84Zcbnk8oF9nRKVj"
|
| 10 |
+
|
| 11 |
+
# Connection string obtained via MongoDB Atlas "Connect" button
|
| 12 |
+
blinded_connection_string = "mongodb+srv://Neil-YL:<db_password>@lcm-ot2-sdl.4wik0.mongodb.net/?retryWrites=true&w=majority&appName=LCM-OT2-SDL"
|
| 13 |
+
|
| 14 |
+
# Replace <password> with the MongoDB password (where again, the connection
|
| 15 |
+
# string and password would normally be kept private)
|
| 16 |
+
connection_string = blinded_connection_string.replace("<db_password>", MONGODB_PASSWORD)
|
| 17 |
+
|
| 18 |
+
@task
|
| 19 |
+
def generate_empty_well():
|
| 20 |
+
dbclient = MongoClient(connection_string)
|
| 21 |
+
db = dbclient["LCM-OT-2-SLD"]
|
| 22 |
+
collection = db["wells"]
|
| 23 |
+
rows = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
|
| 24 |
+
columns = [str(i) for i in range(1, 13)]
|
| 25 |
+
for row in rows:
|
| 26 |
+
for col in columns:
|
| 27 |
+
well = f"{row}{col}"
|
| 28 |
+
metadata = {
|
| 29 |
+
"well": well,
|
| 30 |
+
"status": "empty",
|
| 31 |
+
"project": "OT2"
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
#send_data_to_mongodb(collection="wells", data=metadata)
|
| 35 |
+
query = {"well": well}
|
| 36 |
+
update_data = {"$set": metadata}
|
| 37 |
+
result = collection.update_one(query, update_data, upsert=True)
|
| 38 |
+
|
| 39 |
+
# close connection
|
| 40 |
+
dbclient.close()
|
| 41 |
+
|
| 42 |
+
@task
|
| 43 |
+
def update_used_wells(used_wells):
|
| 44 |
+
dbclient = MongoClient(connection_string)
|
| 45 |
+
db = dbclient["LCM-OT-2-SLD"]
|
| 46 |
+
collection = db["wells"]
|
| 47 |
+
|
| 48 |
+
for well in used_wells:
|
| 49 |
+
metadata = {
|
| 50 |
+
"well": well,
|
| 51 |
+
"status": "used",
|
| 52 |
+
"project": "OT2"
|
| 53 |
+
}
|
| 54 |
+
#send_data_to_mongodb(collection="wells", data=metadata)
|
| 55 |
+
query = {"well": well}
|
| 56 |
+
update_data = {"$set": metadata}
|
| 57 |
+
result = collection.update_one(query, update_data, upsert=True)
|
| 58 |
+
|
| 59 |
+
# close connection
|
| 60 |
+
dbclient.close()
|
| 61 |
+
|
| 62 |
+
@task
|
| 63 |
+
def find_unused_wells():
|
| 64 |
+
dbclient = MongoClient(connection_string)
|
| 65 |
+
db = dbclient["LCM-OT-2-SLD"]
|
| 66 |
+
collection = db["wells"]
|
| 67 |
+
query = {"status": "empty"}
|
| 68 |
+
response = list(collection.find(query))
|
| 69 |
+
df = pd.DataFrame(response)
|
| 70 |
+
|
| 71 |
+
# Extract the "well" column as a list
|
| 72 |
+
if "well" not in df.columns:
|
| 73 |
+
raise ValueError("The returned data does not contain the 'well' field.")
|
| 74 |
+
# Sort obtained list
|
| 75 |
+
def well_sort_key(well):
|
| 76 |
+
row = well[0] # A, B, C, ...
|
| 77 |
+
col = int(well[1:]) # 1, 2, ..., 12
|
| 78 |
+
return (row, col)
|
| 79 |
+
|
| 80 |
+
empty_wells = sorted(df["well"].tolist(), key=well_sort_key)
|
| 81 |
+
#print(empty_wells)
|
| 82 |
+
|
| 83 |
+
# close connection
|
| 84 |
+
dbclient.close()
|
| 85 |
+
|
| 86 |
+
# Check if there are any empty wells
|
| 87 |
+
if len(empty_wells) == 0:
|
| 88 |
+
raise ValueError("No empty wells found")
|
| 89 |
+
#print(empty_wells)
|
| 90 |
+
return empty_wells
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
if __name__ == "__main__":
|
| 95 |
+
generate_empty_well()
|
| 96 |
+
#find_unused_wells()
|
| 97 |
+
|
| 98 |
+
|