DPL-103 [Data fix] update date tested in mongo table for Newcastle samples
neilsycamore opened this issue · comments
date_tested is set to 2020 rather that 2021 (month/day etc OK)
affected plate barcodes are
separate story for lighthouse_samples table
ICHNE000046W
ICHNE000047W
ICHNE000048W
ICHNE000049W
ICHNE000050W
ICHNE000051W
ICHNE000052W
ICHNE000053W
ICHNE000054W
ICHNE000055W
ICHNE000056W
ICHNE000057W
ICHNE000058W
ICHNE000060W
ICHNE000061W
ICHNE000062W
ICHNE000063W
ICHNE000064W
ICHNE000065W
ICHNE000066W
ICHNE000067W
ICHNE000068W
ICHNE000069W
ICHNE000070W
In order to fix these samples, I will be using the following Python script with the correct database constants. @emrojo Do you agree these these are the commands we want to perform?
from datetime import datetime
from pymongo import MongoClient
MONGO_URI = "mongodb://localhost:27017/?readPreference=primary&ssl=false"
MONGO_DB = "lighthouseDevelopmentDB"
MONGO_COLLECTION = "samples"
client = MongoClient(MONGO_URI)
database = client[MONGO_DB]
samples_collection = database[MONGO_COLLECTION]
affected_samples = samples_collection.find(
{"source": "Newcastle", "Date Tested": {"$lt": datetime(2021, 1, 1, 0, 0, 0)}}
)
for sample in affected_samples:
sample_id = sample["_id"]
updated_date_tested = sample["Date Tested"].replace(year=2021)
samples_collection.update_one({"_id": sample_id}, {"$set": {"Date Tested": updated_date_tested}})
Ok, code reviewed
Closing this, as it's in the Done column