Add TIPLOC to PIS Data
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
# program. If not, see
|
||||
# https://git.fjla.uk/OwlBoard/db-manager/src/branch/main/LICENSE
|
||||
|
||||
version = "2023.5.9"
|
||||
version = "2023.5.10"
|
||||
print(f"main.py: Initialising db-manager v{version}")
|
||||
|
||||
#Third Party Imports
|
||||
|
||||
@@ -181,4 +181,9 @@ def putMetaHash(target :str, hash :str):
|
||||
"type": "collection",
|
||||
"hash": hash
|
||||
}
|
||||
res = col.update_one(filter, {"$set": update}, upsert=True)
|
||||
res = col.update_one(filter, {"$set": update}, upsert=True)
|
||||
|
||||
def query(collection, query):
|
||||
col = db[collection]
|
||||
log.out(f"mongo.query: Running query: {query}")
|
||||
return col.find_one(query)
|
||||
32
src/pis.py
32
src/pis.py
@@ -2,8 +2,11 @@ import yaml, hashlib
|
||||
import logger as log
|
||||
import mongo
|
||||
|
||||
REBUILD :bool = False # Set to True to force rebuild
|
||||
|
||||
print("pis.py: PIS Module Loaded", "DBUG")
|
||||
file_location :str = "/app/data/pis/gwr.yaml"
|
||||
#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
|
||||
|
||||
def runUpdate():
|
||||
if (not requiresUpdate()):
|
||||
@@ -14,8 +17,12 @@ def runUpdate():
|
||||
pis_parsed = parse(pis_data)
|
||||
mongo.dropCollection("pis")
|
||||
mongo.putMany("pis", pis_parsed)
|
||||
mongo.createSingleIndex("pis", "stops")
|
||||
mongo.createSingleIndex("pis", "tiplocs")
|
||||
|
||||
def requiresUpdate():
|
||||
if REBUILD:
|
||||
return True
|
||||
currentHash = mongo.getMetaHash("pis")
|
||||
with open(file_location, "r") as f:
|
||||
text = f.read()
|
||||
@@ -39,13 +46,32 @@ def load(): # Programatically add a `toc` field to each entry.
|
||||
|
||||
def parse(codeList):
|
||||
StartLen = len(codeList)
|
||||
print(f"pis.parse: codeList starting length: {StartLen}")
|
||||
log.out(f"pis.parse: codeList starting length: {StartLen}", "DBUG")
|
||||
log.out(f"pis.parse: Removing duplicate codes & adding TIPLOCs")
|
||||
for i in codeList:
|
||||
stops = i['stops']
|
||||
print(stops)
|
||||
code = i['code']
|
||||
for ii in codeList:
|
||||
if stops == ii['stops'] and code != ii['code']:
|
||||
print(f"Identical stopping pattern found: {ii['code']}")
|
||||
codeList.remove(ii)
|
||||
tiplocs = []
|
||||
for iii in stops:
|
||||
print(iii)
|
||||
tiplocs.append(getTiploc(iii))
|
||||
i['tiplocs'] = tiplocs
|
||||
print(f"pis.parse: Removed {StartLen - len(codeList)} duplicates")
|
||||
return codeList
|
||||
return codeList
|
||||
|
||||
def getTiploc(crs :str):
|
||||
CRS = crs.upper()
|
||||
#log.out(f"pis.getTiploc: Finding TIPLOC for {CRS}")
|
||||
query = {
|
||||
'3ALPHA': CRS
|
||||
}
|
||||
res = mongo.query("stations", query)
|
||||
print(res)
|
||||
if 'TIPLOC' in res:
|
||||
return res['TIPLOC']
|
||||
return "UNKNOWN"
|
||||
Reference in New Issue
Block a user