2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-03-23 10:41:51 +00:00

QM placeholder logbook entries sorted out

This commit is contained in:
Philip Sargent 2020-07-04 01:10:53 +01:00
parent 5ed6271c08
commit 51d0daafdd
2 changed files with 28 additions and 15 deletions

@ -12,9 +12,21 @@ from utils import save_carefully
def deleteQMs(): def deleteQMs():
QM.objects.all().delete() QM.objects.all().delete()
DataIssue.objects.filter(parser='QMs').delete()
def parseCaveQMs(cave,inputFile): def parseCaveQMs(cave,inputFile):
"""Runs through the CSV file at inputFile (which is a relative path from expoweb) and saves each QM as a QM instance.""" """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
year. This is pointless but it is needed because found_by is a ForeignKey in the db
and we can't be arsed to fudge this properly with a null.(July 2020)
Linking to a passage in a SVX file might be more interesting as the QM does sometimes
have the passage name, e.g. in 204/qm.csv
C2000-204-39 B Tree Pitch in Cave Tree treeumphant.28 Gosser Streamway
The CSV file does not have the exact date for the QM, only the year, so links to
survex files might be ambiguous. But potentially useful?"""
if cave=='204-steinBH': if cave=='204-steinBH':
try: try:
@ -51,9 +63,9 @@ def parseCaveQMs(cave,inputFile):
placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, place="204", title="placeholder for QMs in 204", text=message, defaults={"date": date(year, 1, 1),"cave_slug":str(steinBr)}) placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, place="204", title="placeholder for QMs in 204", text=message, defaults={"date": date(year, 1, 1),"cave_slug":str(steinBr)})
elif cave=='234-Hauch': elif cave=='234-Hauch':
placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, place="234", title="placeholder for QMs in 234", text=message, defaults={"date": date(year, 1, 1),"cave_slug":str(hauchHl)}) placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, place="234", title="placeholder for QMs in 234", text=message, defaults={"date": date(year, 1, 1),"cave_slug":str(hauchHl)})
if hadToCreate: # if hadToCreate:
print(message) # print(message)
DataIssue.objects.create(parser='QMs', message=message) # DataIssue.objects.create(parser='QMs', message=message)
QMnum=re.match(r".*?-\d*?-X?(?P<numb>\d*)",line[0]).group("numb") QMnum=re.match(r".*?-\d*?-X?(?P<numb>\d*)",line[0]).group("numb")
newQM = QM() newQM = QM()
newQM.found_by=placeholder newQM.found_by=placeholder
@ -65,9 +77,11 @@ def parseCaveQMs(cave,inputFile):
newQM.area=line[2] newQM.area=line[2]
newQM.location_description=line[3] newQM.location_description=line[3]
# Troggle checks 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.
newQM.completion_description=line[4] newQM.completion_description=line[4]
newQM.nearest_station_description=line[5] newQM.nearest_station_description=line[5]
if newQM.completion_description: # Troggle checks 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. if newQM.completion_description:
newQM.ticked_off_by=placeholder newQM.ticked_off_by=placeholder
newQM.comment=line[6] newQM.comment=line[6]
@ -76,18 +90,16 @@ def parseCaveQMs(cave,inputFile):
if preexistingQM.new_since_parsing==False: #if the pre-existing QM has not been modified, overwrite it if preexistingQM.new_since_parsing==False: #if the pre-existing QM has not been modified, overwrite it
preexistingQM.delete() preexistingQM.delete()
newQM.save() newQM.save()
#print((" - overwriting " + str(preexistingQM) +"\r"))
else: # otherwise, print that it was ignored else: # otherwise, print that it was ignored
print((" - preserving " + str(preexistingQM) + ", which was edited in admin \r")) print((" - preserving " + str(preexistingQM) + ", which was edited in admin \r"))
except QM.DoesNotExist: #if there is no pre-existing QM, save the new one except QM.DoesNotExist: #if there is no pre-existing QM, save the new one
newQM.save() newQM.save()
# print("QM "+str(newQM) + ' added to database\r')
except KeyError: #check on this one except KeyError: #check on this one
continue continue
except IndexError: except IndexError:
print(("Index error in " + str(line))) print("Index error in " + str(line))
continue continue
def parse_KH_QMs(kh, inputFile): def parse_KH_QMs(kh, inputFile):
@ -103,9 +115,9 @@ def parse_KH_QMs(kh, inputFile):
#check if placeholder exists for given year, create it if not #check if placeholder exists for given year, create it if not
message = " ! - "+ str(year) + " logbook: placeholder entry for '161 KH' created. Should be re-attached to the actual trip." message = " ! - "+ str(year) + " logbook: placeholder entry for '161 KH' created. Should be re-attached to the actual trip."
placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, place="161", title="placeholder for QMs in 161", text=message, defaults={"date": date((year), 1, 1),"cave_slug":str(kh)}) placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, place="161", title="placeholder for QMs in 161", text=message, defaults={"date": date((year), 1, 1),"cave_slug":str(kh)})
if hadToCreate: # if hadToCreate:
print(message) # print(message)
DataIssue.objects.create(parser='QMs', message=message) # DataIssue.objects.create(parser='QMs', message=message)
lookupArgs={ lookupArgs={
'found_by':placeholder, 'found_by':placeholder,
'number':res['number'] 'number':res['number']
@ -119,6 +131,7 @@ def parse_KH_QMs(kh, inputFile):
save_carefully(QM,lookupArgs,nonLookupArgs) save_carefully(QM,lookupArgs,nonLookupArgs)
def Load_QMs(): def Load_QMs():
deleteQMs()
parseCaveQMs(cave='204-steinBH',inputFile=r"1623/204/qm.csv") parseCaveQMs(cave='204-steinBH',inputFile=r"1623/204/qm.csv")
parseCaveQMs(cave='234-Hauch',inputFile=r"1623/234/qm.csv") parseCaveQMs(cave='234-Hauch',inputFile=r"1623/234/qm.csv")
parseCaveQMs(cave='161-KH', inputFile="1623/161/qmtodo.htm") parseCaveQMs(cave='161-KH', inputFile="1623/161/qmtodo.htm")

@ -34,23 +34,23 @@ def import_logbooks():
troggle.parsers.logbooks.LoadLogbooks() troggle.parsers.logbooks.LoadLogbooks()
def import_QMs(): def import_QMs():
print("Importing QMs (old caves)") print("-- Importing old QMs for 161, 204, 234 from CSV files")
troggle.parsers.QMs.Load_QMs() troggle.parsers.QMs.Load_QMs()
def import_survex(): def import_survex():
# when this import is moved to the top with the rest it all crashes horribly # when this import is moved to the top with the rest it all crashes horribly
import troggle.parsers.survex import troggle.parsers.survex
print("-- Importing Survex Blocks") print("-- Importing Survex and Entrance Positions")
print(" - Survex Blocks") print(" - Survex Blocks")
troggle.parsers.survex.LoadSurvexBlocks() troggle.parsers.survex.LoadSurvexBlocks()
print(" - Survex entrances x/y/z Positions") print(" - Survex entrances x/y/z Positions")
troggle.parsers.survex.LoadPos() troggle.parsers.survex.LoadPositions()
def import_loadpos(): def import_loadpos():
# when this import is moved to the top with the rest it all crashes horribly # when this import is moved to the top with the rest it all crashes horribly
import troggle.parsers.survex import troggle.parsers.survex
print(" - Survex entrances x/y/z Positions") print(" - Survex entrances x/y/z Positions")
troggle.parsers.survex.LoadPos() troggle.parsers.survex.LoadPositions()
def import_drawingsfiles(): def import_drawingsfiles():
print("-- Importing Drawings files") print("-- Importing Drawings files")