forked from expo/troggle
124 lines
4.6 KiB
Python
124 lines
4.6 KiB
Python
import datetime
|
|
import os.path
|
|
import re
|
|
|
|
import django.db.models
|
|
from django.db.models import Min, Max
|
|
from django.core.urlresolvers import reverse
|
|
from django.http import HttpResponse, HttpResponseRedirect
|
|
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
|
|
from troggle.core.models_survex import SurvexLeg, SurvexBlock
|
|
|
|
import troggle.settings as settings
|
|
from settings import *
|
|
|
|
|
|
def pathsreport(request):
|
|
pathsdict={
|
|
"ADMIN_MEDIA_PREFIX" : ADMIN_MEDIA_PREFIX,
|
|
"ADMIN_MEDIA_PREFIX" : ADMIN_MEDIA_PREFIX,
|
|
"CAVEDESCRIPTIONSX" : CAVEDESCRIPTIONS,
|
|
"DIR_ROOT" : DIR_ROOT,
|
|
"ENTRANCEDESCRIPTIONS" : ENTRANCEDESCRIPTIONS,
|
|
"EXPOUSER_EMAIL" : EXPOUSER_EMAIL,
|
|
"EXPOUSERPASS" :"<redacted>",
|
|
"EXPOUSER" : EXPOUSER,
|
|
"EXPOWEB" : EXPOWEB,
|
|
"EXPOWEB_URL" : EXPOWEB_URL,
|
|
"FILES" : FILES,
|
|
"JSLIB_URL" : JSLIB_URL,
|
|
"LOGFILE" : LOGFILE,
|
|
"LOGIN_REDIRECT_URL" : LOGIN_REDIRECT_URL,
|
|
"MEDIA_ADMIN_DIR" : MEDIA_ADMIN_DIR,
|
|
"MEDIA_ROOT" : MEDIA_ROOT,
|
|
"MEDIA_URL" : MEDIA_URL,
|
|
#"PHOTOS_ROOT" : PHOTOS_ROOT,
|
|
"PHOTOS_URL" : PHOTOS_URL,
|
|
"PYTHON_PATH" : PYTHON_PATH,
|
|
"REPOS_ROOT_PATH" : REPOS_ROOT_PATH,
|
|
"ROOT_URLCONF" : ROOT_URLCONF,
|
|
"STATIC_ROOT" : STATIC_ROOT,
|
|
"STATIC_URL" : STATIC_URL,
|
|
"SURVEX_DATA" : SURVEX_DATA,
|
|
"SURVEY_SCANS" : SURVEY_SCANS,
|
|
"SURVEYS" : SURVEYS,
|
|
"SURVEYS_URL" : SURVEYS_URL,
|
|
"SVX_URL" : SVX_URL,
|
|
# "TEMPLATE_DIRS" : TEMPLATE_DIRS,
|
|
"THREEDCACHEDIR" : THREEDCACHEDIR,
|
|
# "TINY_MCE_MEDIA_ROOT" : TINY_MCE_MEDIA_ROOT,
|
|
# "TINY_MCE_MEDIA_URL" : TINY_MCE_MEDIA_URL,
|
|
"TUNNEL_DATA" : TUNNEL_DATA,
|
|
"URL_ROOT" : URL_ROOT
|
|
}
|
|
# settings are unique by paths are not
|
|
ncodes = len(pathsdict)
|
|
bycodeslist = sorted(pathsdict.items())
|
|
|
|
# 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)
|
|
|
|
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())
|
|
try:
|
|
blockroots = SurvexBlock.objects.filter(name="rootblock")
|
|
if len(blockroots)>1:
|
|
print(" ! more than one root survexblock {}".format(len(blockroots)))
|
|
for sbr in blockroots:
|
|
print("{} {} {} {}".format(sbr.id, sbr.name, sbr.legsall, sbr.date))
|
|
sbr = blockroots[0]
|
|
totalsurvexlength = sbr.totalleglength
|
|
nimportlegs = sbr.legsall
|
|
except:
|
|
# if no files yet imported into database
|
|
#survexfile = models_survex.SurvexFile(path=settings.SURVEX_TOPNAME, cave=None)
|
|
#survexblockdummy = models_survex.SurvexBlock(name="dummy", survexpath="", cave=None, survexfile=survexfile,
|
|
#legsall=0, legssplay=0, legssurfc=0, totalleglength=0.0)
|
|
#sbr = survexblockdummy
|
|
totalsurvexlength = 0.0
|
|
nimportlegs = -1
|
|
print("{} {} {} {}".format(sbr.id, sbr.name, sbr.legsall, sbr.date))
|
|
|
|
legsbyexpo = [ ]
|
|
addupsurvexlength = 0
|
|
for expedition in Expedition.objects.all():
|
|
survexblocks = expedition.survexblock_set.all()
|
|
legsyear=0
|
|
survexleglength = 0.0
|
|
for survexblock in survexblocks:
|
|
survexleglength += survexblock.totalleglength
|
|
try:
|
|
legsyear += int(survexblock.legsall)
|
|
except:
|
|
pass
|
|
addupsurvexlength += survexleglength
|
|
legsbyexpo.append((expedition, {"nsurvexlegs": "{:,}".format(legsyear),
|
|
"survexleglength":"{:,.0f}".format(survexleglength)}))
|
|
legsbyexpo.reverse()
|
|
#survexlegs = SurvexLeg.objects.all()
|
|
|
|
renderDict = {**statsDict, **{ "nsurvexlegs": "{:,}".format(nimportlegs), "totalsurvexlength":totalsurvexlength/1000, "addupsurvexlength":addupsurvexlength/1000, "legsbyexpo":legsbyexpo }} # new syntax
|
|
return render(request,'statistics.html', renderDict)
|