Test fixed TT update

This commit is contained in:
Fred Boniface 2023-06-29 20:12:49 +01:00
parent 0c2b0dc0a2
commit 4debe98c18
4 changed files with 8 additions and 6 deletions

View File

@ -88,6 +88,8 @@ def putVersion(version):
return return
def putTimetable(data): def putTimetable(data):
data_length = len(data)
log.out(f"mongo.putTimetable: Adding {data_length} documents to the database")
collection = "timetable" collection = "timetable"
col = db[collection] col = db[collection]
res = col.insert_many(data) res = col.insert_many(data)

View File

@ -6,7 +6,7 @@ REBUILD :bool = False # Set to True to force rebuild
log.out("pis.py: PIS Module Loaded", "DBUG") log.out("pis.py: PIS Module Loaded", "DBUG")
file_location :str = "/app/data/pis/gwr.yaml" # Production & Testing 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(): def runUpdate():
if (not requiresUpdate()): if (not requiresUpdate()):

View File

@ -7,7 +7,7 @@ REBUILD = False
log.out("reasonCodes.py: reasonCodes module initialised", "DBUG") log.out("reasonCodes.py: reasonCodes module initialised", "DBUG")
file_location :str = "/app/data/reasonCodes/reasoncodes.json" # Production & Testing 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(): def runUpdate():
if (not requiresUpdate()): if (not requiresUpdate()):

View File

@ -106,7 +106,6 @@ def runUpdate():
if (status): if (status):
mongo.metaUpdateTime("timetable") mongo.metaUpdateTime("timetable")
_removeOutdatedServices() _removeOutdatedServices()
## Check what happens if there is no update
def insertSchedule(sch_record): def insertSchedule(sch_record):
schedule = sch_record['JsonScheduleV1'] schedule = sch_record['JsonScheduleV1']
@ -148,12 +147,13 @@ def _insertToDb(data :list, type :str):
mongo.putTimetable(data) mongo.putTimetable(data)
mongo.createSingleIndex("timetable", "headcode") mongo.createSingleIndex("timetable", "headcode")
elif type == "update": elif type == "update":
create_transactions = []
for item in data: for item in data:
if item['transactionType'] == "Create": if item['transactionType'] == "Create":
singleList = [item] ### These items should be stored in a list and only create_transactions.append([item])
mongo.putTimetable(singleList) ### Put into the databse AFTER deletions.
elif item['transactionType'] == "Delete": 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") post_count = mongo.getLength("timetable")
log.out(f"timetable._insertToDb: Document count difference after processing: {pre_count - post_count}", "DBUG") log.out(f"timetable._insertToDb: Document count difference after processing: {pre_count - post_count}", "DBUG")
return True #If Successfuls return True #If Successfuls