2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-26 01:01:53 +00:00

Remove unused field on survexstation class

This commit is contained in:
Philip Sargent 2023-07-25 18:56:13 +03:00
parent 7d4ca5dae2
commit 5ce21564fc
2 changed files with 48 additions and 36 deletions

View File

@ -86,22 +86,23 @@ class SurvexStationLookUpManager(models.Manager):
class SurvexStation(models.Model): class SurvexStation(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
block = models.ForeignKey("SurvexBlock", null=True, on_delete=models.SET_NULL) # block = models.ForeignKey("SurvexBlock", null=True, on_delete=models.SET_NULL)
# block not used since 2020. survex stations objects are only used for entrnce locations and all taken from the .3d file
objects = SurvexStationLookUpManager() # overwrites SurvexStation.objects and enables lookup() objects = SurvexStationLookUpManager() # overwrites SurvexStation.objects and enables lookup()
x = models.FloatField(blank=True, null=True) x = models.FloatField(blank=True, null=True)
y = models.FloatField(blank=True, null=True) y = models.FloatField(blank=True, null=True)
z = models.FloatField(blank=True, null=True) z = models.FloatField(blank=True, null=True)
def path(self): # def path(self):
r = self.name # r = self.name
b = self.block # b = self.block
while True: # while True:
if b.name: # if b.name:
r = b.name + "." + r # r = b.name + "." + r
if b.parent: # if b.parent:
b = b.parent # b = b.parent
else: # else:
return r # return r
class Meta: class Meta:
ordering = ("id",) ordering = ("id",)

View File

@ -192,30 +192,42 @@ def LoadPositions():
posfile = open(pospath) posfile = open(pospath)
posfile.readline() # Drop header posfile.readline() # Drop header
try:
survexblockroot = SurvexBlock.objects.get(name=ROOTBLOCK) # not used survexblock on a SurvexStation since we stopped storing all of them in 2020:
except: # try:
try: # survexblockroot = SurvexBlock.objects.get(name=ROOTBLOCK)
survexblockroot = SurvexBlock.objects.get(id=1) # except:
except: # try:
message = " ! FAILED to find root SurvexBlock" # survexblockroot = SurvexBlock.objects.get(id=1)
print(message) # except:
stash_data_issue(parser="entrances", message=message) # message = " ! FAILED to find root SurvexBlock"
raise # print(message)
# stash_data_issue(parser="entrances", message=message)
# raise
sbdict = {}
dups = 0
lineno = 1 # we dropped the header
for line in posfile.readlines(): for line in posfile.readlines():
lineno += 1
r = poslineregex.match(line) r = poslineregex.match(line)
if r: 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: for sid in mappoints:
if id.endswith(sid): if sbid.endswith(sid):
blockpath = "." + id[: -len(sid)].strip(".") blockpath = "." + sbid[: -len(sid)].strip(".") # only the most recent one that is mappoints
# But why are we doing this? Why do we need the survexblock id for each of these ? # 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 # ..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. # 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. # We are reading the .pos file so we only know the SurvexFile not the SurvexBlock.
# 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..
# ghastly. # ghastly.
if False: if False:
try: try:
@ -223,29 +235,28 @@ def LoadPositions():
if len(sbqs) == 1: if len(sbqs) == 1:
sbqs[0] sbqs[0]
if len(sbqs) > 1: 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) print(message)
stash_data_issue(parser="entrances", message=message) stash_data_issue(parser="entrances", message=message)
for b in sbqs:
print(f" - {b}")
sbqs[0] 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: 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) print(message)
stash_data_issue(parser="entrances", message=message) stash_data_issue(parser="entrances", message=message)
try: try:
ss = SurvexStation(name=id, block=survexblockroot) ss = SurvexStation(name=sbid)
ss.x = float(x) ss.x = float(x)
ss.y = float(y) ss.y = float(y)
ss.z = float(z) ss.z = float(z)
ss.save() ss.save()
found += 1 found += 1
except: except:
message = f" ! FAIL to create SurvexStation Entrance point {blockpath} {sid}" message = f" ! {lineno} FAIL to create SurvexStation Entrance point {blockpath} {sid}"
print(message) print(message)
stash_data_issue(parser="entrances", message=message) stash_data_issue(parser="entrances", message=message)
raise raise
print(f" - {found} SurvexStation entrances found.") print(f" - {found} SurvexStation entrances found.")
print(f" - {dups} Duplicated SurvexStation entrances found")
store_data_issues() store_data_issues()