debugging ticklist

This commit is contained in:
Philip Sargent
2022-08-01 02:50:19 +03:00
parent 5da1fce41f
commit 129ea3cc5b
5 changed files with 180 additions and 16 deletions

View File

@@ -1,8 +1,10 @@
import os
import re
import json
import operator
from urllib.parse import urljoin
from pathlib import Path
from functools import reduce
from django.db import models
from django.conf import settings
@@ -177,7 +179,7 @@ class Wallet(models.Model):
def get_json(self):
jsonfile = Path(self.fpath, 'contents.json')
if not Path(jsonfile).is_file():
print(f'{jsonfile} is not a file')
#print(f'{jsonfile} is not a file')
return None
else:
with open(jsonfile) as json_f:
@@ -186,7 +188,7 @@ class Wallet(models.Model):
except:
wurl = f"/scanupload/{self.walletname}" # .replace('#', ':')
message = f"! {str(self.walletname)} Failed to load {jsonfile} JSON file"
print(message)
#print(message)
raise
return waldata
@@ -225,7 +227,118 @@ class Wallet(models.Model):
return None
jsondata = self.get_json()
return jsondata["name"]
def get_fnames(self):
'''Filenames without the suffix, i.e. without the ".jpg"
'''
dirpath = Path(settings.SCANS_ROOT, self.fpath)
files = []
if dirpath.is_dir():
try:
for f in dirpath.iterdir():
if f.is_file():
if f.name != 'contents.json' and f.name != 'walletindex.html':
files.append(Path(f.name).stem)
except FileNotFoundError:
pass
return files
def get_ticks(self):
waldata = self.get_json()
if not waldata:
return {}
ticks = {}
# Initially, are there any required survex files present ?
survexok = "red"
ticks["S"] = "red"
if waldata["survex not required"]:
survexok = "green"
ticks["S"] = "green"
else:
if waldata["survex file"]:
if not type(waldata["survex file"])==list: # a string also is a sequence type, so do it this way
waldata["survex file"] = [waldata["survex file"]]
ngood = 0
nbad = 0
ticks["S"] = "lightblue"
for svx in waldata["survex file"]:
if svx !="":
if (Path(settings.SURVEX_DATA) / svx).is_file():
ngood += 1
else:
nbad += 1
if nbad == 0 and ngood >= 1:
ticks["S"] = "green"
if nbad >= 1 and ngood >= 1:
ticks["S"] = "orange"
if nbad >= 1 and ngood == 0:
ticks["S"] = "red"
# Cave Description
if waldata["description written"]:
ticks["C"] = "green"
else:
ticks["C"] = survexok
# QMs
if waldata["qms written"]:
ticks["Q"] = "green"
else:
ticks["Q"] = survexok
# Notes, Plan, Elevation; Tunnel
if waldata["electronic survey"]:
ticks["N"] = "green"
ticks["P"] = "green"
ticks["E"] = "green"
ticks["T"] = "green"
else:
files = self.get_fnames()
print(self.walletname,files)
# Notes required
notes_scanned = reduce(operator.or_, [f.startswith("note") for f in files], False)
notes_scanned = reduce(operator.or_, [f.endswith("notes") for f in files], notes_scanned)
if notes_scanned:
ticks["N"] = "green"
else:
ticks["N"] = "red"
# Plan drawing required
plan_scanned = reduce(operator.or_, [f.startswith("plan") for f in files], False)
plan_scanned = reduce(operator.or_, [f.endswith("plan") for f in files], plan_scanned)
plan_drawing_required = not (plan_scanned or waldata["plan drawn"] or waldata["plan not required"])
if plan_drawing_required:
ticks["P"] = "red"
else:
ticks["P"] = "green"
# Elev drawing required
elev_scanned = reduce(operator.or_, [f.startswith("elev") for f in files], False)
elev_scanned = reduce(operator.or_, [f.endswith("elev") for f in files], elev_scanned)
elev_scanned = reduce(operator.or_, [f.endswith("elevation") for f in files], elev_scanned)
elev_drawing_required = not (elev_scanned or waldata["elev drawn"] or waldata["elev not required"])
if elev_drawing_required:
ticks["E"] = "red"
else:
ticks["E"] = "green"
# Tunnel / Therion
if elev_drawing_required or plan_drawing_required:
ticks["T"] = "red"
else:
ticks["T"] = "green"
# Website
if waldata["website updated"]:
ticks["W"] = "green"
else:
ticks["W"] = "red"
return ticks
def __str__(self):
return "[" + str(self.walletname) + " (Wallet)]"