2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-25 08:41:51 +00:00

Fixing inherited *date into sub-blocks

This commit is contained in:
Philip Sargent 2023-03-14 02:12:28 +00:00
parent b428a87f1a
commit 85fab88ac9
5 changed files with 55 additions and 22 deletions

View File

@ -162,8 +162,9 @@ class QM(TroggleModel):
("B", "B: Average lead"),
("C", "C: Tight unpromising lead"),
("D", "D: Dig"),
("X", "X: Unclimbable aven"),
) # also seen "?" and "V" in imported data - see urls.py
("X", "X: Unclimbable or horrid"),
("V", "V: Vertical"),
) # also seen "?" in imported data - see urls.py
grade = models.CharField(max_length=1, choices=GRADE_CHOICES)
location_description = models.TextField(blank=True)
nearest_station_description = models.CharField(max_length=400, blank=True, null=True)

View File

@ -344,6 +344,7 @@ def svx(request, survex_file):
# collect all the survex blocks which actually have a valid date
if svxfile:
has_3d = (Path(survexdatasetpath) / Path(survex_file + ".3d")).is_file()
try:
svxblocks = svxfile.survexblock_set.filter(date__isnull=False).order_by('date')
except:
@ -353,12 +354,14 @@ def svx(request, survex_file):
svxlength = 0.0
for b in svxblocksall:
svxlength += b.legslength
print(svxlength,b, b.legsall)
# print(svxlength,b, b.legsall)
except AttributeError: # some survexfiles just *include files and have no blocks themselves
svxblocksall = []
else:
svxblocks = []
svxblocksall = []
svxlength = 0.0
has_3d = False
if not difflist:
difflist = ["Survex file does not exist yet"]
@ -368,7 +371,7 @@ def svx(request, survex_file):
vmap = {
"settings": settings,
"warning": warning,
"has_3d": (Path(survexdatasetpath) / Path(survex_file + ".3d")).is_file(),
"has_3d": has_3d,
"title": survex_file,
"svxlength": svxlength,
"svxblocks": svxblocks,

View File

@ -333,8 +333,8 @@ class LoadingSurvex:
caverndate = None
currentteam = set()
inheritteam = set()
currentdate = set()
inheritdate = set()
currentdate = None
inheritdate = None
pending = []
adhocload = False
@ -381,12 +381,13 @@ class LoadingSurvex:
return self.inheritteam
def fix_undated(self, survexblock):
"""Called when we reach *end of a block
"""Called when we reach *end of a block OR when a QM is seen.
Checks to see if the block has no *date, in which case it uses the
inherited date.
This is fine if the inherited date is from the same SurvexFile,
but inheriting dates across *include files is almost certainly NOT
expected behaviour, even though it is syntactically "correct".
expected behaviour, even though it is syntactically "correct",
so triggers a Warning.
"""
if survexblock.parent.name == "troggle_unseens":
# Bolluxed up if we try to inherit from this random junk, so don't.
@ -394,19 +395,38 @@ class LoadingSurvex:
if self.currentdate:
# already set
if not survexblock.date:
# error
message = (
f"! no survexblock.date but currentdate is set. ({survexblock})-{survexblock.survexfile.path} {self.currentdate=}"
)
print(self.insp + message)
stash_data_issue(
parser="survex", message=message, url=None, sb=(survexblock.survexfile.path)
)
return
if self.inheritdate:
survexblock.date = self.inheritdate
self.currentdate = self.inheritdate # unecessary duplication
# Not an error, so not put in DataIssues, but is printed to debug output
message = (
f"- No *date. INHERITING date from ({survexblock})-{survexblock.survexfile.path} to ({survexblock.parent}) to {self.inheritdate:%Y-%m-%d}"
f"- No *date. INHERITING date from ({survexblock.parent})-{survexblock.parent.survexfile.path} to ({survexblock})-{survexblock.survexfile.path} {self.inheritdate:%Y-%m-%d}"
)
print(self.insp + message)
# stash_data_issue(
# parser="survex", message=message, url=None, sb=(survexblock.survexfile.path)
# parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) # child
# )
survexblock.date = self.inheritdate
self.currentdate = self.inheritdate # unecessary duplication
if survexblock.survexfile != survexblock.parent.survexfile:
# This is noteworthy, however.
message = (
f"- Warning *date INHERITED from DIFFERENT file:\n ({survexblock.parent})-{survexblock.parent.survexfile.path} to ({survexblock})-{survexblock.survexfile.path} {self.inheritdate:%Y-%m-%d}\n {self.stackbegin} {self.inheritdate:%Y-%m-%d}"
)
print(self.insp + message)
stash_data_issue(
parser="survex", message=message, url=None, sb=(survexblock.parent.survexfile.path) # PARENT
)
return self.inheritdate
else:
# This is not an error in the Expo dataset.
@ -583,7 +603,7 @@ class LoadingSurvex:
print(self.insp + message)
stash_data_issue(parser="survexunits", message=message)
def get_expo_from_year(self, year):
def get_expo_from_year(self, year, line, survexblock):
# cacheing to save DB query on every block
if year in self.expos:
expo = self.expos[year]
@ -597,9 +617,14 @@ class LoadingSurvex:
stash_data_issue(
parser="survex", message=message, url=None, sb=(survexblock.survexfile.path)
)
expo = expeditions[0]
self.expos[year] = expo
if expeditions:
expo = expeditions[0]
self.expos[year] = expo
else:
expo = Expedition.objects.get(year="1976")
message = f"! DATE INCORRECT. There is no expedition for the year {year}. {survexblock.survexfile.path} ({survexblock}) - set to 1976."
print(self.insp + message)
stash_data_issue(parser='survex', message=message, url=None, sb=(survexblock.survexfile.path))
return expo
def LoadSurvexDate(self, survexblock, line):
@ -615,9 +640,8 @@ class LoadingSurvex:
*team came before this *date, in which case the names are only in 'pending'"""
global trip_person_record
expo = self.get_expo_from_year(year)
expo = self.get_expo_from_year(year, line, survexblock)
survexblock.expedition = expo
survexblock.save()
team = get_team_on_trip(survexblock) # should be empty, should only be in 'pending'
# team = SurvexPersonRole.objects.filter(survexblock=survexblock)
@ -645,6 +669,7 @@ class LoadingSurvex:
message=message,
url=None, sb=(survexblock.survexfile.path),
)
oline = line
if len(line) > 10:
message = "! DATE Warning LONG DATE '{}' ({}) {}".format(oline, survexblock, survexblock.survexfile.path)
@ -694,7 +719,7 @@ class LoadingSurvex:
if survexblock.date:
# do not actually need a distict variable 'currentdate' but it makes the code clearer
self.currentdate = survexblock.date
survexblock.save()
def LoadSurvexLeg(self, survexblock, sline, comment, svxline):
"""This reads compass, clino and tape data but only keeps the tape lengths,
@ -1585,7 +1610,7 @@ class LoadingSurvex:
self.inheritteam = self.currentteam
self.currentteam = set() # zero the current team when we start a new block
self.inheritdate = self.currentdate
self.currentdate = set() # zero the current date when we start a new block
self.currentdate = None # zero the current date when we start a new block
printbegin()
newsurvexblock = SurvexBlock(
name=blkid,

View File

@ -40,6 +40,8 @@
{% for QM in cave.get_QMs %}
{% if QM.ticked %}
<li><a href="{{QM.get_absolute_url}}">{{QM}}</a>
{% if QM.nearest_station %}&vellip;<em>{{QM.nearest_station}}</em>&vellip;{% endif %}
{% if QM.nearest_station_name %}&vellip;<em>{{QM.nearest_station_name}}</em>&vellip;{% endif %}
{% if QM.nearest_station_description %}&vellip;<em>{{QM.nearest_station_description}}</em>&vellip;{% endif %} {{QM.location_description}} <b>{{QM.grade}}</b>
{% if QM.block %} <a href="/survexfile/{{QM.block.survexfile.path}}.svx">{{QM.block}}.svx</a> {{QM.block.date}} {% endif %}

View File

@ -80,14 +80,16 @@ LOGMESSAGES
-->
{% endif %}
</div>
undergound survey length: {{svxlength|floatformat:2}} metres
<span style="font-family: monospace; font-size: 130%; ">
underground survey length: {{svxlength|floatformat:2}} metres<br />
{% for sb in svxblocks %}
block:({{sb}}) has parent block:<a href="{{sb.parent.path}}">({{sb.parent}})</a>
{% empty %}
Cannot find any <em>dated</em> survex blocks in this survex file (not looking at *include files). <br />
Report this to a nerd if you think this is incorrect.
<hr />
{% endfor %}
<span style="font-family: monospace; font-size: 130%; ">
{% for key, value in events.items %}
{% with trips=value.0 svxothers=value.1 wallets=value.2 blocks=value.3 %}