2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-13 22:17:07 +00:00

QMs now have working url to survexfile & tick description

This commit is contained in:
Philip Sargent
2022-07-20 14:44:56 +03:00
parent 2a7f1506c9
commit 549c1649b4
6 changed files with 91 additions and 54 deletions

View File

@@ -9,14 +9,16 @@ from troggle.core.models.troggle import DataIssue
from troggle.core.models.caves import QM, Cave, LogbookEntry
from troggle.core.utils import save_carefully
'''Reads the CSV files containg QMs for a select few caves'''
'''Reads the CSV files containg QMs for a select few caves
See parsers/survex.py for the parser which extracts QMs from the survex files
'''
def deleteQMs():
QM.objects.all().delete()
DataIssue.objects.filter(parser='QMs').delete()
def parseCaveQMs(cave,inputFile):
def parseCaveQMs(cave, inputFile, ticked=False):
"""Runs through the CSV file at inputFile (which is a relative path from expoweb) and
saves each QM as a QM instance.
This is creating and linking a Placeholder logbookentry dated 1st Jan. in the relevant
@@ -59,7 +61,7 @@ def parseCaveQMs(cave,inputFile):
message = f' ! - {qmPath} KH is not in the database. Please run cave parser'
print(message)
DataIssue.objects.create(parser='QMs', message=message)
nqms = parse_KH_QMs(kh, inputFile=inputFile)
nqms = parse_KH_QMs(kh, inputFile=inputFile, ticked=ticked)
return nqms
#qmPath = settings.EXPOWEB+inputFile
@@ -77,16 +79,6 @@ def parseCaveQMs(cave,inputFile):
n += 1
year=int(line[0][1:5])
logslug = f'PH_{int(year)}_{int(n):02d}'
# logbook placeholder code was previously here. No longer needed.
#check if placeholder exists for given year, create it if not
# message = " ! - "+ str(year) + " logbook: placeholder entry for '" + cave + "' created. DUMMY EXPEDITION ID. Should be re-attached to the actual trip."
# if cave=='204-steinBH':
# placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, place="204", title="placeholder for QMs in 204", text=message, entry_type="DUMMY", expedition_id=1, defaults={"date": date(year, 1, 1),"cave_slug":str(steinBr), "slug": logslug})
# elif cave=='234-Hauch':
# placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, place="234", title="placeholder for QMs in 234", text=message, entry_type="DUMMY", expedition_id=1, defaults={"date": date(year, 1, 1),"cave_slug":str(hauchHl)})
# # if hadToCreate:
# # print(message)
# # DataIssue.objects.create(parser='QMs', message=message)
QMnum=re.match(r".*?-\d*?-X?(?P<numb>\d*)",line[0]).group("numb")
newQM = QM()
# newQM.found_by=placeholder
@@ -100,12 +92,13 @@ def parseCaveQMs(cave,inputFile):
newQM.area=line[2]
newQM.location_description=line[3]
# Troggle will in future (?! - written in 2006) check if QMs are completed by checking if they have a ticked_off_by trip.
# In the table, completion is indicated by the presence of a completion discription.
# In the table, completion is indicated by the presence of a completion discription.
newQM.completion_description=line[4]
newQM.nearest_station_description=line[5]
# if newQM.completion_description:
# newQM.ticked_off_by=placeholder
if newQM.completion_description:
newQM.ticked = True
else:
newQM.ticked = False
newQM.comment=line[6]
try:
@@ -134,7 +127,7 @@ def parseCaveQMs(cave,inputFile):
continue
return nqms
def parse_KH_QMs(kh, inputFile):
def parse_KH_QMs(kh, inputFile, ticked):
"""import QMs from the 1623-161 (Kaninchenhohle) html pages, different format
"""
khQMs=open(os.path.join(settings.EXPOWEB, inputFile),'r')
@@ -161,12 +154,13 @@ def parse_KH_QMs(kh, inputFile):
'grade':res['grade']
}
nonLookupArgs={
'ticked': ticked,
'nearest_station_name':res['nearest_station'],
'location_description':res['description']
}
instance, created = save_carefully(QM,lookupArgs,nonLookupArgs)
# if created:
# message = " ! - "+ instance.code() + " QM entry for '161 KH' created. "
# message = f" ! - {instance.code()} QM entry for '161 KH' created. ticked: {ticked}"
# print(message)
# DataIssue.objects.create(parser='QMs', message=message)
nqms += 1
@@ -177,8 +171,9 @@ def Load_QMs():
deleteQMs()
n204 = parseCaveQMs(cave='204-steinBH',inputFile=r"1623/204/qm.csv")
n234 = parseCaveQMs(cave='234-Hauch',inputFile=r"1623/234/qm.csv")
n161 = parseCaveQMs(cave='161-KH', inputFile="1623/161/qmtodo.htm")
n161 = parseCaveQMs(cave='161-KH', inputFile="1623/161/qmtodo.htm", ticked=False)
t161 = parseCaveQMs(cave='161-KH', inputFile="1623/161/qmdone.htm", ticked=True)
#parseCaveQMs(cave='balkonhoehle',inputFile=r"1623/264/qm.csv")
print(f" - Imported: {n204} QMs for 204, {n234} QMs for 234, {n161} QMs for 161.")
print(f" - Imported: {n204} QMs for 204, {n234} QMs for 234, {t161} QMs for 161 done, {n161} QMs for 161 not done.")
print ()