2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-01-19 09:22:32 +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

View File

@ -12,9 +12,21 @@ from utils import save_carefully
def deleteQMs():
QM.objects.all().delete()
DataIssue.objects.filter(parser='QMs').delete()
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':
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)})
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)})
if hadToCreate:
print(message)
DataIssue.objects.create(parser='QMs', message=message)
# 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
@ -65,9 +77,11 @@ def parseCaveQMs(cave,inputFile):
newQM.area=line[2]
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.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.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
preexistingQM.delete()
newQM.save()
#print((" - overwriting " + str(preexistingQM) +"\r"))
else: # otherwise, print that it was ignored
print((" - preserving " + str(preexistingQM) + ", which was edited in admin \r"))
except QM.DoesNotExist: #if there is no pre-existing QM, save the new one
newQM.save()
# print("QM "+str(newQM) + ' added to database\r')
except KeyError: #check on this one
continue
except IndexError:
print(("Index error in " + str(line)))
print("Index error in " + str(line))
continue
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
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)})
if hadToCreate:
print(message)
DataIssue.objects.create(parser='QMs', message=message)
# if hadToCreate:
# print(message)
# DataIssue.objects.create(parser='QMs', message=message)
lookupArgs={
'found_by':placeholder,
'number':res['number']
@ -119,6 +131,7 @@ def parse_KH_QMs(kh, inputFile):
save_carefully(QM,lookupArgs,nonLookupArgs)
def Load_QMs():
deleteQMs()
parseCaveQMs(cave='204-steinBH',inputFile=r"1623/204/qm.csv")
parseCaveQMs(cave='234-Hauch',inputFile=r"1623/234/qm.csv")
parseCaveQMs(cave='161-KH', inputFile="1623/161/qmtodo.htm")

View File

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