2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-15 14:07:14 +00:00

fixed survey station casesensitivity

This commit is contained in:
2025-07-20 16:57:58 +02:00
parent 5770a9b2e7
commit 29840aabff
3 changed files with 101 additions and 92 deletions

View File

@@ -128,9 +128,38 @@ def validate_entrance_stations(ent=None):
return
so = SurvexStation.objects.filter(name=station.lower())
if so.count() == 1:
message = f"X - Entrance {ent} station '{station}' should be '{station.lower()}'"
message = f" X - Entrance {ent} station text '{station}' should be '{station.lower()}' to match created SurvexStation"
stash_data_issue(parser="positions", message=message, url=url)
print(message)
def find_station(station, ent_type):
nonlocal url
if not station:
return False
try:
if SurvexStation.objects.filter(name=station).count() == 1:
return True
except:
message = f" ! - Entrance {ent} has invalid '{ent_type}' station '{station}'. EXCEPTION."
stash_data_issue(parser="positions", message=message, url=url)
print(message)
bads +=1
return False
candidates = [station.lower(), station.upper()]
for stn in candidates:
if SurvexStation.objects.filter(name=stn).count() == 1:
message = f" # - Entrance {ent} has '{ent_type}' station '{station}'. with incorrect capitalisation {stn}"
stash_data_issue(parser="positions", message=message, url=url)
print(message)
return True
message =f" ! - No items found for Entrance {ent} '{ent_type}' station '{station}"
stash_data_issue(parser="positions", message=message, url=url)
print(message)
return False
def validate_ent(ent):
"""For each of the two station strings in an Entrance object,
@@ -153,37 +182,15 @@ def validate_entrance_stations(ent=None):
else:
print(f"BUGGER bad cave '{cavelist}' on Entrance object {ent} ")
url="/caves"
for st, ent_type in {ent.other_station: "other", ent.tag_station: "tag"}.items():
if st == "":
for stn, ent_type in {ent.other_station: "other", ent.tag_station: "tag"}.items():
if stn == "":
continue
try:
so = SurvexStation.objects.filter(name=st)
except:
message = f" ! - Entrance {ent} has invalid '{ent_type}' station '{st}'. EXCEPTION."
stash_data_issue(parser="positions", message=message, url=url)
print(message)
bads +=1
continue
if so.count() == 1:
if find_station(stn, ent_type):
good +=1
# print(f"OK - Entrance {ent} '{ent_type}' station '{st}'")
continue
if so.count() != 0:
message =f"{so.count()} found for Entrance {ent} '{ent_type}' station '{st}' {so}"
else:
# not found
message = f" ! - Entrance {ent} '{ent_type}' station '{st}' not found as a registered SurvexStation"
if st == ent.best_station():
message = message + " - AND THIS IS THE 'BEST' ONE"
else:
message = message + " - not the 'best'"
stash_data_issue(parser="positions", message=message, url=url)
print(message)
bads +=1
station_lower_case(st)
continue
bads +=1
if ent:
return validate_ent(ent)
@@ -241,65 +248,65 @@ def LoadPositions():
SurvexStation.objects.all().delete()
# def runcavern3d(msg=None):
# if msg:
# print(" - ", msg)
# outputdir = Path(str(f"{topdata}.svx")).parent
# file3d = Path(f"{topdata}.3d")
# try:
# sp = subprocess.run(
# [settings.CAVERN, "--log", f"--output={outputdir}", f"{topdata}.svx"],
# capture_output=True,
# check=False,
# text=True,
# ) # check=False means exception not raised
# if sp.returncode != 0:
# message = f" ! Error: cavern: creating {file3d} in runcavern3()"
# stash_data_issue(parser="positions", message=message)
# print(message)
def runcavern3d(msg=None):
if msg:
print(" - ", msg)
outputdir = Path(str(f"{topdata}.svx")).parent
file3d = Path(f"{topdata}.3d")
try:
sp = subprocess.run(
[settings.CAVERN, "--log", f"--output={outputdir}", f"{topdata}.svx"],
capture_output=True,
check=False,
text=True,
) # check=False means exception not raised
if sp.returncode != 0:
message = f" ! Error: cavern: creating {file3d} in runcavern3()"
stash_data_issue(parser="positions", message=message)
print(message)
# # find the errors in the .log file
# sp = subprocess.run(
# ["grep", "error:", f"{topdata}.log"], capture_output=True, check=False, text=True
# ) # check=False means exception not raised
# message = f" ! Error: cavern: {sp.stdout} creating {file3d} "
# stash_data_issue(parser="positions", message=message)
# print(message)
# find the errors in the .log file
sp = subprocess.run(
["grep", "error:", f"{topdata}.log"], capture_output=True, check=False, text=True
) # check=False means exception not raised
message = f" ! Error: cavern: {sp.stdout} creating {file3d} "
stash_data_issue(parser="positions", message=message)
print(message)
# except:
# message = f" ! CalledProcessError 'cavern' in runcavern3() at {topdata}."
# stash_data_issue(parser="positions", message=message)
# print(message)
except:
message = f" ! CalledProcessError 'cavern' in runcavern3() at {topdata}."
stash_data_issue(parser="positions", message=message)
print(message)
# if file3d.is_file():
# message = f" ! CalledProcessError. File permissions {file3d.stat().st_mode} on {str(file3d)}"
# stash_data_issue(parser="positions", message=message)
# print(message)
if file3d.is_file():
message = f" ! CalledProcessError. File permissions {file3d.stat().st_mode} on {str(file3d)}"
stash_data_issue(parser="positions", message=message)
print(message)
# if file3d.is_file(): # might be an old one though, if previous step failed
# try:
# sp = subprocess.run(
# [settings.SURVEXPORT, "--pos", f"{file3d}"],
# cwd=settings.SURVEX_DATA,
# capture_output=True,
# check=False,
# text=True,
# )
# if sp.returncode != 0:
# print(
# f" ! Error: survexport creating {topdata}.pos in runcavern3().\n\n"
# + str(sp.stdout)
# + "\n\nreturn code: "
# + str(sp.returncode)
# )
# except:
# message = f" ! CalledProcessError 'survexport' in runcavern3() at {file3d}."
# stash_data_issue(parser="positions", message=message)
# print(message)
# else:
# message = f" ! Failed to find {file3d} so aborting generation of new .pos, using old one if present"
# stash_data_issue(parser="positions", message=message)
# print(message)
if file3d.is_file(): # might be an old one though, if previous step failed
try:
sp = subprocess.run(
[settings.SURVEXPORT, "--pos", f"{file3d}"],
cwd=settings.SURVEX_DATA,
capture_output=True,
check=False,
text=True,
)
if sp.returncode != 0:
print(
f" ! Error: survexport creating {topdata}.pos in runcavern3().\n\n"
+ str(sp.stdout)
+ "\n\nreturn code: "
+ str(sp.returncode)
)
except:
message = f" ! CalledProcessError 'survexport' in runcavern3() at {file3d}."
stash_data_issue(parser="positions", message=message)
print(message)
else:
message = f" ! Failed to find {file3d} so aborting generation of new .pos, using old one if present"
stash_data_issue(parser="positions", message=message)
print(message)
topdata = Path(settings.SURVEX_DATA, settings.SURVEX_TOPNAME)
print(f" - Generating a list of Pos from {topdata}.3d and then loading...")
@@ -316,8 +323,8 @@ def LoadPositions():
d3dpath = topdata.with_suffix(".3d")
pospath = topdata.with_suffix(".pos")
# we do not need to do this as the previous 'survex' step in databaseReset generated the .3d and .pos file
# runcavern3d(f"Regen {settings.DEVSERVER=}") # always regenerate .3d and .pos as the *includes may have changed
runcavern3d(f"Regenerating .pos file {settings.DEVSERVER=}") # always regenerate .3d and .pos as the *includes may have changed
mappoints = {}
found_points = {}

View File

@@ -2272,17 +2272,17 @@ def FindAndLoadSurvex():
# In fact we always want to run this, and the location stuff later needs the .pos file
# so we should not be using the RunSurvexIfNeeded function.
print(f" - Running cavern on '{fullpathtotop}'", file=sys.stderr)
print(f" - Running cavern on fullpathtotop : '{fullpathtotop}'", file=sys.stderr)
logpath = Path(fullpathtotop + ".log")
try:
print(
f" - Regenerating cavern .pos .log and .3d for '{fullpathtotop}'\n at '{logpath}'\n"
f" - Regenerating cavern .log and .3d for '{fullpathtotop}'\n at '{logpath}'\n"
)
outputdir = Path(str(f"{fullpathtotop}.svx")).parent
sp = subprocess.run(
[settings.CAVERN, "--log", "--pos", f"--output={outputdir}", f"{fullpathtotop}.svx"],
[settings.CAVERN, "--log", f"--output={outputdir}", f"{fullpathtotop}.svx"],
capture_output=True,
check=False,
text=True,

View File

@@ -143,7 +143,7 @@ Nope, it is not useful, removing it... Philip S.
<h2>Entrances</h2>
<ol>
{% for ent in cave.entrances %}
<li>
<br /><li>
Id letter: '{{ ent.entranceletter|safe}}'
{% if ent.entrance.name %}
{{ ent.entrance.name|safe }}
@@ -201,10 +201,12 @@ and the appropriate <var>*equate</var> and <var>*entrance</var> fields in the su
to equate <var>p{{ ent.entrance.name|lower|safe }}</var> to the actual survey station. The WGS84 fields on the entrance edit form would be deleted, and a Tag/Other survex station id to <var>{{cave.areacode}}.p{{ ent.entrance.name|lower|safe }} </var>used instead.
{% endif %}
{% if ent.entrance.tag_station %}
<dt>Tag Location</dt><dd>{{ ent.entrance.tag_station }} <a href="https://www.openstreetmap.org/?mlat={{ ent.entrance.tag.latlong.0}}&mlon={{ent.entrance.tag.latlong.1}}">{{ ent.entrance.tag.latlong.0|floatformat:5 }}N {{ ent.entrance.tag.latlong.1|floatformat:5 }}E</a> (UTM33 {{ ent.entrance.tag.x|floatformat:0 }}, {{ ent.entrance.tag.y|floatformat:0 }}), {{ ent.entrance.tag.z|floatformat:0 }}m (SRTM is {{ ent.entrance.tag.srtm_diff.0|safe }} m, distance from reference: {{ent.entrance.tag.srtm_alt.1|floatformat:0}}m)
<dt>Tag Location</dt><dd>{{ ent.entrance.tag_station }} <a href="https://www.openstreetmap.org/?mlat={{ ent.entrance.tag.latlong.0}}&mlon={{ent.entrance.tag.latlong.1}}#map=19/{ ent.entrance.tag.latlong.0}}/{ ent.entrance.tag.latlong.1}}&layers=P">{{ ent.entrance.tag.latlong.0|floatformat:5 }}N {{ ent.entrance.tag.latlong.1|floatformat:5 }}E</a> (UTM33 {{ ent.entrance.tag.x|floatformat:0 }}, {{ ent.entrance.tag.y|floatformat:0 }}), {{ ent.entrance.tag.z|floatformat:0 }}m (SRTM is {{ ent.entrance.tag.srtm_diff.0|safe }} m, distance from reference: {{ent.entrance.tag.srtm_alt.1|floatformat:0}}m)
<a href="https://osmand.net/map/?pin={{ ent.entrance.tag.latlong.0}},{{ ent.entrance.tag.latlong.1}}#20/{{ ent.entrance.tag.latlong.0|floatformat:7}}/{{ent.entrance.tag.latlong.1|floatformat:7}}">OSMand</a>
<a href="https://osmand.net/map/?pin={{ ent.entrance.tag.latlong.0}},{{ ent.entrance.tag.latlong.1}}#20/{{ ent.entrance.tag.latlong.0|floatformat:7}}/{{ent.entrance.tag.latlong.1|floatformat:7}}">OSMand</a>
<a href="https://www.bing.com/maps/?cp={{ ent.entrance.tag.latlong.0}}%7E{{ ent.entrance.tag.latlong.1}}&lvl=20&style=h">Bing satellite</a>
</dd>
{% endif %}
{% if ent.entrance.bearings %}