2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-23 15:51:52 +00:00
troggle/core/views_statistics.py

93 lines
3.3 KiB
Python
Raw Normal View History

2020-06-12 18:10:07 +01:00
import datetime
import os.path
import re
import django.db.models
from django.db.models import Min, Max
from django.shortcuts import render, render_to_response
from django.template import Context, loader
from django.template.defaultfilters import slugify
from django.utils import timezone
from django.views.generic.list import ListView
from troggle.core.models import Expedition, Person, PersonExpedition
from troggle.core.models_caves import Cave, LogbookEntry
2020-06-24 14:10:13 +01:00
from troggle.core.models_survex import SurvexBlock
2020-06-12 18:10:07 +01:00
import troggle.settings as settings
def pathsreport(request):
pathsdict={
"CAVEDESCRIPTIONS" : settings.CAVEDESCRIPTIONS,
"DIR_ROOT" : settings.DIR_ROOT,
"ENTRANCEDESCRIPTIONS" : settings.ENTRANCEDESCRIPTIONS,
"EXPOUSER_EMAIL" : settings.EXPOUSER_EMAIL,
2020-06-12 18:10:07 +01:00
"EXPOUSERPASS" :"<redacted>",
"EXPOUSER" : settings.EXPOUSER,
"EXPOWEB" : settings.EXPOWEB,
"EXPOWEB_URL" : settings.EXPOWEB_URL,
"FILES" : settings.FILES,
"JSLIB_URL" : settings.JSLIB_URL,
"LOGFILE" : settings.LOGFILE,
"LOGIN_REDIRECT_URL" : settings.LOGIN_REDIRECT_URL,
"MEDIA_ROOT" : settings.MEDIA_ROOT,
"MEDIA_URL" : settings.MEDIA_URL,
"PHOTOS_URL" : settings.PHOTOS_URL,
"PYTHON_PATH" : settings.PYTHON_PATH,
"REPOS_ROOT_PATH" : settings.REPOS_ROOT_PATH,
"ROOT_URLCONF" : settings.ROOT_URLCONF,
"STATIC_URL" : settings.STATIC_URL,
"SURVEX_DATA" : settings.SURVEX_DATA,
"SURVEY_SCANS" : settings.SURVEY_SCANS,
"SURVEYS" : settings.SURVEYS,
"SURVEYS_URL" : settings.SURVEYS_URL,
"THREEDCACHEDIR" : settings.THREEDCACHEDIR,
"TUNNEL_DATA" : settings.TUNNEL_DATA,
"URL_ROOT" : settings.URL_ROOT
2020-06-12 18:10:07 +01:00
}
2020-06-14 10:05:25 +01:00
# settings are unique by paths are not
2020-06-12 18:10:07 +01:00
ncodes = len(pathsdict)
bycodeslist = sorted(pathsdict.items())
2020-06-14 10:05:25 +01:00
# create a temporary list
bypathslist = []
# iterate through the dictionary and append each tuple into the temporary list
for key, value in pathsdict.items():
tmptuple = (key, value)
bypathslist.append(tmptuple)
# bypathslist = sorted(bypathslist)
2020-06-12 18:10:07 +01:00
return render(request, 'pathsreport.html', {
"pathsdict":pathsdict,
"bycodeslist":bycodeslist,
"bypathslist":bypathslist,
"ncodes":ncodes})
def stats(request):
statsDict={}
statsDict['expoCount'] = "{:,}".format(Expedition.objects.count())
statsDict['caveCount'] = "{:,}".format(Cave.objects.count())
statsDict['personCount'] = "{:,}".format(Person.objects.count())
statsDict['logbookEntryCount'] = "{:,}".format(LogbookEntry.objects.count())
legsbyexpo = [ ]
addupsurvexlength = 0
for expedition in Expedition.objects.all():
survexblocks = expedition.survexblock_set.all()
legsyear=0
survexleglength = 0.0
for survexblock in survexblocks:
2020-07-04 13:31:46 +01:00
survexleglength += survexblock.legslength
2020-06-12 18:10:07 +01:00
try:
2020-06-16 19:27:32 +01:00
legsyear += int(survexblock.legsall)
2020-06-12 18:10:07 +01:00
except:
pass
addupsurvexlength += survexleglength
legsbyexpo.append((expedition, {"nsurvexlegs": "{:,}".format(legsyear),
"survexleglength":"{:,.0f}".format(survexleglength)}))
legsbyexpo.reverse()
2020-07-04 13:31:46 +01:00
renderDict = {**statsDict, **{ "addupsurvexlength":addupsurvexlength/1000, "legsbyexpo":legsbyexpo }} # new syntax
2020-06-12 18:10:07 +01:00
return render(request,'statistics.html', renderDict)