2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-21 23:01:52 +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):
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()
x = models.FloatField(blank=True, null=True)
y = models.FloatField(blank=True, null=True)
z = models.FloatField(blank=True, null=True)
def path(self):
r = self.name
b = self.block
while True:
if b.name:
r = b.name + "." + r
if b.parent:
b = b.parent
else:
return r
# def path(self):
# r = self.name
# b = self.block
# while True:
# if b.name:
# r = b.name + "." + r
# if b.parent:
# b = b.parent
# else:
# return r
class Meta:
ordering = ("id",)

View File

@ -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()