2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-26 09:11:54 +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"), ("B", "B: Average lead"),
("C", "C: Tight unpromising lead"), ("C", "C: Tight unpromising lead"),
("D", "D: Dig"), ("D", "D: Dig"),
("X", "X: Unclimbable aven"), ("X", "X: Unclimbable or horrid"),
) # also seen "?" and "V" in imported data - see urls.py ("V", "V: Vertical"),
) # also seen "?" in imported data - see urls.py
grade = models.CharField(max_length=1, choices=GRADE_CHOICES) grade = models.CharField(max_length=1, choices=GRADE_CHOICES)
location_description = models.TextField(blank=True) location_description = models.TextField(blank=True)
nearest_station_description = models.CharField(max_length=400, blank=True, null=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 # collect all the survex blocks which actually have a valid date
if svxfile: if svxfile:
has_3d = (Path(survexdatasetpath) / Path(survex_file + ".3d")).is_file()
try: try:
svxblocks = svxfile.survexblock_set.filter(date__isnull=False).order_by('date') svxblocks = svxfile.survexblock_set.filter(date__isnull=False).order_by('date')
except: except:
@ -353,12 +354,14 @@ def svx(request, survex_file):
svxlength = 0.0 svxlength = 0.0
for b in svxblocksall: for b in svxblocksall:
svxlength += b.legslength 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 except AttributeError: # some survexfiles just *include files and have no blocks themselves
svxblocksall = [] svxblocksall = []
else: else:
svxblocks = [] svxblocks = []
svxblocksall = [] svxblocksall = []
svxlength = 0.0
has_3d = False
if not difflist: if not difflist:
difflist = ["Survex file does not exist yet"] difflist = ["Survex file does not exist yet"]
@ -368,7 +371,7 @@ def svx(request, survex_file):
vmap = { vmap = {
"settings": settings, "settings": settings,
"warning": warning, "warning": warning,
"has_3d": (Path(survexdatasetpath) / Path(survex_file + ".3d")).is_file(), "has_3d": has_3d,
"title": survex_file, "title": survex_file,
"svxlength": svxlength, "svxlength": svxlength,
"svxblocks": svxblocks, "svxblocks": svxblocks,

View File

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

View File

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