2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-13 20:27:05 +00:00

QM reports all working

This commit is contained in:
Philip Sargent
2022-07-06 17:35:08 +03:00
parent 7dc3cc3b91
commit d3572e18c3
5 changed files with 67 additions and 59 deletions

View File

@@ -27,7 +27,11 @@ def parseCaveQMs(cave,inputFile):
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?"""
survex files might be ambiguous. But potentially useful?
Much of this code assumes that QMs are edited using troggle. This is not done so this code can be deleted.
All QMs are created afresh and this is all only run once on import on a fresh database.
"""
if cave=='204-steinBH':
try:
@@ -59,7 +63,7 @@ def parseCaveQMs(cave,inputFile):
return nqms
#qmPath = settings.EXPOWEB+inputFile
qmPath = os.path.join(settings.EXPOWEB, inputFile)
qmPath = os.path.join(settings.EXPOWEB, inputFile) # why not use the pathlib stuff ?
qmCSVContents = open(qmPath,'rU')
dialect=csv.Sniffer().sniff(qmCSVContents.read())
@@ -73,20 +77,22 @@ 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)
# 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
# newQM.found_by=placeholder
newQM.number=QMnum
newQM.cave = caveid
newQM.blockname = ""
if line[1]=="Dig":
newQM.grade="D"
else:
@@ -94,12 +100,12 @@ 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.
# 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.
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_off_by=placeholder
newQM.comment=line[6]
try:
@@ -139,15 +145,16 @@ def parse_KH_QMs(kh, inputFile):
if res:
res=res.groupdict()
year=int(res['year'])
# 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 '161 KH' created. DUMMY EXPEDITION ID. 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, entry_type="DUMMY", expedition_id=1, defaults={"date": date((year), 1, 1),"cave_slug":str(kh)})
# if hadToCreate:
# message = " ! - "+ str(year) + " logbook: placeholder entry for '161 KH' created. DUMMY EXPEDITION ID. 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, entry_type="DUMMY", expedition_id=1, defaults={"date": date((year), 1, 1),"cave_slug":str(kh)})
# # if hadToCreate:
# print(message)
# DataIssue.objects.create(parser='QMs', message=message)
lookupArgs={
# inadequate now that the sequence numbers are not unique for survex-parsed QMs
'found_by':placeholder,
#'found_by':placeholder,
'blockname': "",
'expoyear':year,
'number':res['number'],
'cave': kh,
@@ -158,10 +165,10 @@ def parse_KH_QMs(kh, inputFile):
'location_description':res['description']
}
instance, created = save_carefully(QM,lookupArgs,nonLookupArgs)
if created:
message = " ! - "+ instance.code() + " QM entry for '161 KH' created. "
print(message)
DataIssue.objects.create(parser='QMs', message=message)
# if created:
# message = " ! - "+ instance.code() + " QM entry for '161 KH' created. "
# print(message)
# DataIssue.objects.create(parser='QMs', message=message)
nqms += 1
return nqms