forked from expo/troggle
[svn] latest hacking for various statistics
This commit is contained in:
@@ -13,6 +13,7 @@ getcontext().prec=2 #use 2 significant figures for decimal calculations
|
||||
|
||||
from models_survex import *
|
||||
|
||||
|
||||
def get_related_by_wikilinks(wiki_text):
|
||||
found=re.findall(settings.QM_PATTERN,wiki_text)
|
||||
res=[]
|
||||
@@ -120,6 +121,14 @@ class Person(TroggleModel):
|
||||
def bisnotable(self):
|
||||
return self.notability() > Decimal(1)/Decimal(3)
|
||||
|
||||
def surveyedleglength(self):
|
||||
return sum([personexpedition.surveyedleglength() for personexpedition in self.personexpedition_set.all()])
|
||||
|
||||
def first(self):
|
||||
return self.personexpedition_set.order_by('-expedition')[0]
|
||||
def last(self):
|
||||
return self.personexpedition_set.order_by('expedition')[0]
|
||||
|
||||
#def Sethref(self):
|
||||
#if self.last_name:
|
||||
#self.href = self.first_name.lower() + "_" + self.last_name.lower()
|
||||
@@ -151,11 +160,11 @@ class PersonExpedition(TroggleModel):
|
||||
|
||||
def GetPersonroles(self):
|
||||
res = [ ]
|
||||
for personrole in self.personrole_set.order_by('survex_block'):
|
||||
if res and res[-1]['survexpath'] == personrole.survex_block.survexpath:
|
||||
for personrole in self.personrole_set.order_by('survexblock'):
|
||||
if res and res[-1]['survexpath'] == personrole.survexblock.survexpath:
|
||||
res[-1]['roles'] += ", " + str(personrole.role)
|
||||
else:
|
||||
res.append({'date':personrole.survex_block.date, 'survexpath':personrole.survex_block.survexpath, 'roles':str(personrole.role)})
|
||||
res.append({'date':personrole.survexblock.date, 'survexpath':personrole.survexblock.survexpath, 'roles':str(personrole.role)})
|
||||
return res
|
||||
|
||||
class Meta:
|
||||
@@ -178,6 +187,9 @@ class PersonExpedition(TroggleModel):
|
||||
def get_absolute_url(self):
|
||||
return urlparse.urljoin(settings.URL_ROOT, reverse('personexpedition',kwargs={'first_name':self.person.first_name,'last_name':self.person.last_name,'year':self.expedition.year}))
|
||||
|
||||
def surveyedleglength(self):
|
||||
survexblocks = [personrole.survexblock for personrole in self.personrole_set.all() ]
|
||||
return sum([survexblock.totalleglength for survexblock in set(survexblocks)])
|
||||
|
||||
#
|
||||
# Single parsed entry from Logbook
|
||||
|
||||
@@ -46,6 +46,22 @@ class SurvexFile(models.Model):
|
||||
self.survexdirectory = survexdirectory
|
||||
self.save()
|
||||
|
||||
class SurvexEquate(models.Model):
|
||||
cave = models.ForeignKey('Cave', blank=True, null=True)
|
||||
|
||||
class SurvexStation(models.Model):
|
||||
name = models.CharField(max_length=20)
|
||||
block = models.ForeignKey('SurvexBlock')
|
||||
equate = models.ForeignKey('SurvexEquate', blank=True, null=True)
|
||||
|
||||
class SurvexLeg(models.Model):
|
||||
block = models.ForeignKey('SurvexBlock')
|
||||
#title = models.ForeignKey('SurvexTitle')
|
||||
stationfrom = models.ForeignKey('SurvexStation', related_name='stationfrom')
|
||||
stationto = models.ForeignKey('SurvexStation', related_name='stationto')
|
||||
tape = models.FloatField()
|
||||
compass = models.FloatField()
|
||||
clino = models.FloatField()
|
||||
#
|
||||
# Single SurvexBlock
|
||||
#
|
||||
@@ -62,6 +78,7 @@ class SurvexBlock(models.Model):
|
||||
begin_char = models.IntegerField() # code for where in the survex data files this block sits
|
||||
survexpath = models.CharField(max_length=200) # the path for the survex stations
|
||||
refscandir = models.CharField(max_length=100)
|
||||
totalleglength = models.FloatField()
|
||||
|
||||
class Meta:
|
||||
ordering = ('id',)
|
||||
@@ -78,6 +95,17 @@ class SurvexBlock(models.Model):
|
||||
res.append({'person':personrole.personexpedition.person, 'expeditionyear':personrole.personexpedition.expedition.year, 'roles':str(personrole.role)})
|
||||
return res
|
||||
|
||||
def MakeSurvexStation(self, name):
|
||||
ssl = self.survexstation_set.filter(name=name)
|
||||
if ssl:
|
||||
assert len(ssl) == 1
|
||||
return ssl[0]
|
||||
ss = SurvexStation(name=name, block=self)
|
||||
ss.save()
|
||||
return ss
|
||||
|
||||
|
||||
|
||||
class SurvexTitle(models.Model):
|
||||
survexblock = models.ForeignKey('SurvexBlock')
|
||||
title = models.CharField(max_length=200)
|
||||
@@ -87,7 +115,7 @@ class SurvexTitle(models.Model):
|
||||
# member of a SurvexBlock
|
||||
#
|
||||
class PersonRole(models.Model):
|
||||
survex_block = models.ForeignKey('SurvexBlock')
|
||||
survexblock = models.ForeignKey('SurvexBlock')
|
||||
|
||||
ROLE_CHOICES = (
|
||||
('insts','Instruments'),
|
||||
@@ -109,6 +137,6 @@ class PersonRole(models.Model):
|
||||
persontrip = models.ForeignKey('PersonTrip', blank=True, null=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.person) + " - " + unicode(self.survex_block) + " - " + unicode(self.nrole)
|
||||
return unicode(self.person) + " - " + unicode(self.survexblock) + " - " + unicode(self.nrole)
|
||||
|
||||
|
||||
|
||||
@@ -7,9 +7,6 @@ from core.models import QM, Photo, LogbookEntry, Cave
|
||||
import re, urlparse
|
||||
|
||||
register = template.Library()
|
||||
url_root=settings.URL_ROOT
|
||||
if settings.URL_ROOT.endswith('/'):
|
||||
url_root=settings.URL_ROOT[:-1]
|
||||
|
||||
|
||||
@register.filter()
|
||||
@@ -93,7 +90,7 @@ def wiki_to_html_short(value, autoescape=None):
|
||||
[[QM:C204-1999-24]]
|
||||
If the QM does not exist, the function will return a link for creating it.
|
||||
"""
|
||||
qmdict={'urlroot':url_root,'cave':matchobj.groups()[2],'year':matchobj.groups()[1],'number':matchobj.groups()[3]}
|
||||
qmdict={'urlroot':settings.URL_ROOT,'cave':matchobj.groups()[2],'year':matchobj.groups()[1],'number':matchobj.groups()[3]}
|
||||
try:
|
||||
qm=QM.objects.get(found_by__cave__kataster_number = qmdict['cave'],
|
||||
found_by__date__year = qmdict['year'],
|
||||
@@ -146,13 +143,13 @@ def wiki_to_html_short(value, autoescape=None):
|
||||
value = re.sub(photoSrcPattern,photoSrcRepl, value, re.DOTALL)
|
||||
|
||||
#make cave links
|
||||
value = re.sub("\[\[\s*cave:([^\s]+)\s*\s*\]\]", r'<a href="%s/cave/\1/">\1</a>' % url_root, value, re.DOTALL)
|
||||
value = re.sub("\[\[\s*cave:([^\s]+)\s*\s*\]\]", r'<a href="%scave/\1/">\1</a>' % settings.URL_ROOT, value, re.DOTALL)
|
||||
#make people links
|
||||
value = re.sub("\[\[\s*person:(.+)\|(.+)\]\]",r'<a href="%s/person/\1/">\2</a>' % url_root, value, re.DOTALL)
|
||||
value = re.sub("\[\[\s*person:(.+)\|(.+)\]\]",r'<a href="%sperson/\1/">\2</a>' % settings.URL_ROOT, value, re.DOTALL)
|
||||
#make subcave links
|
||||
value = re.sub("\[\[\s*subcave:(.+)\|(.+)\]\]",r'<a href="%s/subcave/\1/">\2</a>' % url_root, value, re.DOTALL)
|
||||
value = re.sub("\[\[\s*subcave:(.+)\|(.+)\]\]",r'<a href="%ssubcave/\1/">\2</a>' % settings.URL_ROOT, value, re.DOTALL)
|
||||
#make cavedescription links
|
||||
value = re.sub("\[\[\s*cavedescription:(.+)\|(.+)\]\]",r'<a href="%s/cavedescription/\1/">\2</a>' % url_root, value, re.DOTALL)
|
||||
value = re.sub("\[\[\s*cavedescription:(.+)\|(.+)\]\]",r'<a href="%scavedescription/\1/">\2</a>' % settings.URL_ROOT, value, re.DOTALL)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from django.shortcuts import render_to_response
|
||||
from troggle.core.models import Expedition, Person, PersonExpedition, PersonTrip, LogbookEntry
|
||||
import troggle.core.models as models
|
||||
import troggle.settings as settings
|
||||
from django.db import models
|
||||
import django.db.models
|
||||
from troggle.parsers.logbooks import LoadLogbookForExpedition
|
||||
from troggle.parsers.people import GetPersonExpeditionNameLookup
|
||||
from troggle.core.forms import PersonForm
|
||||
@@ -13,7 +14,7 @@ from troggle.alwaysUseRequestContext import render_response
|
||||
|
||||
import re
|
||||
|
||||
@models.permalink #this allows the nice get_absolute_url syntax we are using
|
||||
@django.db.models.permalink #this allows the nice get_absolute_url syntax we are using
|
||||
|
||||
def getNotablePersons():
|
||||
notablepersons = []
|
||||
@@ -27,7 +28,7 @@ def personindex(request):
|
||||
persons = Person.objects.all()
|
||||
# From what I can tell, "persons" seems to be the table rows, while "personss" is the table columns. - AC 16 Feb 09
|
||||
personss = [ ]
|
||||
ncols = 5
|
||||
ncols = 4
|
||||
nc = (len(persons) + ncols - 1) / ncols
|
||||
for i in range(ncols):
|
||||
personss.append(persons[i * nc: (i + 1) * nc])
|
||||
@@ -76,9 +77,9 @@ def GetPersonChronology(personexpedition):
|
||||
a.setdefault("persontrips", [ ]).append(persontrip)
|
||||
|
||||
for personrole in personexpedition.personrole_set.all():
|
||||
a = res.setdefault(personrole.survex_block.date, { })
|
||||
a = res.setdefault(personrole.survexblock.date, { })
|
||||
b = a.setdefault("personroles", { })
|
||||
survexpath = personrole.survex_block.survexpath
|
||||
survexpath = personrole.survexblock.survexpath
|
||||
|
||||
if b.get(survexpath):
|
||||
b[survexpath] += ", " + str(personrole.nrole)
|
||||
@@ -135,3 +136,20 @@ def personForm(request,pk):
|
||||
form=PersonForm(instance=person)
|
||||
return render_response(request,'personform.html', {'form':form,})
|
||||
|
||||
|
||||
def experimental(request):
|
||||
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}))
|
||||
legsbyexpo.reverse()
|
||||
|
||||
survexlegs = models.SurvexLeg.objects.all()
|
||||
totalsurvexlength = sum([survexleg.tape for survexleg in survexlegs])
|
||||
return render_response(request, 'experimental.html', { "nsurvexlegs":len(survexlegs), "totalsurvexlength":totalsurvexlength, "legsbyexpo":legsbyexpo })
|
||||
|
||||
|
||||
@@ -113,8 +113,7 @@ class SvxForm(forms.Form):
|
||||
def svx(request, survex_file):
|
||||
# get the basic data from the file given in the URL
|
||||
dirname = os.path.split(survex_file)[0]
|
||||
if dirname:
|
||||
dirname += "/"
|
||||
dirname += "/"
|
||||
nowtime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
outputtype = "normal"
|
||||
form = SvxForm({'filename':survex_file, 'dirname':dirname, 'datetime':nowtime, 'outputtype':outputtype})
|
||||
|
||||
Reference in New Issue
Block a user