diff options
author | expo <expo@expobox.potato.hut> | 2013-08-01 17:00:01 +0200 |
---|---|---|
committer | expo <expo@expobox.potato.hut> | 2013-08-01 17:00:01 +0200 |
commit | df8618d0f0c7df09a90ecad9ef7885ee4da39e01 (patch) | |
tree | 4410fef6482a3c913386d2bef909d3688ddc52ad /core | |
parent | 64f4e122a519ed1a1c3b462f20a41af555a42cec (diff) | |
download | troggle-df8618d0f0c7df09a90ecad9ef7885ee4da39e01.tar.gz troggle-df8618d0f0c7df09a90ecad9ef7885ee4da39e01.tar.bz2 troggle-df8618d0f0c7df09a90ecad9ef7885ee4da39e01.zip |
Prospecting guide and images and few minor other things.
Diffstat (limited to 'core')
-rw-r--r-- | core/admin.py | 1 | ||||
-rw-r--r-- | core/imageposcalc.ods | bin | 0 -> 11110 bytes | |||
-rw-r--r-- | core/models.py | 70 | ||||
-rw-r--r-- | core/views_caves.py | 233 | ||||
-rw-r--r-- | core/views_survex.py | 5 |
5 files changed, 286 insertions, 23 deletions
diff --git a/core/admin.py b/core/admin.py index 0192807..0c8b605 100644 --- a/core/admin.py +++ b/core/admin.py @@ -120,6 +120,7 @@ admin.site.register(LogbookEntry, LogbookEntryAdmin) admin.site.register(QM, QMAdmin) admin.site.register(Survey, SurveyAdmin) admin.site.register(ScannedImage) +admin.site.register(SurvexStation) admin.site.register(SurvexScansFolder) admin.site.register(SurvexScanSingle) diff --git a/core/imageposcalc.ods b/core/imageposcalc.ods Binary files differnew file mode 100644 index 0000000..0cc2135 --- /dev/null +++ b/core/imageposcalc.ods diff --git a/core/models.py b/core/models.py index e064814..a3bd832 100644 --- a/core/models.py +++ b/core/models.py @@ -249,7 +249,7 @@ class LogbookEntry(TroggleModel): filename = models.CharField(max_length=200,null=True) class Meta: - verbose_name_plural = "Logbook Entries" + verbose_name_plural = "Logbook Entries" # several PersonTrips point in to this object ordering = ('-date',) @@ -397,11 +397,14 @@ class Cave(TroggleModel): #href = models.CharField(max_length=100) + + class Meta: + ordering = ('kataster_code', 'unofficial_number') def hassurvey(self): if not self.underground_centre_line: return "No" - if (self.underground_centre_line.find("<img") > -1 or self.underground_centre_line.find("<a") > -1): + if (self.survey.find("<img") > -1 or self.survey.find("<a") > -1 or self.survey.find("<IMG") > -1 or self.survey.find("<A") > -1): return "Yes" return "Missing" @@ -501,8 +504,17 @@ class Cave(TroggleModel): u8 = u.encode("utf-8") f.write(u8) f.close() - - + + def getArea(self): + areas = self.area.all() + lowestareas = list(areas) + for area in areas: + if area.parent in areas: + try: + lowestareas.remove(area.parent) + except: + pass + return lowestareas[0] def getCaveByReference(reference): areaname, code = reference.split("-", 1) @@ -539,7 +551,7 @@ class Entrance(TroggleModel): ('P?', 'Paint (?)'), ('T', 'Tag'), ('T?', 'Tag (?)'), - ('R', 'Retagged'), + ('R', 'Needs Retag'), ('S', 'Spit'), ('S?', 'Spit (?)'), ('U', 'Unmarked'), @@ -548,7 +560,7 @@ class Entrance(TroggleModel): marking_comment = models.TextField(blank=True,null=True) FINDABLE_CHOICES = ( ('?', 'To be confirmed ...'), - ('S', 'Surveyed'), + ('S', 'Coordinates'), ('L', 'Lost'), ('R', 'Refindable')) findability = models.CharField(max_length=1, choices=FINDABLE_CHOICES, blank=True, null=True) @@ -575,21 +587,46 @@ class Entrance(TroggleModel): def find_location(self): + r = {'': 'To be entered ', + '?': 'To be confirmed:', + 'S': '', + 'L': 'Lost:', + 'R': 'Refindable:'}[self.findability] + if self.tag_station: + try: + s = SurvexStation.objects.lookup(self.tag_station) + return r + "%0.0fE %0.0fN %0.0fAlt" % (s.x, s.y, s.z) + except: + return r + "%s Tag Station not in dataset" % self.tag_station + if self.exact_station: + try: + s = SurvexStation.objects.lookup(self.exact_station) + return r + "%0.0fE %0.0fN %0.0fAlt" % (s.x, s.y, s.z) + except: + return r + "%s Exact Station not in dataset" % self.tag_station + if self.other_station: + try: + s = SurvexStation.objects.lookup(self.other_station) + return r + "%0.0fE %0.0fN %0.0fAlt %s" % (s.x, s.y, s.z, self.other_description) + except: + return r + "%s Other Station not in dataset" % self.tag_station + if self.FINDABLE_CHOICES == "S": + r += "ERROR, Entrance has been surveyed but has no survex point" + if self.bearings: + return r + self.bearings + return r + + def best_station(self): if self.tag_station: - s = SurvexStation.objects.lookup(self.tag_station) - return "%0.0fE %0.0fN %0.0fAlt" % (s.x, s.y, s.z) + return self.tag_station if self.exact_station: - s = SurvexStation.objects.lookup(self.exact_station) - return "%0.0fE %0.0fN %0.0fAlt" % (s.x, s.y, s.z) + return self.exact_station if self.other_station: - s = SurvexStation.objects.lookup(self.other_station) - return "%0.0fE %0.0fN %0.0fAlt %s" % (s.x, s.y, s.z, self.other_description) - if self.bearings: - return self.bearings + return self.other_station def has_photo(self): if self.photo: - if (self.photo.find("<img") > -1 or self.photo.find("<a") > -1): + if (self.photo.find("<img") > -1 or self.photo.find("<a") > -1 or self.photo.find("<IMG") > -1 or self.photo.find("<A") > -1): return "Yes" else: return "Missing" @@ -607,6 +644,9 @@ class Entrance(TroggleModel): def tag(self): return SurvexStation.objects.lookup(self.tag_station) + + def needs_surface_work(self): + return self.findability != "S" or not self.has_photo or self.marking != "T" def get_absolute_url(self): diff --git a/core/views_caves.py b/core/views_caves.py index 16dbaac..7a266b5 100644 --- a/core/views_caves.py +++ b/core/views_caves.py @@ -1,4 +1,7 @@ -from troggle.core.models import CaveSlug, Cave, CaveAndEntrance, Survey, Expedition, QM, CaveDescription, EntranceSlug, Entrance, Area +#!/usr/bin/python +# -*- coding: utf-8 -*- + +from troggle.core.models import CaveSlug, Cave, CaveAndEntrance, Survey, Expedition, QM, CaveDescription, EntranceSlug, Entrance, Area, SurvexStation from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, VersionControlCommentForm, EntranceForm, EntranceLetterForm import troggle.core.models as models import troggle.settings as settings @@ -8,10 +11,13 @@ from django.forms.models import modelformset_factory from django import forms from django.core.urlresolvers import reverse from utils import render_with_context # see views_logbooks for explanation on this. -from django.http import HttpResponseRedirect +from django.http import HttpResponse, HttpResponseRedirect from django.conf import settings import re, urlparse from django.shortcuts import get_object_or_404 +import settings + +import Image, ImageDraw, ImageFont, string, os, sys def getCave(cave_id): """Returns a cave object when given a cave name or number. It is used by views including cavehref, ent, and qm.""" @@ -249,19 +255,21 @@ def get_qms(request, caveslug): return render_with_context(request,'options.html', {"items": [(e.entrance.slug(), e.entrance.slug()) for e in cave.entrances()]}) areanames = [ - #('', 'Location unclear'), + ('', 'Location unclear'), ('1a', '1a – Plateau: around Top Camp'), ('1b', '1b – Western plateau near 182'), ('1c', '1c – Eastern plateau near 204 walk-in path'), ('1d', '1d – Further plateau around 76'), ('2a', '2a – Southern Schwarzmooskogel near 201 path and the Nipple'), ('2b', '2b – Eishöhle area'), + ('2b or 4 (unclear)', '2b or 4 (unclear)'), ('2c', '2c – Kaninchenhöhle area'), ('2d', '2d – Steinbrückenhöhle area'), ('3', '3 – Bräuning Alm'), ('4', '4 – Kratzer valley'), ('5', '5 – Schwarzmoos-Wildensee'), ('6', '6 – Far plateau'), + ('1626 or 6 (borderline)', '1626 or 6 (borderline)'), ('7', '7 – Egglgrube'), ('8a', '8a – Loser south face'), ('8b', '8b – Loser below Dimmelwand'), @@ -274,8 +282,221 @@ areanames = [ def prospecting(request): + #for key, name in areanames: + # print key, Area.objects.get(short_name = key) + areas = [] for key, name in areanames: - print key, Area.objects.get(short_name = key) - areas = [ (name, Area.objects.get(short_name = key)) for key, name in areanames ] - return render_with_context(request,'prospecting.html', {"areas": areas}) + a = Area.objects.get(short_name = key) + caves = list(a.cave_set.all()) + caves.sort(caveCmp) + areas.append((name, a, caves)) + return render_with_context(request, 'prospecting.html', {"areas": areas}) + +# Parameters for big map and zoomed subarea maps: +# big map first (zoom factor ignored) + +maps = { +# id left top right bottom zoom +# G&K G&K G&K G&K factor +"all": [33810.4, 85436.5, 38192.0, 81048.2, 0.35, + "All"], +"40": [36275.6, 82392.5, 36780.3, 81800.0, 3.0, + "Eishöhle"], +"76": [35440.0, 83220.0, 36090.0, 82670.0, 1.3, + "Eislufthöhle"], +"204": [36354.1, 84154.5, 37047.4, 83300, 3.0, + "Steinbrückenhöhle"], +"tc": [35230.0, 82690.0, 36110.0, 82100.0, 3.0, + "Near Top Camp"], +"grieß": + [36000.0, 86300.0, 38320.0, 84400.0, 4.0, + "Grießkogel Area"], +} + +for n in maps.keys(): + L, T, R, B, S, name = maps[n] + W = (R-L)/2 + H = (T-B)/2 + for i in range(2): + for j in range(2): + maps["%s%i%i" % (n, i, j)] = [L + i * W, T - j * H, L + (i + 1) * W, T - (j + 1) * H, S, name] +# Keys in the order in which we want the maps output +mapcodes = ["all", "grieß","40", "76", "204", "tc"] +# Field codes +L = 0 +T = 1 +R = 2 +B = 3 +ZOOM = 4 +DESC = 5 + +areacolours = { + '1a' : '#00ffff', + '1b' : '#ff00ff', + '1c' : '#ffff00', + '1d' : '#ffffff', + '2a' : '#ff0000', + '2b' : '#00ff00', + '2c' : '#008800', + '2d' : '#ff9900', + '3' : '#880000', + '4' : '#0000ff', + '6' : '#000000', # doubles for surface fixed pts, and anything else + '7' : '#808080' + } + + +for FONT in [ + "/usr/share/fonts/truetype/freefont/FreeSans.ttf", + "/usr/X11R6/lib/X11/fonts/truetype/arial.ttf", + "C:\WINNT\Fonts\ARIAL.TTF" + ]: + if os.path.isfile(FONT): break +TEXTSIZE = 16 +CIRCLESIZE =8 +LINEWIDTH = 2 +myFont = ImageFont.truetype(FONT, TEXTSIZE) + +def mungecoord(x, y, mapcode, img): + # Top of Zinken is 73 1201 = dataset 34542 81967 + # Top of Hinter is 1073 562 = dataset 36670 83317 + # image is 1417 by 2201 + # FACTOR1 = 1000.0 / (36670.0-34542.0) + # FACTOR2 = (1201.0-562.0) / (83317 - 81967) + # FACTOR = (FACTOR1 + FACTOR2)/2 + # The factors aren't the same as the scanned map's at a slight angle. I + # can't be bothered to fix this. Since we zero on the Hinter it makes + # very little difference for caves in the areas round 76 or 204. + # xoffset = (x - 36670)*FACTOR + # yoffset = (y - 83317)*FACTOR + # return (1073 + xoffset, 562 - yoffset) + + m = maps[mapcode] + factorX, factorY = img.size[0] / (m[R] - m[L]), img.size[1] / (m[T] - m[B]) + return ((x - m[L]) * factorX, (m[T] - y) * factorY) + +COL_TYPES = {True: "red", + False: "#dddddd", + "Reference": "#dddddd"} + +def plot(surveypoint, number, point_type, label, mapcode, draw, img): + try: + ss = SurvexStation.objects.lookup(surveypoint) + E, N = ss.x, ss.y + shortnumber = number.replace("—","") + (x,y) = map(int, mungecoord(E, N, mapcode, img)) + #imgmaps[maparea].append( [x-4, y-SIZE/2, x+4+draw.textsize(shortnumber)[0], y+SIZE/2, shortnumber, label] ) + draw.rectangle([(x+CIRCLESIZE, y-TEXTSIZE/2), (x+CIRCLESIZE*2+draw.textsize(shortnumber)[0], y+TEXTSIZE/2)], fill="#ffffff") + draw.text((x+CIRCLESIZE * 1.5,y-TEXTSIZE/2), shortnumber, fill="#000000") + draw.ellipse([(x-CIRCLESIZE,y-CIRCLESIZE),(x+CIRCLESIZE,y+CIRCLESIZE)], fill=COL_TYPES[point_type], outline="#000000") + except: + pass + +def prospecting_image(request, name): + + mainImage = Image.open(os.path.join(settings.SURVEY_SCANS, "location_maps", "pguidemap.jpg")) + if settings.PUBLIC_SITE and not request.user.is_authenticated(): + mainImage = Image.new("RGB", mainImage.size, '#ffffff') + m = maps[name] + #imgmaps = [] + if name == "all": + img = mainImage + else: + M = maps['all'] + W, H = mainImage.size + l = int((m[L] - M[L]) / (M[R] - M[L]) * W) + t = int((m[T] - M[T]) / (M[B] - M[T]) * H) + r = int((m[R] - M[L]) / (M[R] - M[L]) * W) + b = int((m[B] - M[T]) / (M[B] - M[T]) * H) + img = mainImage.crop((l, t, r, b)) + w = int(round(m[ZOOM] * (m[R] - m[L]) / (M[R] - M[L]) * W)) + h = int(round(m[ZOOM] * (m[B] - m[T]) / (M[B] - M[T]) * H)) + img = img.resize((w, h), Image.BICUBIC) + draw = ImageDraw.Draw(img) + draw.setfont(myFont) + if name == "all": + for maparea in maps.keys(): + if maparea == "all": + continue + localm = maps[maparea] + l,t = mungecoord(localm[L], localm[T], "all", img) + r,b = mungecoord(localm[R], localm[B], "all", img) + text = maparea + " map" + textlen = draw.textsize(text)[0] + 3 + draw.rectangle([l, t, l+textlen, t+TEXTSIZE+2], fill='#ffffff') + draw.text((l+2, t+1), text, fill="#000000") + #imgmaps.append( [l, t, l+textlen, t+SIZE+2, "submap" + maparea, maparea + " subarea map"] ) + draw.line([l, t, r, t], fill='#777777', width=LINEWIDTH) + draw.line([l, b, r, b], fill='#777777', width=LINEWIDTH) + draw.line([l, t, l, b], fill='#777777', width=LINEWIDTH) + draw.line([r, t, r, b], fill='#777777', width=LINEWIDTH) + draw.line([l, t, l+textlen, t], fill='#777777', width=LINEWIDTH) + draw.line([l, t+TEXTSIZE+2, l+textlen, t+TEXTSIZE+2], fill='#777777', width=LINEWIDTH) + draw.line([l, t, l, t+TEXTSIZE+2], fill='#777777', width=LINEWIDTH) + draw.line([l+textlen, t, l+textlen, t+TEXTSIZE+2], fill='#777777', width=LINEWIDTH) + #imgmaps[maparea] = [] + # Draw scale bar + m100 = int(100 / (m[R] - m[L]) * img.size[0]) + draw.line([10, TEXTSIZE*3, 10, TEXTSIZE*2], fill='#000000', width=LINEWIDTH) + draw.line([10, TEXTSIZE*2, 10+m100, TEXTSIZE*2], fill='#000000', width=LINEWIDTH) + draw.line([10+m100, TEXTSIZE * 3, 10+m100, TEXTSIZE*2], fill='#000000', width=LINEWIDTH) + label = "100m" + draw.text([10 + (m100 - draw.textsize(label)[0]) / 2, TEXTSIZE/2], label, fill='#000000') + plot("laser.0_7", "BNase", "Reference", "Bräuning Nase laser point", name, draw, img) + plot("226-96", "BZkn", "Reference", "Bräuning Zinken trig point", name, draw, img) + plot("vd1","VD1","Reference", "VD1 survey point", name, draw, img) + plot("laser.kt114_96","HSK","Reference", "Hinterer Schwarzmooskogel trig point", name, draw, img) + plot("2000","Nipple","Reference", "Nipple (Weiße Warze)", name, draw, img) + plot("3000","VSK","Reference", "Vorderer Schwarzmooskogel summit", name, draw, img) + plot("topcamp", "TC", "Reference", "Top Camp", name, draw, img) + plot("laser.0", "LSR0", "Reference", "Laser Point 0", name, draw, img) + plot("laser.0_1", "LSR1", "Reference", "Laser Point 0/1", name, draw, img) + plot("laser.0_3", "LSR3", "Reference", "Laser Point 0/3", name, draw, img) + plot("laser.0_5", "LSR5", "Reference", "Laser Point 0/5", name, draw, img) + plot("225-96", "BAlm", "Reference", "Bräuning Alm trig point", name, draw, img) + for entrance in Entrance.objects.all(): + station = entrance.best_station() + if station: + #try: + areaName = entrance.caveandentrance_set.all()[0].cave.getArea().short_name + plot(station, "%s-%s" % (areaName, str(entrance)[5:]), entrance.needs_surface_work(), str(entrance), name, draw, img) + #except: + # pass + + for (N, E, D, num) in [(35975.37, 83018.21, 100,"177"), # Calculated from bearings + (35350.00, 81630.00, 50, "71"), # From Auer map + (36025.00, 82475.00, 50, "146"), # From mystery map + (35600.00, 82050.00, 50, "35"), # From Auer map + (35650.00, 82025.00, 50, "44"), # From Auer map + (36200.00, 82925.00, 50, "178"), # Calculated from bearings + (35232.64, 82910.37, 25, "181"), # Calculated from bearings + (35323.60, 81357.83, 50, "74") # From Auer map + ]: + (N,E,D) = map(float, (N, E, D)) + maparea = Cave.objects.get(kataster_number = num).getArea().short_name + lo = mungecoord(N-D, E+D, name, img) + hi = mungecoord(N+D, E-D, name, img) + lpos = mungecoord(N-D, E, name, img) + draw.ellipse([lo,hi], outline="#000000") + draw.ellipse([lo[0]+1, lo[1]+1, hi[0]-1, hi[1]-1], outline=areacolours[maparea]) + draw.ellipse([lo[0]+2, lo[1]+2, hi[0]-2, hi[1]-2], outline=areacolours[maparea]) + draw.rectangle([lpos[0],lpos[1]-TEXTSIZE/2, lpos[0] + draw.textsize(name)[0], lpos[1]+TEXTSIZE/2], fill="#ffffff") + draw.text((lpos[0], lpos[1]-TEXTSIZE/2), num, fill="#000000") + response = HttpResponse(content_type = "image/png") + del draw + img.save(response, "PNG") + return response + +STATIONS = {} +poslineregex = re.compile("^\(\s*([+-]?\d*\.\d*),\s*([+-]?\d*\.\d*),\s*([+-]?\d*\.\d*)\s*\)\s*([^\s]+)$") +def LoadPos(): + call([settings.CAVERN, "--output=%s/all.3d" % settings.SURVEX_DATA, "%s/all.svx" % settings.SURVEX_DATA]) + call([settings.THREEDTOPOS, '%sall.3d' % settings.SURVEX_DATA], cwd = settings.SURVEX_DATA) + posfile = open("%sall.pos" % settings.SURVEX_DATA) + posfile.readline()#Drop header + for line in posfile.readlines(): + r = poslineregex.match(line) + if r: + x, y, z, name = r.groups() + STATIONS[name] = (x, y, z) diff --git a/core/views_survex.py b/core/views_survex.py index cf3b556..3c53625 100644 --- a/core/views_survex.py +++ b/core/views_survex.py @@ -243,7 +243,8 @@ def identifycavedircontents(gcavedir): else: subsvx.append(nf) else: - assert re.match(".*?(?:.3d|.log|.err|.txt|.tmp|.diff|.e?spec|~)$", f), (gcavedir, f) + pass + #assert re.match(".*?(?:.3d|.log|.err|.txt|.tmp|.diff|.e?spec|~)$", f), (gcavedir, f) subsvx.sort() #assert primesvx, (gcavedir, subsvx) if primesvx: @@ -317,4 +318,4 @@ def survexcavesingle(request, survex_cave): -
\ No newline at end of file + |