more QMs parsed correctly

This commit is contained in:
Philip Sargent 2023-03-18 00:57:40 +00:00
parent 7345e3a328
commit d64948749e
4 changed files with 36 additions and 25 deletions

View File

@ -141,16 +141,26 @@ def parse_KH_QMs(kh, inputFile, ticked):
with open(os.path.join(settings.EXPOWEB, inputFile), "r") as khQMfile:
khQMs = khQMfile.readlines()
nqms = 0
for line in khQMs:
line = 0
fails = 0
for dataline in khQMs:
# <dt><a href="sibria.htm#qC1997-161-27" name="C1997-161-27">C1997-161-27</a> A<dd>Sib: pitch at end of Fuzzy Logic [Paradox Rift - continues] [sep.fuzzy.13]
line += 1
res = re.search(
r"name=\"[CB](?P<year>\d*)-(?P<cave>\d*)-(?P<number>\d*).*</a> (?P<grade>[ABCDX])<dd>(?P<location_description>.*)\[(?P<nearest_station_name>.*)\]",
line,
r"name=\"[CB](?P<year>\d*)-(?P<cave>\d*)-(?P<number>\d*).*</a>\s*(?P<grade>[ABCDX?V])<dd>(?P<location_description>.*)(\[(?P<station_name>.*)\])?",
dataline,
)
if res:
res = res.groupdict()
year = int(res["year"])
nearest_station_name = ""
resolution_station_name = ""
if res["station_name"]:
if ticked:
resolution_station_name = res["station_name"].replace("<a href=\"","<a href=\"/1623/161/")
else:
nearest_station_name = res["station_name"]
lookupAttribs = {
#'found_by':placeholder,
"blockname": "",
@ -163,13 +173,20 @@ def parse_KH_QMs(kh, inputFile, ticked):
"ticked": ticked,
"page_ref": "",
"completion_description": "",
"nearest_station_name": res["nearest_station_name"],
"location_description": res["location_description"],
"nearest_station_name": nearest_station_name,
"resolution_station_name": resolution_station_name,
"location_description": res["location_description"].replace("<a href=\"","<a href=\"/1623/161/"),
}
# Create new. We know it doesn't exist as we deleted evrything when we started.
instance = QM.objects.create(**nonLookupAttribs, **lookupAttribs)
nqms += 1
else:
if dataline.startswith("<dt><a href"):
fails += 1
message = f" ! - {inputFile} line {line} Parse error \n{str(dataline)} "
print(message)
DataIssue.objects.create(parser="QMs", message=message)
print(f" - {fails:2g} parsing errors in {inputFile}")
return nqms

View File

@ -1313,7 +1313,7 @@ class LoadingSurvex:
blockname = survexblock.name
else:
blockname = survexblock.name[:6] + survexblock.name[-1:]
# logslug = f'D{int(qmyear)}_{blockname}_{int(qm_no):03d}'
# logslug = f'D{int(qmyear)}_{blockname}_{int(qm_no):03d}'
qm_ticked = False # default
qm_no = qmline.group(1) # this is NOT unique across multiple survex files
@ -1340,14 +1340,7 @@ class LoadingSurvex:
else:
qm_ticked = True
# print(f"{survexblock.survexfile.cave} {survexblock}:{qm_no}{qm_grade} {qmline.group(4)}", file=sys.stderr)
if resolution_station_name:
qm_ticked = True
# if qmline.group(6) and qmline.group(6) != "-":
# resolution_station_name = qmline.group(6)
# if qmline.group(7):
# resolution_station_name = resolution_station_name + "." + qmline.group(7)
# else:
# resolution_station_name = ""
qm_notes = qmline.group(5)
# qm_notes = qmline.group(8)

View File

@ -27,7 +27,7 @@
<h3>Open leads</h3>
<ul>{% for QM in cave.get_open_QMs %}
<li><a href="{{QM.get_absolute_url}}">{{QM}}</a>
{% if QM.nearest_station_name %}&sect;<em>{{QM.nearest_station_name}}</em>&sect;{% endif %}
{% if QM.nearest_station_name %}&sect;<em>{{QM.nearest_station_name|safe}}</em>&sect;{% 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 %}</li>
{% empty %}
@ -36,13 +36,13 @@
</ul>
&sect; QM.nearest_station_name<br />
&star; QM.resolution_station_name<br />
&star; QM.resolution_station_name - when ticked.<br />
<h3>Ticked off</h3>
<ul>{% for QM in cave.get_ticked_QMs %}
<li><a href="{{QM.get_absolute_url}}">{{QM}}</a>
{% if QM.nearest_station_name %}&sect;<em>{{QM.nearest_station_name}}</em>&sect;{% endif %}
{% if QM.resolution_station_name %}&star;<em>{{QM.resolution_station_name}}</em>&star;{% endif %}
{{QM.location_description}} <b>{{QM.grade}}</b>
{% if QM.nearest_station_name %}&sect;<em>{{QM.nearest_station_name|safe}}</em>&sect;{% endif %}
{% if QM.resolution_station_name %}<b>&star;<em>{{QM.resolution_station_name|safe}}</em>&star;</b>{% endif %}
{{QM.location_description|safe}} <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.completion_description %}
@ -57,5 +57,5 @@
</ul>
</p>
&sect; QM.nearest_station_name<br />
&star; QM.resolution_station_name<br />
&star; QM.resolution_station_name - when ticked.<br />
{% endblock %}

View File

@ -31,17 +31,18 @@ Tick off completion description: '{{qm.completion_description}}' </a> <br />
Tick off url: <a href="/{{qm.get_completion_url}}">{{qm.get_completion_url}}</a> WRONG <br />
Tick off date: '{{qm.completion_date}}' [For survex file ticks. not implemented yet]</a> <br />
{% endif %}
QM page_ref: '{{qm.page_ref}}'<br>
{% if qm.cave %}
<h3>Cave: {{qm.cave|safe }}</h3>
<a href="{% url 'caveQMs' qm.cave|safe %}">All QMs on this cave </a>{{ qm.cave|safe }} <br>
<a href="/{{ qm.cave.url }}"> Cave description </a> {{ qm.cave|safe }}
{{ qm.cave|safe }}<a href="{% url 'caveQMs' qm.cave|safe %}">All QMs </a> <br>
{{ qm.cave|safe }}<a href="/{{ qm.cave.url }}"> description </a> <br />
{{ qm.cave }} <a href="/survexfile/{{ qm.cave.kataster_number }}"> survexfiles </a> <br />
{% else %}
<h3>This QM is OPEN</h3>
Comment: '{{qm.comment}}'</a> <br />
{% endif %}
QM page_ref: '{{qm.page_ref}}'<br>
<h3>QM Number: {{qm.number}} Grade: {{qm.grade}} </h3>