diff --git a/src/mongo.py b/src/mongo.py index 648be32..ead16a4 100644 --- a/src/mongo.py +++ b/src/mongo.py @@ -88,6 +88,8 @@ def putVersion(version): return def putTimetable(data): + data_length = len(data) + log.out(f"mongo.putTimetable: Adding {data_length} documents to the database") collection = "timetable" col = db[collection] res = col.insert_many(data) diff --git a/src/pis.py b/src/pis.py index ded3570..95eb81f 100644 --- a/src/pis.py +++ b/src/pis.py @@ -6,7 +6,7 @@ REBUILD :bool = False # Set to True to force rebuild log.out("pis.py: PIS Module Loaded", "DBUG") file_location :str = "/app/data/pis/gwr.yaml" # Production & Testing -#file_location :str = "/home/fred.boniface/git/owlboard/db-manager/data/pis/gwr.yaml" # Local Development +file_location :str = "/home/fred.boniface/git/owlboard/db-manager/data/pis/gwr.yaml" # Local Development def runUpdate(): if (not requiresUpdate()): diff --git a/src/reasonCodes.py b/src/reasonCodes.py index f7c202a..e996327 100644 --- a/src/reasonCodes.py +++ b/src/reasonCodes.py @@ -7,7 +7,7 @@ REBUILD = False log.out("reasonCodes.py: reasonCodes module initialised", "DBUG") file_location :str = "/app/data/reasonCodes/reasoncodes.json" # Production & Testing -#file_location :str = "/home/fred.boniface/git/owlboard/db-manager/data/reasonCodes/reasoncodes.json" # Local Development +file_location :str = "/home/fred.boniface/git/owlboard/db-manager/data/reasonCodes/reasoncodes.json" # Local Development def runUpdate(): if (not requiresUpdate()): diff --git a/src/timetable.py b/src/timetable.py index a37eba8..92f715b 100644 --- a/src/timetable.py +++ b/src/timetable.py @@ -106,7 +106,6 @@ def runUpdate(): if (status): mongo.metaUpdateTime("timetable") _removeOutdatedServices() - ## Check what happens if there is no update def insertSchedule(sch_record): schedule = sch_record['JsonScheduleV1'] @@ -148,12 +147,13 @@ def _insertToDb(data :list, type :str): mongo.putTimetable(data) mongo.createSingleIndex("timetable", "headcode") elif type == "update": + create_transactions = [] for item in data: if item['transactionType'] == "Create": - singleList = [item] ### These items should be stored in a list and only - mongo.putTimetable(singleList) ### Put into the databse AFTER deletions. + create_transactions.append([item]) elif item['transactionType'] == "Delete": - mongo.deleteTimetableData({'trainUid': item['trainUid'], 'scheduleStartDate': item['scheduleStartDate'], 'stpIndicator': item['stpIndicator']}) ## Also need to consider the STP indicator and end date here else I am deleting LTP services when an STP is meant to be deleted. + mongo.deleteTimetableData({'trainUid': item['trainUid'], 'scheduleStartDate': item['scheduleStartDate'], 'stpIndicator': item['stpIndicator']}) + mongo.putTimetable(create_transactions) post_count = mongo.getLength("timetable") log.out(f"timetable._insertToDb: Document count difference after processing: {pre_count - post_count}", "DBUG") return True #If Successfuls