From c247636c4ce2fd352ed59c658b7f2101944208cc Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Tue, 14 Mar 2023 03:27:05 +0000 Subject: [PATCH] Working on QMn TICK lines again --- core/views/survex.py | 2 +- parsers/survex.py | 78 +++++++++++++++++++++++++------------------- 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/core/views/survex.py b/core/views/survex.py index 5115cb7..cdc2d24 100644 --- a/core/views/survex.py +++ b/core/views/survex.py @@ -104,7 +104,7 @@ survextemplatefile = """; *** THIS IS A TEMPLATE FILE NOT WHAT YOU MIGHT BE EXPE ; QM doesn't go anywhere, set the resolution-station to be the same as the ; nearest-station. Include any relevant details of how to find or push the QM in ; the textual description. -;Serial number grade(A/B/C/X) nearest-station resolution-station description +;Serial number grade(A/B/C/D/V/X) nearest-station resolution-station description ;[ QM1 A surveyname.3 - description of QM ] ;[ QM2 B surveyname.5 - description of QM ] diff --git a/parsers/survex.py b/parsers/survex.py index 81500a8..1849fce 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -254,7 +254,8 @@ class LoadingSurvex: rx_teamabs = re.compile(r"(?i)^\s*(" + instruments + ")?(?:es|s)?\s*$") rx_person = re.compile(r"(?i) and |/| / |, | , |&| & | \+ |^both$|^none$") rx_qm = re.compile( - r"(?i)^\s*QM(\d+)\s+(.+)\s+([\w\-\_]+)\.([\w\.\-]+)\s+(([\w\-]+)\.([\w\.\-]+)|\-)\s+(.+)$" +# r"(?i)^\s*QM(\d+)\s+(.+)\s+([\w\-\_]+)\.([\w\.\-]+)\s+(([\w\-]+)\.([\w\.\-]+)|\-)\s+(.+)$" + r"(?i)^\s*QM(\d+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+(.+)$" ) # does not recognise non numeric suffix survey point ids rx_qm0 = re.compile(r"(?i)^\s*QM(\d+)\s+(.+)$") @@ -1272,54 +1273,73 @@ class LoadingSurvex: debugprint = False self.currentsurvexfile.save() self.currentsurvexfile = self.stacksvxfiles.pop() + def TickSurvexQM(self, survexblock, qmtick): """Interpret the specially formatted comment which is a QM TICKED statement""" # Now we need to find the correct QM object. It will be in the same block and have the same number. try: + # could try to search on blockname instead? + # but the QMn TICK has to be in the same block anyway qm = QM.objects.filter(block=survexblock, number=int(qmtick.group(1))) except: # raise - message = f' ! QM TICK find FAIL QM{qmtick.group(1)} date:"{qmtick.group(2)}" qmlist:"{qm}" in "{survexblock.survexfile.path}" + comment:"{qmtick.group(3)}" ' + message = f' ! QM TICK find FAIL QM{qmtick.group(1)} date:"{qmtick.group(2)}" qmlist:"{qm}" in "{survexblock.survexfile.path}" + completion_description:"{qmtick.group(3)}" ' print(message) stash_data_issue( parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) ) if len(qm) > 1: - message = f' ! QM TICK MULTIPLE found FAIL QM{qmtick.group(1)} date:"{qmtick.group(2)}" in "{survexblock.survexfile.path}" + comment:"{qmtick.group(3)}" ' + message = f' ! QM TICK MULTIPLE found FAIL QM{qmtick.group(1)} date:"{qmtick.group(2)}" in "{survexblock.survexfile.path}" + completion_description:"{qmtick.group(3)}" ' print(message) stash_data_issue( parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) ) qm[0].ticked = True + # qm[0].ticked_date = qmtick.group(2) # not in data model yet + qm[0].completion_description = qmtick.group(3) qm[0].save() def LoadSurvexQM(self, survexblock, qmline): """Interpret the specially formatted comment which is a QM definition""" +# r"(?i)^\s*QM(\d+)\s+(.+)\s+([\w\-\_]+)\.([\w\.\-]+)\s+(([\w\-]+)\.([\w\.\-]+)|\-)\s+(.+)$" +# r"(?i)^\s*QM(\d+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+(.+)$" +# rx_qm_tick QMnn TICK date comment +# (r"(?i)^\s*QM(\d+)\s+TICK\s([\d\-]+)\s(.*)$") + insp = self.insp + # create a short, hopefully-unique name for this block to be used in the QM id + blockname = survexblock.name[:6] + survexblock.name[-1:] + # logslug = f'D{int(qmyear)}_{blockname}_{int(qm_no):03d}' qm_no = qmline.group(1) # this is NOT unique across multiple survex files + qm_grade = qmline.group(2).strip().upper() # TICK or [a-dA-DvVxX?] + if qm_grade == "TICK": + self.TickSurvexQM(survexblock, qmline) + return - qm_grade = qmline.group(2).strip().upper() # [a-dA-DvVxX?] if qm_grade not in ["A", "B", "C", "D", "X", "V", "?"]: - message = f" ! QM{qm_no} INVALID code '{qm_grade}' in '{survexblock.survexfile.path}'" + message = f" ! QM{qm_no} INVALID code '{qm_grade}' [{blockname}] '{survexblock.survexfile.path}'" print(insp + message) stash_data_issue( parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) ) - - if qmline.group(3): # usual closest survey station - qm_nearest = qmline.group(3) - if qmline.group(4): - qm_nearest = qm_nearest + "." + qmline.group(4) + qm_nearest = qmline.group(3) + # if qmline.group(3): # usual closest survey station + # qm_nearest = qmline.group(3) + # if qmline.group(4): + # qm_nearest = qm_nearest + "." + qmline.group(4) + + qm_resolve_station = qmline.group(4) + # if qmline.group(6) and qmline.group(6) != "-": + # qm_resolve_station = qmline.group(6) + # if qmline.group(7): + # qm_resolve_station = qm_resolve_station + "." + qmline.group(7) + # else: + # qm_resolve_station = "" + qm_notes = qmline.group(5) + # qm_notes = qmline.group(8) - if qmline.group(6) and qmline.group(6) != "-": - qm_resolve_station = qmline.group(6) - if qmline.group(7): - qm_resolve_station = qm_resolve_station + "." + qmline.group(7) - else: - qm_resolve_station = "" - qm_notes = qmline.group(8) # Spec of QM in SVX files: # ;Serial number grade(A/B/C/D/V/X) nearest-station resolution-station description # ;QM1 a hobnob_hallway_2.42 hobnob-hallway_3.42 junction of keyhole passage @@ -1332,15 +1352,10 @@ class LoadingSurvex: # Older troggle/CSV assumes a logbook entry 'found_by' for each QM, with a date. # We don't need this anymore so we don't need to create a placeholder logbook entry. - - # create a short, hopefully-unique name for this block to be used in the QM id - blockname = survexblock.name[:6] + survexblock.name[-1:] - # logslug = f'D{int(qmyear)}_{blockname}_{int(qm_no):03d}' - + + if survexblock.survexfile.cave: survexblock.survexfile.cave.slug() - else: - pass self.fix_undated(survexblock) # null-op if already set expoyear = str(survexblock.date.year) @@ -1392,16 +1407,11 @@ class LoadingSurvex: if qmline: self.LoadSurvexQM(survexblock, qmline) else: - # rx_qm_tick = re.compile(r"(?i)^\s*QM(\d+)\s+TICK\s([\d\-]+)\s(.*)$") - qmtick = self.rx_qm_tick.match(comment) - if qmtick: - self.TickSurvexQM(survexblock, qmtick) - else: - message = f' ! QM Unrecognised as valid in "{survexblock.survexfile.path}" QM{qml.group(1)} "{qml.group(2)}" : regex failure typo?' - print(message) - stash_data_issue( - parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) - ) + message = f' ! QM Unrecognised as valid in "{survexblock.survexfile.path}" QM{qml.group(1)} "{qml.group(2)}" : regex failure typo?' + print(message) + stash_data_issue( + parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) + ) def LoadSurvexComment(self, survexblock, comment): # ignore all comments except ;ref, ; wallet and ;QM and ;*include (for collated survex file)