diff options
Diffstat (limited to 'parsers/locations.py')
-rw-r--r-- | parsers/locations.py | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/parsers/locations.py b/parsers/locations.py index 8384028..b3a318c 100644 --- a/parsers/locations.py +++ b/parsers/locations.py @@ -192,30 +192,42 @@ def LoadPositions(): posfile = open(pospath) posfile.readline() # Drop header - try: - survexblockroot = SurvexBlock.objects.get(name=ROOTBLOCK) - except: - try: - survexblockroot = SurvexBlock.objects.get(id=1) - except: - message = " ! FAILED to find root SurvexBlock" - print(message) - stash_data_issue(parser="entrances", message=message) - raise + + # not used survexblock on a SurvexStation since we stopped storing all of them in 2020: + # try: + # survexblockroot = SurvexBlock.objects.get(name=ROOTBLOCK) + # except: + # try: + # survexblockroot = SurvexBlock.objects.get(id=1) + # except: + # message = " ! FAILED to find root SurvexBlock" + # print(message) + # stash_data_issue(parser="entrances", message=message) + # raise + sbdict = {} + dups = 0 + lineno = 1 # we dropped the header for line in posfile.readlines(): + lineno += 1 r = poslineregex.match(line) if r: - x, y, z, id = r.groups() + x, y, z, sbid = r.groups() # renamed id to sbid so as to not confuse with Django internal .id + if sbid in sbdict: + dups += 1 + message = f" ! DUPLICATE SurvexBlock identifier in .pos file '{sbid}'\n{sbs[sbid]}\n{lineno} / {line}" + print(message) + stash_data_issue(parser="entrances", message=message) + else: + sbdict[sbid] = lineno + for sid in mappoints: - if id.endswith(sid): - blockpath = "." + id[: -len(sid)].strip(".") - # But why are we doing this? Why do we need the survexblock id for each of these ? + if sbid.endswith(sid): + blockpath = "." + sbid[: -len(sid)].strip(".") # only the most recent one that is mappoints + # But why are we doing this? Why do we want the survexblock id for each of these ? # ..because mostly they don't actually appear in any SVX file. We should match them up # via the cave data, not by this half-arsed syntactic match which almost never works. PMS. - # It is pointless linking them all to the root survexblock, they don't need it. - # If there is a link to a survexblock it should be the one the station appears in ! - # But we are reading the .pos file so we only know the SurvexFile not the SurvexBlock.. + # We are reading the .pos file so we only know the SurvexFile not the SurvexBlock. # ghastly. if False: try: @@ -223,29 +235,28 @@ def LoadPositions(): if len(sbqs) == 1: sbqs[0] if len(sbqs) > 1: - message = f" ! MULTIPLE SurvexBlocks {len(sbqs):3} matching Entrance point {blockpath} {sid} '{id}'" + message = f" ! MULTIPLE {len(sbqs):3} SurvexBlocks '{blockpath}' from survex files mention Entrance point '{sbid}' (line {lineno})" print(message) stash_data_issue(parser="entrances", message=message) + for b in sbqs: + print(f" - {b}") sbqs[0] - elif len(sbqs) <= 0: - message = f" ! ZERO SurvexBlocks matching Entrance point {blockpath} {sid} '{id}'" - print(message) - stash_data_issue(parser="entrances", message=message) except: - message = f" ! FAIL in getting SurvexBlock matching Entrance point {blockpath} {sid}" + message = f" ! {lineno} FAIL in getting SurvexBlock matching Entrance point {blockpath} {sid}" print(message) stash_data_issue(parser="entrances", message=message) try: - ss = SurvexStation(name=id, block=survexblockroot) + ss = SurvexStation(name=sbid) ss.x = float(x) ss.y = float(y) ss.z = float(z) ss.save() found += 1 except: - message = f" ! FAIL to create SurvexStation Entrance point {blockpath} {sid}" + message = f" ! {lineno} FAIL to create SurvexStation Entrance point {blockpath} {sid}" print(message) stash_data_issue(parser="entrances", message=message) raise print(f" - {found} SurvexStation entrances found.") + print(f" - {dups} Duplicated SurvexStation entrances found") store_data_issues() |