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
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)

View File

@ -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()):

View File

@ -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()):

View File

@ -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