From cdd4e685ee95e44b9a599b03cf11723a4ce7b7c6 Mon Sep 17 00:00:00 2001 From: substantialnoninfringinguser Date: Wed, 13 May 2009 05:46:12 +0100 Subject: [PATCH] [svn] cave maps to all logbook entry trips done there Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8228 by julian @ 1/24/2009 11:59 PM --- databaseReset.py | 1 + expo/models.py | 35 +++-- expo/views_caves.py | 9 +- media/css/main2.css | 2 +- parsers/cavetab.py | 249 ++++++++++++++++---------------- parsers/logbooks.py | 9 +- templates/cave.html | 13 ++ templates/caveindex.html | 16 +- templates/expedition.html | 7 +- templates/index.html | 25 ++-- templates/logbookentry.html | 7 +- templates/personexpedition.html | 7 +- urls.py | 4 +- 13 files changed, 225 insertions(+), 159 deletions(-) diff --git a/databaseReset.py b/databaseReset.py index 2bb34cd..fe7bb1f 100644 --- a/databaseReset.py +++ b/databaseReset.py @@ -18,6 +18,7 @@ user.is_superuser = True user.save() import parsers.cavetab +parsers.cavetab.LoadCaveTab() import parsers.people parsers.people.LoadPersonsExpos() import parsers.logbooks diff --git a/expo/models.py b/expo/models.py index 058fff5..2b3919c 100644 --- a/expo/models.py +++ b/expo/models.py @@ -49,18 +49,6 @@ class Expedition(models.Model): date+=datetime.timedelta(days=1) return res - # deprecated - def GetPersonExpedition(self, name): - person_expeditions = PersonExpedition.objects.filter(expedition=self) - res = None - for person_expedition in person_expeditions: - for possible_name_from in person_expedition.GetPossibleNameForms(): - #print "nnn", possiblenamefrom - if name == possible_name_from: - assert not res, "Ambiguous: " + name - res = person_expedition - return res - @@ -198,6 +186,7 @@ class CaveAndEntrance(models.Model): return unicode(self.cave) + unicode(self.entrance_letter) class Cave(models.Model): + # too much here perhaps official_name = models.CharField(max_length=160) area = models.ManyToManyField(Area, blank=True, null=True) kataster_code = models.CharField(max_length=20,blank=True,null=True) @@ -216,6 +205,18 @@ class Cave(models.Model): depth = models.CharField(max_length=100,blank=True,null=True) extent = models.CharField(max_length=100,blank=True,null=True) survex_file = models.CharField(max_length=100,blank=True,null=True) #should be filefield, need to fix parser first + + href = models.CharField(max_length=100) + + def Sethref(self): + if self.kataster_number: + self.href = self.kataster_number + elif self.unofficial_number: + self.href = self.unofficial_number + else: + self.href = official_name.lower() + + def __unicode__(self): if self.kataster_number: if self.kat_area(): @@ -227,6 +228,8 @@ class Cave(models.Model): return self.kat_area() + u": " + self.unofficial_number else: return self.unofficial_number + + def kat_area(self): for a in self.area.all(): if a.kat_area(): @@ -271,12 +274,15 @@ class LogbookEntry(models.Model): text = models.TextField() href = models.CharField(max_length=100) + # turn these into functions logbookentry_next = models.ForeignKey('LogbookEntry', related_name='pnext', blank=True,null=True) logbookentry_prev = models.ForeignKey('LogbookEntry', related_name='pprev', blank=True,null=True) class Meta: verbose_name_plural = "Logbook Entries" # several PersonTrips point in to this object + class Meta: + ordering = ('-date',) def __unicode__(self): return "%s: (%s)" % (self.date, self.title) @@ -287,6 +293,7 @@ class PersonTrip(models.Model): # this will be a foreign key of the place(s) the trip went through # possibly a trip has a plurality of triplets pointing into it place = models.CharField(max_length=100) + # should add cave thing here (copied from logbook maybe) date = models.DateField() time_underground = models.FloatField() logbook_entry = models.ForeignKey(LogbookEntry) @@ -473,4 +480,6 @@ class Survey(models.Model): return self.scannedimage_set.filter(contents='plan') def elevations(self): - return self.scannedimage_set.filter(contents='elevation') \ No newline at end of file + return self.scannedimage_set.filter(contents='elevation') + + \ No newline at end of file diff --git a/expo/views_caves.py b/expo/views_caves.py index 691dd43..3363a2e 100644 --- a/expo/views_caves.py +++ b/expo/views_caves.py @@ -7,13 +7,20 @@ import search def caveindex(request): caves = Cave.objects.all() - return render_to_response('caveindex.html', {'caves': caves, 'settings': settings}) + notablecavehrefs = [ "161", "204", "258", "76" ] + notablecaves = [ Cave.objects.get(href=href) for href in notablecavehrefs ] + return render_to_response('caveindex.html', {'caves': caves, 'notablecaves':notablecaves, 'settings': settings}) def cave(request, cave_id): #hm, we're only choosing by the number within kataster, needs to be fixed. Caves in 1626 will presumably not work. - AC 7DEC08 cave = Cave.objects.filter(kataster_number = cave_id)[0] return render_to_response('cave.html', {'cave': cave, 'settings': settings}) +def cavehref(request, href): + cave = Cave.objects.get(href=href) + return render_to_response('cave.html', {'cave': cave, 'settings': settings}) + + def ent(request, cave_id, ent_letter): cave = Cave.objects.filter(kataster_number = cave_id)[0] cave_and_ent = CaveAndEntrance.objects.filter(cave = cave).filter(entrance_letter = ent_letter)[0] diff --git a/media/css/main2.css b/media/css/main2.css index 4f827b3..c7c7276 100644 --- a/media/css/main2.css +++ b/media/css/main2.css @@ -149,7 +149,7 @@ table.survexcontibutions td.roles table.survexcontibutions td.survexblock { width:260px; background-color:#feeeed; } table.survexcontibutions td.trip -{ width:190px; } +{ width:280px; } table.survexcontibutions td.place { width:140px; } diff --git a/parsers/cavetab.py b/parsers/cavetab.py index 7f3146a..3203879 100644 --- a/parsers/cavetab.py +++ b/parsers/cavetab.py @@ -56,9 +56,6 @@ MarkingComment = 43 Findability = 44 FindabilityComment = 45 -cavetab = open(os.path.join(settings.EXPOWEB, "noinfo", "CAVETAB2.CSV")) -caveReader = csv.reader(cavetab) -caveReader.next() # Strip out column headers def html_to_wiki(text): if type(text) != str: @@ -138,130 +135,137 @@ def html_to_wiki(text): text2 = "" return out -for katArea in ['1623', '1626']: - if not models.Area.objects.filter(short_name = katArea): - newArea = models.Area(short_name = katArea) - newArea.save() -area1626 = models.Area.objects.filter(short_name = '1626')[0] -area1623 = models.Area.objects.filter(short_name = '1623')[0] +def LoadCaveTab(): + cavetab = open(os.path.join(settings.EXPOWEB, "noinfo", "CAVETAB2.CSV")) + caveReader = csv.reader(cavetab) + caveReader.next() # Strip out column headers + + for katArea in ['1623', '1626']: + if not models.Area.objects.filter(short_name = katArea): + newArea = models.Area(short_name = katArea) + newArea.save() + area1626 = models.Area.objects.filter(short_name = '1626')[0] + area1623 = models.Area.objects.filter(short_name = '1623')[0] + + counter=0 + for line in caveReader : + if line[Area] == 'nonexistent': + continue + entranceLetters=[] #Used in caves that have mulitlple entrances, which are not described on seperate lines + if line[MultipleEntrances] == 'yes' or line[MultipleEntrances]=='': + args = {} + def addToArgs(CSVname, modelName): + if line[CSVname]: + args[modelName] = html_to_wiki(line[CSVname]) + addToArgs(KatasterNumber, "kataster_number") + addToArgs(KatStatusCode, "kataster_code") + addToArgs(UnofficialNumber, "unofficial_number") + addToArgs(Name, "official_name") + addToArgs(Comment, "notes") + addToArgs(Explorers, "explorers") + addToArgs(UndergroundDescription, "underground_description") + addToArgs(Equipment, "equipment") + addToArgs(KatasterStatus, "kataster_status") + addToArgs(References, "references") + addToArgs(UndergroundCentreLine, "underground_centre_line") + addToArgs(UndergroundDrawnSurvey, "survey") + addToArgs(Length, "length") + addToArgs(Depth, "depth") + addToArgs(Extent, "extent") + addToArgs(SurvexFile, "survex_file") + addToArgs(Notes, "notes") -counter=0 -for line in caveReader : - if line[Area] == 'nonexistent': - continue - entranceLetters=[] #Used in caves that have mulitlple entrances, which are not described on seperate lines - if line[MultipleEntrances] == 'yes' or line[MultipleEntrances]=='': - args = {} - def addToArgs(CSVname, modelName): - if line[CSVname]: - args[modelName] = html_to_wiki(line[CSVname]) - addToArgs(KatasterNumber, "kataster_number") - addToArgs(KatStatusCode, "kataster_code") - addToArgs(UnofficialNumber, "unofficial_number") - addToArgs(Name, "official_name") - addToArgs(Comment, "notes") - addToArgs(Explorers, "explorers") - addToArgs(UndergroundDescription, "underground_description") - addToArgs(Equipment, "equipment") - addToArgs(KatasterStatus, "kataster_status") - addToArgs(References, "references") - addToArgs(UndergroundCentreLine, "underground_centre_line") - addToArgs(UndergroundDrawnSurvey, "survey") - addToArgs(Length, "length") - addToArgs(Depth, "depth") - addToArgs(Extent, "extent") - addToArgs(SurvexFile, "survex_file") - addToArgs(Notes, "notes") - - newCave = models.Cave(**args) - newCave.save() - - if line[Area]: - if line[Area] == "1626": - newCave.area.add(area1626) - else: - area = models.Area.objects.filter(short_name = line[Area]) - if area: - newArea = area[0] + newCave = models.Cave(**args) + newCave.Sethref() + newCave.save() + + if line[Area]: + if line[Area] == "1626": + newCave.area.add(area1626) else: - newArea = models.Area(short_name = line[Area], parent = area1623) - newArea.save() - newCave.area.add(newArea) - else: - newCave.area.add(area1623) - - newCave.save() + area = models.Area.objects.filter(short_name = line[Area]) + if area: + newArea = area[0] + else: + newArea = models.Area(short_name = line[Area], parent = area1623) + newArea.save() + newCave.area.add(newArea) + else: + newCave.area.add(area1623) + + newCave.save() if line[UnofficialName]: newUnofficialName = models.OtherCaveName(cave = newCave, name = line[UnofficialName]) newUnofficialName.save() - if line[MultipleEntrances] == '' or \ - line[MultipleEntrances] == 'entrance' or \ - line[MultipleEntrances] == 'last entrance': - args = {} - def addToArgs(CSVname, modelName): - if line[CSVname]: - args[modelName] = html_to_wiki(line[CSVname]) - def addToArgsViaDict(CSVname, modelName, dictionary): - if line[CSVname]: - args[modelName] = dictionary[html_to_wiki(line[CSVname])] - addToArgs(EntranceName, 'name') - addToArgs(Explorers, 'explorers') - addToArgs(Map, 'map_description') - addToArgs(Location, 'location_description') - addToArgs(Approach, 'approach') - addToArgs(EntranceDescription, 'entrance_description') - addToArgs(UndergroundDescription, 'underground_description') - addToArgs(PhotoOfLocation, 'photo') - addToArgsViaDict(Marking, 'marking', {"Paint": "P", - "Paint (?)": "P?", - "Tag": "T", - "Tag (?)": "T?", - "Retagged": "R", - "Retag": "R", - "Spit": "S", - "Spit (?)": "S?", - "Unmarked": "U", - "": "?", - }) - addToArgs(MarkingComment, 'marking_comment') - addToArgsViaDict(Findability, 'findability', {"Surveyed": "S", - "Lost": "L", - "Refindable": "R", - "": "?", - "?": "?", - }) - addToArgs(FindabilityComment, 'findability_description') - addToArgs(Easting, 'easting') - addToArgs(Northing, 'northing') - addToArgs(Altitude, 'alt') - addToArgs(DescriptionOfOtherPoint, 'other_description') - def addToArgsSurveyStation(CSVname, modelName): - if line[CSVname]: - surveyPoint = models.SurveyStation(name = line[CSVname]) - surveyPoint.save() - args[modelName] = html_to_wiki(surveyPoint) - addToArgsSurveyStation(TagPoint, 'tag_station') - addToArgsSurveyStation(ExactEntrance, 'exact_station') - addToArgsSurveyStation(OtherPoint, 'other_station') - addToArgs(OtherPoint, 'other_description') - if line[GPSpreSA]: - addToArgsSurveyStation(GPSpreSA, 'other_station') - args['other_description'] = 'pre selective availability GPS' - if line[GPSpostSA]: - addToArgsSurveyStation(GPSpostSA, 'other_station') - args['other_description'] = 'post selective availability GPS' - addToArgs(Bearings, 'bearings') - newEntrance = models.Entrance(**args) - newEntrance.save() - - if line[Entrances]: - entrance_letter = line[Entrances] - else: - entrance_letter = '' - - newCaveAndEntrance = models.CaveAndEntrance(cave = newCave, entrance = newEntrance, entrance_letter = entrance_letter) - newCaveAndEntrance.save() + + if line[MultipleEntrances] == '' or \ + line[MultipleEntrances] == 'entrance' or \ + line[MultipleEntrances] == 'last entrance': + args = {} + def addToArgs(CSVname, modelName): + if line[CSVname]: + args[modelName] = html_to_wiki(line[CSVname]) + def addToArgsViaDict(CSVname, modelName, dictionary): + if line[CSVname]: + args[modelName] = dictionary[html_to_wiki(line[CSVname])] + addToArgs(EntranceName, 'name') + addToArgs(Explorers, 'explorers') + addToArgs(Map, 'map_description') + addToArgs(Location, 'location_description') + addToArgs(Approach, 'approach') + addToArgs(EntranceDescription, 'entrance_description') + addToArgs(UndergroundDescription, 'underground_description') + addToArgs(PhotoOfLocation, 'photo') + addToArgsViaDict(Marking, 'marking', {"Paint": "P", + "Paint (?)": "P?", + "Tag": "T", + "Tag (?)": "T?", + "Retagged": "R", + "Retag": "R", + "Spit": "S", + "Spit (?)": "S?", + "Unmarked": "U", + "": "?", + }) + addToArgs(MarkingComment, 'marking_comment') + addToArgsViaDict(Findability, 'findability', {"Surveyed": "S", + "Lost": "L", + "Refindable": "R", + "": "?", + "?": "?", + }) + addToArgs(FindabilityComment, 'findability_description') + addToArgs(Easting, 'easting') + addToArgs(Northing, 'northing') + addToArgs(Altitude, 'alt') + addToArgs(DescriptionOfOtherPoint, 'other_description') + def addToArgsSurveyStation(CSVname, modelName): + if line[CSVname]: + surveyPoint = models.SurveyStation(name = line[CSVname]) + surveyPoint.save() + args[modelName] = html_to_wiki(surveyPoint) + addToArgsSurveyStation(TagPoint, 'tag_station') + addToArgsSurveyStation(ExactEntrance, 'exact_station') + addToArgsSurveyStation(OtherPoint, 'other_station') + addToArgs(OtherPoint, 'other_description') + if line[GPSpreSA]: + addToArgsSurveyStation(GPSpreSA, 'other_station') + args['other_description'] = 'pre selective availability GPS' + if line[GPSpostSA]: + addToArgsSurveyStation(GPSpostSA, 'other_station') + args['other_description'] = 'post selective availability GPS' + addToArgs(Bearings, 'bearings') + newEntrance = models.Entrance(**args) + newEntrance.save() + + if line[Entrances]: + entrance_letter = line[Entrances] + else: + entrance_letter = '' + + newCaveAndEntrance = models.CaveAndEntrance(cave = newCave, entrance = newEntrance, entrance_letter = entrance_letter) + newCaveAndEntrance.save() # lookup function modelled on GetPersonExpeditionNameLookup @@ -277,6 +281,9 @@ def GetCaveLookup(): Gcavelookup[cave.kataster_number] = cave if cave.unofficial_number: Gcavelookup[cave.unofficial_number] = cave + + Gcavelookup["tunnocks"] = Gcavelookup["258"] + Gcavelookup["hauchhole"] = Gcavelookup["234"] return Gcavelookup \ No newline at end of file diff --git a/parsers/logbooks.py b/parsers/logbooks.py index 9ad1962..3bad8c4 100644 --- a/parsers/logbooks.py +++ b/parsers/logbooks.py @@ -63,13 +63,16 @@ def GetTripCave(place): #need to be fuzzier about matching h return +noncaveplaces = [ "Journey", "Loser Plateau" ] def EnterLogIntoDbase(date, place, title, text, trippeople, expedition, logtime_underground): trippersons, author = GetTripPersons(trippeople, expedition, logtime_underground) # tripCave = GetTripCave(place) lbo = models.LogbookEntry(date=date, place=place, title=title[:50], text=text, author=author, expedition=expedition) - lbo.cave=GetCaveLookup().get(place) - print "pppp", place, lbo.cave + lplace = place.lower() + if lplace not in noncaveplaces: + lbo.cave=GetCaveLookup().get(lplace) + print "pppp %s |%s|" % (lplace, str(lbo.cave)) lbo.save() #print "ttt", date, place @@ -158,7 +161,7 @@ def Parseloghtml01(year, expedition, txt): tripid = mtripid and mtripid.group(1) or "" tripheader = re.sub("]*>", "", tripheader) - print [tripheader] + #print [tripheader] #continue tripdate, triptitle, trippeople = tripheader.split("|") diff --git a/templates/cave.html b/templates/cave.html index 24c0101..f8a511d 100644 --- a/templates/cave.html +++ b/templates/cave.html @@ -2,6 +2,19 @@ {% load wiki_markup %} {% block content %} + +
+

