From 29eae4e9b2fe31d68eebf361578d01ae99f2bdc8 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Fri, 25 Jul 2025 16:06:26 +0200 Subject: [PATCH] fixing resolved QM regex --- databaseReset.py | 7 ++++++- parsers/imports.py | 9 +++++++++ parsers/survex.py | 32 +++++++++++++++++++++++--------- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/databaseReset.py b/databaseReset.py index d7b2c91..51f4ea0 100644 --- a/databaseReset.py +++ b/databaseReset.py @@ -67,6 +67,7 @@ from troggle.parsers.imports import ( import_users, import_QMs, import_survex, + import_justsurvex, import_survex_checks, import_surveyscans, ) @@ -240,6 +241,7 @@ class JobQueue: "scans", "drawings", "survex", + "justsurvex", "test", "TOTAL" ] @@ -258,7 +260,7 @@ class JobQueue: for a specified run in the history""" total = 0 for module in self.results_order: - if module in ["runlabel", "date", "test", "TOTAL"]: + if module in ["runlabel", "date", "test", "TOTAL", "justsurvex"]: continue # print(i, module, f"length={len(self.results[module])} ") if self.results[module][i]: @@ -447,6 +449,7 @@ def usage(): scans - the survey scans in all the wallets (must run before survex) drawings - read in the Tunnel & Therion files - which scans the survey scans too survex - read in the survex files - all the survex blocks and entrances x/y/z + justsurvex- read in and parse just the survex file (does not leave system in usable state) survex_ck - set caves and people on wallets, check wallets for *ref ents - read just the entrances x/y/z (must run after survex) @@ -527,6 +530,8 @@ if __name__ == "__main__": jq.enq("scans", import_surveyscans) elif "survex" in sys.argv: jq.enq("survex", import_survex) + elif "justsurvex" in sys.argv: + jq.enq("justsurvex", import_justsurvex) elif "loadpos" in sys.argv: jq.enq("survex", import_loadpos) elif "drawings" in sys.argv: diff --git a/parsers/imports.py b/parsers/imports.py index 54e2afe..d553941 100644 --- a/parsers/imports.py +++ b/parsers/imports.py @@ -67,6 +67,15 @@ def import_survex(): with transaction.atomic(): troggle.parsers.locations.LoadPositions() + +def import_justsurvex(): + print("-- Importing Just Survex files") + with transaction.atomic(): + import troggle.parsers.survex + print(" - Survex Blocks") + with transaction.atomic(): + troggle.parsers.survex.LoadSurvexBlocks() + def import_survex_checks(): print(" - Survex: check wallet references and set persons, caves") with transaction.atomic(): diff --git a/parsers/survex.py b/parsers/survex.py index 36861d6..d921f39 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -271,6 +271,7 @@ class LoadingSurvex: rx_linelen = re.compile(r"[\d\-+.]+$") # this extensive list of expo roles are now (after 24/2/2025) just comments and not legal survex code. + # all now irrelevant as Olly restricted the list and survex now notices this. roles = "(assistant|bitch|bodger|bolt|bolter|bolting|book|clino|comp|compass|consultant|disto|distox|distox2|" roles += "dog|dogsbody|drawing|drill|gps|helper|inst|instr|instrument|length|monkey|nagging|nail|" roles += "nail_polish|nail_polish_bitch|nail_polish_monkey|nail_varnish|nail_varnish_bitch|note|notebook|" @@ -283,14 +284,7 @@ class LoadingSurvex: rx_teamabs = re.compile(r"(?i)^\s*(" + roles + r")?(?:es|s)?\s*$") rx_teamone = re.compile(r"(?i)^\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]+)\s+([^\s]+)\s+([^\s]+)\s+(.+)$" - ) - # does not recognise non numeric suffix survey point ids - rx_qm0 = re.compile(r"(?i)^\s*QM(\d+)\s+(.+)$") - rx_qm_tick = re.compile(r"(?i)^\s*QM(\d+)\s+TICK\s([\d\-]+)\s(.*)$") - # remember there is also QM_PATTERN used in views.other and set in settings.py + rx_tapelng = re.compile(r"(?i).*(tape|length).*$") rx_cave = re.compile(r"(?i)caves-(\d\d\d\d)/([-\d\w]+|\d\d\d\d-?\w+-\d+)") @@ -309,6 +303,17 @@ class LoadingSurvex: rx_commteam = re.compile(r"(?i)\s*(Messteam|Zeichner|LUSS Dead Mountains)\s*[:]?(.*)") # non-expo survex files rx_quotedtitle = re.compile(r'(?i)^"(.*)"$') + # QM recognizers + # does not recognise non numeric suffix survey point ids + rx_qm0 = re.compile(r"(?i)^\s*QM(\d+)\s+(.+)$") + rx_qm_tick = re.compile(r"(?i)^\s*QM(\d+)\s+TICK\s([\d\-]+)\s(.*)$") + # remember there is also QM_PATTERN used in views.other and set in settings.py + + rx_qm = re.compile( + r"^\s*QM(\d+)\s+([A-DVXa-dvx?])\s+([\w\-\_]+\.)?(([\w\.\-]+))\s*(\-|([\w\-]+)(\.([\w\.\-]+))?)(\s+(.*))$" + ) + # This regex matches a QM survey line where station identifiers and locations may be optional or placeholders. + """ Regular expression explanation for rx_starref (MS CoPilot) - Not actually USED any more ?! @@ -1626,9 +1631,18 @@ class LoadingSurvex: which is a QM new declaration or a QM TICK closing declaration. It _should_ recognise a non-numeric survey station ID, but currently doesn't. - Valid QM types are [a-dA-DvVxX?] A-D, V for Vertical, X for horrible and ? for unknown + Valid QM types are [A-DvVxX?] A-D, V for Vertical, X for horrible and ? for unknown """ # rx_qm : r"(?i)^\s*QM(\d+)\s+?(.+)\s+([\w\-\_]+)(\.([\w\.\-]+)?)\s+(([\w\-]+)\.([\w\.\-]+)|\-)\s+(.+)$) + # This regex parses strings that start with "QM" followed by digits, then extracts several structured parts: + # (?i) : Case-insensitive matching + # ^\s* : Start of line, optional leading whitespace + # QM(\d+) : "QM" followed by a digit sequence (capture group 1) + # \s+?(.+) : Minimal spaces, then a descriptive text (capture group 2) + # \s+([\w\-_]+) : identifier prefix with word characters, hyphen or underscore (capture group 3) + # (\.([\w.\-]+)?) : identifier starting with a dot (capture group 4 and 5) + # \s+(([\w\-]+)\.([\w.\-]+)|\-?) : Either a pair of identifiers separated by a dot or an optional single dash (capture group 6, with 7 & 8 as subgroups) + # \s+(.+)$ : Remaining text at the end (e.g., comments or summary) (capture group 9) qmline = self.rx_qm.match(comment) if qmline: self.LoadSurvexQM(survexblock, qmline)