summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/views.py2
-rw-r--r--core/views_logbooks.py2
-rw-r--r--core/views_other.py23
-rw-r--r--core/views_statistics.py112
4 files changed, 114 insertions, 25 deletions
diff --git a/core/views.py b/core/views.py
index d81e03c..b74b709 100644
--- a/core/views.py
+++ b/core/views.py
@@ -5,4 +5,4 @@ from . import views_caves
from . import views_survex
from . import views_logbooks
from . import views_other
-
+from . import views_statistics
diff --git a/core/views_logbooks.py b/core/views_logbooks.py
index 4c36d04..27a236e 100644
--- a/core/views_logbooks.py
+++ b/core/views_logbooks.py
@@ -220,7 +220,7 @@ def pathsreport(request):
def experimental(request):
- blockroots = models.SurvexBlock.objects.filter(name="root")
+ blockroots = models.SurvexBlock.objects.filter(name="rootblock")
if len(blockroots)>1:
print(" ! more than one root survexblock {}".format(len(blockroots)))
for sbr in blockroots:
diff --git a/core/views_other.py b/core/views_other.py
index c31777a..9fa34c0 100644
--- a/core/views_other.py
+++ b/core/views_other.py
@@ -20,29 +20,6 @@ print("** importing troggle/core/views_other.py")
def showrequest(request):
return HttpResponse(request.GET)
-def stats(request):
- statsDict={}
- statsDict['expoCount'] = int(Expedition.objects.count())
- statsDict['caveCount'] = int(Cave.objects.count())
- statsDict['personCount'] = int(Person.objects.count())
- statsDict['logbookEntryCount'] = int(LogbookEntry.objects.count())
-
- legsbyexpo = [ ]
- for expedition in Expedition.objects.all():
- survexblocks = expedition.survexblock_set.all()
- survexlegs = [ ]
- survexleglength = 0.0
- for survexblock in survexblocks:
- survexlegs.extend(survexblock.survexleg_set.all())
- survexleglength += survexblock.totalleglength
- legsbyexpo.append((expedition, {"nsurvexlegs":len(survexlegs), "survexleglength":survexleglength/1000}))
- legsbyexpo.reverse()
- survexlegs = SurvexLeg.objects.all()
- totalsurvexlength = sum([survexleg.tape for survexleg in survexlegs])
-
- renderDict = {**statsDict, **{ "nsurvexlegs":len(survexlegs), "totalsurvexlength":totalsurvexlength/1000, "legsbyexpo":legsbyexpo }} # new syntax
- return render(request,'statistics.html', renderDict)
-
def frontpage(request):
if request.user.is_authenticated():
return render(request,'tasks.html')
diff --git a/core/views_statistics.py b/core/views_statistics.py
new file mode 100644
index 0000000..0b1db33
--- /dev/null
+++ b/core/views_statistics.py
@@ -0,0 +1,112 @@
+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
+ }
+
+ ncodes = len(pathsdict)
+
+ bycodeslist = sorted(pathsdict.items())
+ bypathslist = sorted(iter(pathsdict.items()), key=lambda x: x[1])
+
+ 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())
+
+ 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.text, sbr.date))
+ sbr = blockroots[0]
+ totalsurvexlength = sbr.totalleglength
+ try:
+ nimportlegs = int(sbr.text)
+ except:
+ print("{} {} {} {}".format(sbr.id, sbr.name, sbr.text, sbr.date))
+ nimportlegs = -1
+
+ 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.text)
+ 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)