All trips done in this cave

+ + {% for logbookentry in cave.logbookentry_set.all %} + + + + + {% endfor %} +
{{logbookentry.date}}{{logbookentry.title|safe}}
+
+ {% if cave.entrances %}

Entrances

{% for ent in cave.entrances %} diff --git a/templates/caveindex.html b/templates/caveindex.html index d97aff8..b38e69f 100644 --- a/templates/caveindex.html +++ b/templates/caveindex.html @@ -4,7 +4,19 @@ {% block title %}Cave Index{% endblock %} {% block content %} -{% for cave in caves %} -

{{ cave }} {{ cave.official_name|wiki_to_html_short }}

+ +

Notable caves

+ + +

All caves

+ + {% endblock %} \ No newline at end of file diff --git a/templates/expedition.html b/templates/expedition.html index a7add92..e4f12f0 100644 --- a/templates/expedition.html +++ b/templates/expedition.html @@ -38,7 +38,12 @@ {{logbookentry.date}} {{logbookentry.title|safe}} {{logbookentry.author.name}} - {{logbookentry.place}} + + {% if logbookentry.cave %} + {{logbookentry.place}} + {% else %} + {{logbookentry.place}} + {% endif %} {% endfor %} diff --git a/templates/index.html b/templates/index.html index f30c100..2dad17b 100644 --- a/templates/index.html +++ b/templates/index.html @@ -9,26 +9,25 @@ Work down through an expedition page link

Remaining work: -

continue to build up the network;

-

tables of trips per year per person;

+

(separate out the recent/notable people) vast front-page layout table of folks and caving trips and years;

parse 1995-1976 logbooks;

-

continue to correct the name matching and spelling;

+

name matching and spelling in survex files;

detect T/U on log entries;

+

Improve logbook wikihtml text

match caves to log entries;

-

see the cave list;

simplify the survex parsing code (if necessary);

-

vast front-page layout table of folks and caving trips and years;

links between logbooks and survex blocks to cave things;

where are the subcaves;

mini-tree of survexblocks;

connect sketches to caves to survey blocks and render thumbnailwise;

all images to start appearing in pages; and so on

+

tables of trips per year per person;

{{message}}