Building out timetable logic
This commit is contained in:
parent
5773cc3d36
commit
3aee27d129
@ -47,12 +47,30 @@ def getTimetable(full = False):
|
||||
download_url = full_data_url if full else update_data_url
|
||||
response = requests.get(downloadUrl, auth=(CORPUS_USER, CORPUS_PASS))
|
||||
mongo.incrementCounter("schedule_api")
|
||||
return response
|
||||
return zlib.decompress(response.content, 16+zlib.MAX_WBITS)
|
||||
|
||||
def parseTimetable(data):
|
||||
## Parse the update file
|
||||
## Check how the downloaded data is displayed
|
||||
return
|
||||
def loopTimetable(data):
|
||||
listify = data.splitlines()
|
||||
documents = []
|
||||
for item in listify:
|
||||
dic = json.loads(item)
|
||||
if ('JsonTimetableV1' in dic):
|
||||
timestamp = dic['JsonTimetableV1']['timestamp']
|
||||
sequence = dic['JsonTimetableV1']['Metadata']['sequence']
|
||||
detail = {timestamp: timestamp, sequence: sequence}
|
||||
# Do something with this data here
|
||||
# Check if timestamp and sequence are correct, if not trigger a full download
|
||||
elif ('TiplocV1' in dic):
|
||||
print("Disregarding TIPLOC Data")
|
||||
# Not used as TIPLOCs etc. are sourced from CORPUS
|
||||
elif ('JsonAssociationV1' in dic):
|
||||
print("JsonAssociationData")
|
||||
# Associates trains with eachother - not planning to use yet.
|
||||
elif ('JsonScheduleV1' in dic):
|
||||
print("JsonScheduleData")
|
||||
document = insertSchedule(dic)
|
||||
documents.append(document)
|
||||
return documents
|
||||
|
||||
def runUpdate():
|
||||
required = isUpdateRequired()
|
||||
@ -66,3 +84,41 @@ def runUpdate():
|
||||
log.out("timetable.runUpdate: timetable update is not needed")
|
||||
return "done"
|
||||
## Check what happens if there is no update
|
||||
|
||||
def insertSchedule(sch_record):
|
||||
schedule = sch_record['JsonScheduleV1']
|
||||
scheduleId = schedule['CIF_train_uid']
|
||||
transactionType = schedule['transaction_type']
|
||||
document = {
|
||||
'stpIndicator': schedule['CIF_stp_indicator'],
|
||||
'trainUid': scheduleId,
|
||||
'headcode': schedule['schedule_segment']['signalling_id'],
|
||||
'powerType': schedule['schedule_segment']['CIF_power_type'],
|
||||
'planSpeed': schedule['schedule_segment']['CIF_speed'],
|
||||
'scheduleEndDate': schedule['schedule_end_date']
|
||||
}
|
||||
return document
|
||||
|
||||
# Proposed Document Schema:
|
||||
# {
|
||||
# stp_indicator: "O",
|
||||
# train_uid: "C07284"
|
||||
# atoc_code: "GW"
|
||||
# schedule_days_runs: [0,1,2,3,4,5,6] # Sunday-Saturday
|
||||
# schedule_end_date: "2023-06-02"
|
||||
# headcode: "5G30"
|
||||
# power_type: "DMU"
|
||||
# speed: "090"
|
||||
# catering_code: null
|
||||
# service_branding: ""
|
||||
# passenger_stops: [
|
||||
# {
|
||||
# 'tiploc': "TIPLOC",
|
||||
# 'pb_arr': "PublicArrival",
|
||||
# 'pb_dep': "PublicDepartr"
|
||||
# }
|
||||
# ]
|
||||
|
||||
### CURRENT STATE: loopTimetable and insertSchedule builds the data into
|
||||
### a suitable format to send to Mongo, passengerStops are not yet
|
||||
### parsed and there needs to be logic around the transaction_type
|
61
test-data/JsonScheduleV1
Normal file
61
test-data/JsonScheduleV1
Normal file
@ -0,0 +1,61 @@
|
||||
{
|
||||
"JsonScheduleV1": {
|
||||
"CIF_bank_holiday_running": null,
|
||||
"CIF_stp_indicator": "P",
|
||||
"CIF_train_uid": "P06522",
|
||||
"applicable_timetable": "Y",
|
||||
"atoc_code": "GW",
|
||||
"new_schedule_segment": {
|
||||
"traction_class": "",
|
||||
"uic_code": ""
|
||||
},
|
||||
"schedule_days_runs": "0000001",
|
||||
"schedule_end_date": "2023-12-03",
|
||||
"schedule_segment": {
|
||||
"signalling_id": "5O98",
|
||||
"CIF_train_category": "EE",
|
||||
"CIF_headcode": "",
|
||||
"CIF_course_indicator": 1,
|
||||
"CIF_train_service_code": "25471001",
|
||||
"CIF_business_sector": "??",
|
||||
"CIF_power_type": "DMU",
|
||||
"CIF_timing_load": "E",
|
||||
"CIF_speed": "090",
|
||||
"CIF_operating_characteristics": "D",
|
||||
"CIF_train_class": null,
|
||||
"CIF_sleepers": null,
|
||||
"CIF_reservations": null,
|
||||
"CIF_connection_indicator": null,
|
||||
"CIF_catering_code": null,
|
||||
"CIF_service_branding": "",
|
||||
"schedule_location": [
|
||||
{
|
||||
"location_type": "LO",
|
||||
"record_identity": "LO",
|
||||
"tiploc_code": "WEYMTH",
|
||||
"tiploc_instance": null,
|
||||
"departure": "0005",
|
||||
"public_departure": null,
|
||||
"platform": "3",
|
||||
"line": null,
|
||||
"engineering_allowance": null,
|
||||
"pathing_allowance": null,
|
||||
"performance_allowance": null
|
||||
},
|
||||
{
|
||||
"location_type": "LT",
|
||||
"record_identity": "LT",
|
||||
"tiploc_code": "WEYMJS",
|
||||
"tiploc_instance": null,
|
||||
"platform": null,
|
||||
"arrival": "0008",
|
||||
"public_arrival": null,
|
||||
"path": null
|
||||
}
|
||||
]
|
||||
},
|
||||
"schedule_start_date": "2023-10-29",
|
||||
"train_status": "P",
|
||||
"transaction_type": "Create"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user