2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-17 04:57:03 +00:00

refactoring wallets and expos survey lengths code

This commit is contained in:
2025-06-30 12:05:54 +03:00
parent 823ef5b7e7
commit 8d901efdfc
4 changed files with 50 additions and 50 deletions

View File

@@ -15,21 +15,12 @@ from troggle.parsers.people import GetPersonExpeditionNameLookup, foreign_friend
# from django.views.generic.list import ListView
"""Very simple report pages summarizing data about the whole set of expeditions and of
the status of data inconsistencies
the status of data inconsistencies. Also the wallets summary report.
"""
def svxfilewild(request, year=None):
"""Looks for survexfiles which do not have an associated
wallet, per year
"""
def legs_by_expo(expos):
legsbyexpo = []
addupsurvexlength = 0.0
addupsurvexlegs = 0
if not year:
expos = Expedition.objects.all()
else:
expos = Expedition.objects.filter(year=year)
for expedition in expos:
survexblocks = expedition.survexblock_set.all()
@@ -42,7 +33,9 @@ def svxfilewild(request, year=None):
addupsurvexlegs += legsyear
legsbyexpo.append((expedition, {"nsurvexlegs": legsyear, "survexleglength": survexleglength}))
legsbyexpo.reverse()
return legsbyexpo, addupsurvexlegs, addupsurvexlength
def legs_and_lengths(expos):
svxwild = []
svxforeign = []
wildlength = 0.0
@@ -66,6 +59,23 @@ def svxfilewild(request, year=None):
for p in people:
team.append(p.personname)
sb.team = team
return svxwild, svxforeign, wildlength, foreignlength
def svxfilewild(request, year=None):
"""Looks for survexfiles which do not have an associated
wallet, per year. This should not be in this file, but with the other wallets reports.
"""
if not year:
expos = Expedition.objects.all()
else:
expos = Expedition.objects.filter(year=year)
legsbyexpo, addupsurvexlegs, addupsurvexlength = legs_by_expo(expos)
svxwild, svxforeign, wildlength, foreignlength = legs_and_lengths(expos)
walletslength = 0.0
if year:
wallets = Wallet.objects.filter(walletyear__year=year)
@@ -73,7 +83,7 @@ def svxfilewild(request, year=None):
for sb in w.survexblock_set.all():
walletslength += sb.legslength
if not year:
year = current_expo()
year = " - all years"
return render(request, "survexfilewild.html",
{"addupsurvexlength": addupsurvexlength / 1000,
"legsbyexpo": legsbyexpo,
@@ -86,7 +96,27 @@ def svxfilewild(request, year=None):
"svxwild": svxwild,
"svxforeign": svxforeign}
)
def stats(request):
"""Calculates number of survey blocks, the number of survey legs and the survey length for each year.
This is only underground survey legs, but includes ARGE as well as Expo survex files.
"""
statsDict = {}
statsDict["expoCount"] = f"{Expedition.objects.count():,}"
statsDict["caveCount"] = f"{Cave.objects.count():,}"
statsDict["personCount"] = f"{Person.objects.count():,}"
statsDict["walletsCount"] = f"{Wallet.objects.count():,}"
statsDict["logbookEntryCount"] = f"{LogbookEntry.objects.count():,}"
expos = Expedition.objects.all()
legsbyexpo, addupsurvexlegs, addupsurvexlength = legs_by_expo(expos)
renderDict = {
**statsDict,
**{"addupsurvexlength": addupsurvexlength / 1000, "legsbyexpo": legsbyexpo, "nsurvexlegs": addupsurvexlegs, "year": current_expo()},
} # new syntax
return render(request, "statistics.html", renderDict)
def therionissues(request):
"""Page displaying contents of a file produced during data import"""
logname = "therionrefs.log"
@@ -229,36 +259,6 @@ def pathsreport(request):
)
def stats(request):
"""Calculates number of survey blocks, the number of survey legs and the survey length for each year.
This is only underground survey legs, but includes ARGE as well as Expo survex files.
"""
statsDict = {}
statsDict["expoCount"] = f"{Expedition.objects.count():,}"
statsDict["caveCount"] = f"{Cave.objects.count():,}"
statsDict["personCount"] = f"{Person.objects.count():,}"
statsDict["logbookEntryCount"] = f"{LogbookEntry.objects.count():,}"
legsbyexpo = []
addupsurvexlength = 0.0
addupsurvexlegs = 0
for expedition in Expedition.objects.all():
survexblocks = expedition.survexblock_set.all()
legsyear = 0
survexleglength = 0.0
for survexblock in survexblocks:
survexleglength += survexblock.legslength
legsyear += int(survexblock.legsall)
addupsurvexlength += survexleglength
addupsurvexlegs += legsyear
legsbyexpo.append((expedition, {"nsurvexlegs": legsyear, "survexleglength": survexleglength}))
legsbyexpo.reverse()
renderDict = {
**statsDict,
**{"addupsurvexlength": addupsurvexlength / 1000, "legsbyexpo": legsbyexpo, "nsurvexlegs": addupsurvexlegs, "year": current_expo()},
} # new syntax
return render(request, "statistics.html", renderDict)
def dataissues(request):