2013-06-19 03:21:41 +01:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
2005-06-24 23:17:41 +01:00
# Script to create a slightly more useful attempt
# at a prospecting guide.
areas = [ ' ' , ' 1a ' , ' 1b ' , ' 1c ' , ' 1d ' , ' 2a ' , ' 2b ' , ' 2c ' , ' 2d ' , ' 3 ' , ' 4 ' , ' 5 ' , ' 6 ' , ' 7 ' , ' 8a ' , ' 8b ' , ' 8c ' , ' 8d ' , ' 9 ' , ' 10 ' , ' 11 ' ]
areanames = {
2006-06-22 02:01:02 +01:00
' ' : ' 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 ' ,
' 2c ' : ' 2c – Kaninchenhöhle area ' ,
' 2d ' : ' 2d – Steinbrückenhöhle area ' ,
' 3 ' : ' 3 – Bräuning Alm ' ,
2005-06-24 23:17:41 +01:00
' 4 ' : ' 4 – Kratzer valley ' ,
' 5 ' : ' 5 – Schwarzmoos-Wildensee ' ,
' 6 ' : ' 6 – Far plateau ' ,
' 7 ' : ' 7 – Egglgrube ' ,
' 8a ' : ' 8a – Loser south face ' ,
' 8b ' : ' 8b – Loser below Dimmelwand ' ,
' 8c ' : ' 8c – Augst See ' ,
' 8d ' : ' 8d – Loser-Hochganger ridge ' ,
' 9 ' : ' 9 – Gschwandt Alm ' ,
' 10 ' : ' 10 – Altaussee ' ,
2006-06-21 00:58:09 +01:00
' 11 ' : ' 11 – Augstbach '
2005-06-24 23:17:41 +01:00
}
areacolours = {
' 1a ' : ' #00ffff ' ,
' 1b ' : ' #ff00ff ' ,
' 1c ' : ' #ffff00 ' ,
' 1d ' : ' #ffffff ' ,
' 2a ' : ' #ff0000 ' ,
' 2b ' : ' #00ff00 ' ,
' 2c ' : ' #008800 ' ,
' 2d ' : ' #ff9900 ' ,
2006-06-21 00:58:09 +01:00
' 3 ' : ' #880000 ' ,
2005-06-24 23:17:41 +01:00
' 4 ' : ' #0000ff ' ,
2006-06-22 17:06:42 +01:00
' 6 ' : ' #000000 ' , # doubles for surface fixed pts, and anything else
2005-06-24 23:17:41 +01:00
' 7 ' : ' #808080 '
}
cavelists = { }
for a in areas : cavelists [ a ] = [ ]
2013-06-19 03:21:41 +01:00
#check to see if cmd is on $PATH
def exists_in_path ( cmd ) :
# can't search the path if a directory is specified
assert not os . path . dirname ( cmd )
extensions = os . environ . get ( " PATHEXT " , " " ) . split ( os . pathsep )
for directory in os . environ . get ( " PATH " , " " ) . split ( os . pathsep ) :
2015-06-19 23:51:19 +01:00
base = os . path . join ( directory , cmd )
2013-06-19 03:21:41 +01:00
options = [ base ] + [ ( base + ext ) for ext in extensions ]
for filename in options :
if os . path . exists ( filename ) :
return True
return False
2005-06-24 23:17:41 +01:00
def chomp ( s ) :
2006-06-22 02:01:02 +01:00
if not s : return s
2015-06-20 00:06:52 +01:00
if s [ - 1 ] == " \n " : return s [ : - 1 ]
2006-06-21 00:58:09 +01:00
else : return s
2005-06-24 23:17:41 +01:00
def find_effective_number ( c ) :
2006-06-21 00:58:09 +01:00
""" Determine an appropriate number to use. """
if c [ " Kataster Number " ] :
return c [ " Kataster Number " ]
else :
return c [ " Unofficial number " ]
2005-08-03 18:30:30 +01:00
2005-06-24 23:17:41 +01:00
def longnumber ( c , number ) :
2006-06-21 00:58:09 +01:00
""" Both numbers """
2015-06-20 00:06:52 +01:00
if c [ " Unofficial number " ] and c [ " Unofficial number " ] != number :
2006-06-21 00:58:09 +01:00
return number + " ( " + c [ " Unofficial number " ] + " ) "
else :
2005-06-24 23:17:41 +01:00
return number
def find_location ( cave ) :
for fixtype in [ " tag point in dataset " , " other point in dataset " , " exact entrance in dataset (drip line/highest enclosed contour) " , " GPS post SA " , " GPS pre SA " ] :
2015-06-20 00:06:52 +01:00
if cave [ fixtype ] :
2005-06-24 23:17:41 +01:00
return positions [ cave [ fixtype ] ]
return 0
2015-06-19 23:51:19 +01:00
2006-06-22 02:01:02 +01:00
def is_explored ( cave ) :
s = cave [ " Kat Status Code " ]
2015-06-20 00:06:52 +01:00
if not s : return " <td></td> "
2006-06-22 02:01:02 +01:00
s = s . replace ( " (?) " , " " )
if s [ - 1 ] == " " : s = s [ : - 1 ]
2015-06-20 00:06:52 +01:00
if not s :
2015-06-19 23:51:19 +01:00
print " Rogue space in " + find_effective_number ( cave )
2006-06-22 02:01:02 +01:00
return " <td></td> "
code = s [ - 1 ]
2006-06-26 21:05:11 +01:00
if code == ' + ' : status = " good "
elif code in [ ' = ' , ' x ' ] : status = " bad "
elif code in [ ' - ' , ' ? ' ] : status = " awful "
else : return " <td> %s </td> " % code
2006-06-22 02:01:02 +01:00
return " <td class= \" %s \" > %s </td> " % ( status , code )
def is_tagged ( cave ) :
s = chomp ( cave [ " Marking " ] )
s = re . sub ( r ' \ s+(?: \ ( \ ? \ ))?$ ' , " " , s )
if not s and cave [ " Multiple entrances " ] in [ " yes " , " entrance " , " last entrance " ] :
return " <td></td> "
2006-06-26 21:05:11 +01:00
if s == " Tag " : return " <td class= \" good \" > %s </td> " % s
if s in [ " Retag " , " Paint " , " Spit " ] : return " <td class= \" bad \" > %s </td> " % s
if s == " Unmarked " : return " <td class= \" awful \" >None</td> "
if s == " " : return " <td class= \" awful \" ></td> "
2006-06-22 02:01:02 +01:00
print " Unrecognised marking status on %s : %s " % ( find_effective_number ( cave ) , repr ( s ) )
return " <td>ERROR</td> "
def findability_color ( cave ) :
2006-06-26 21:05:11 +01:00
if cave [ " Findability " ] == " Surveyed " : return " good "
elif cave [ " Findability " ] == " Refindable " : return " bad "
elif cave [ " Findability " ] == " Lost " : return " awful "
else : return " "
2006-06-22 02:01:02 +01:00
def is_underground_surveyed ( cave ) :
s = chomp ( cave [ " Underground drawn survey " ] )
2015-06-20 00:06:52 +01:00
if cave [ " Multiple entrances " ] not in [ " " , " yes " ] : return " <td></td> "
2006-06-26 21:05:11 +01:00
if not s :
return " <td class= \" awful \" >None</td> "
2015-06-20 00:06:52 +01:00
if s . find ( " <img " ) > - 1 or s . find ( " <a " ) > - 1 :
2006-06-26 21:05:11 +01:00
return " <td class= \" good \" >Yes</td> "
2006-06-22 02:01:02 +01:00
else :
2006-06-26 21:05:11 +01:00
return " <td class= \" bad \" >Missing</td> "
2006-06-22 02:01:02 +01:00
def have_survey_data ( cave ) :
2015-06-20 00:06:52 +01:00
if cave [ " Multiple entrances " ] not in [ " " , " yes " ] : return " <td></td> "
2006-06-22 02:13:48 +01:00
s = chomp ( cave [ " Underground centre line " ] )
2006-06-26 21:05:11 +01:00
if s : return " <td class= \" good \" >Yes</td> "
s = chomp ( cave [ " Survex file to get length and depth " ] )
if s : return " <td class= \" good \" >Yes</td> "
if cave [ " Kat Status Code " ] and cave [ " Kat Status Code " ] [ 0 ] == ' 1 ' :
# Cave < 50m deep and < 50m long...
# Sadly this band includes caves we really ought to have data for as
# well as caves small enough that a grade 1 sketch is justifiable.
return " <td class= \" bad \" ><small><50m</small></td> "
s = chomp ( cave [ " Underground drawn survey " ] )
if s : return " <td class= \" bad \" >Missing</td> "
return " <td class= \" awful \" >None</td> "
2006-06-22 02:01:02 +01:00
def has_photo ( cave ) :
s = chomp ( cave [ " Photo of location " ] )
2015-06-20 00:06:52 +01:00
if ( cave [ " Multiple entrances " ] not in [ " " , " yes " ] ) and chomp ( cave [ " Autogen file " ] ) == " " :
2006-06-22 02:01:02 +01:00
return " <td></td> "
2006-06-26 21:05:11 +01:00
if not s :
return " <td class= \" awful \" >None</td> "
2015-06-20 00:06:52 +01:00
if s . find ( " <img " ) > - 1 or s . find ( " <a " ) > - 1 :
2006-06-26 21:05:11 +01:00
return " <td class= \" good \" >Yes</td> "
2006-06-22 02:01:02 +01:00
else :
2006-06-26 21:05:11 +01:00
return " <td class= \" bad \" >Missing</td> "
2005-06-24 23:17:41 +01:00
def find_label ( cave , number ) :
t = longnumber ( cave , number ) + " "
if ( cave [ " Name " ] and cave [ " Unofficial Name " ] ) : t + = cave [ " Name " ] + " ( " + cave [ " Unofficial Name " ] + " ) "
elif cave [ " Name " ] : t + = cave [ " Name " ]
else : t + = cave [ " Unofficial Name " ]
try :
n = number
2015-06-20 00:06:52 +01:00
if n [ - 1 ] in string . lowercase : n = n [ : - 1 ]
2005-06-24 23:17:41 +01:00
except :
n = " NONE "
2006-06-22 02:01:02 +01:00
if lengths . has_key ( n ) :
t + = ( " %s m long %s m deep " % ( lengths [ n ] [ 0 ] , lengths [ n ] [ 1 ] ) )
2005-06-24 23:17:41 +01:00
return t
2006-06-22 02:01:02 +01:00
def get_img_name ( maparea ) :
filename = " prospecting_guide "
if maparea != " all " :
filename + = " _ " + maparea + " area "
2006-06-22 18:38:02 +01:00
if showbg :
filename + = " .jpg "
else :
filename + = " .png "
2006-06-22 02:01:02 +01:00
return filename
# Parameters for big map and zoomed subarea maps:
2006-06-22 17:06:42 +01:00
# big map first (zoom factor ignored)
2006-06-22 02:01:02 +01:00
maps = {
2015-06-19 23:51:19 +01:00
# id left top right bottom zoom description
2015-07-21 16:59:14 +01:00
# UTM33 UTM33 UTM33 UTM33 factor
# DO NOT just change the coordinates of "all" - they MUST match the borders of the background image.
" all " : [ 409276. , 5285237. , 413197. , 5279805. , 1.0 , " All " ] ,
" 40 " : [ 411110. , 5281326. , 411603. , 5280722. , 3.0 , " Eishöhle " ] ,
" 76 " : [ 410293. , 5282171. , 410931. , 5281607. , 3.0 , " Eislufthöhle " ] ,
" 204 " : [ 411226. , 5283086. , 411904. , 5282315. , 3.0 , " Steinbrückenhöhle " ] ,
" tc " : [ 410071. , 5281646. , 410939. , 5281036. , 3.0 , " Near Top Camp " ] ,
" gk " : [ 410918. , 5285237. , 413197. , 5283288. , 4.0 , " Grießkogel Area " ] ,
2006-06-22 02:01:02 +01:00
}
# Keys in the order in which we want the maps output
2015-06-19 23:51:19 +01:00
mapcodes = [ " all " , " gk " , " 40 " , " 76 " , " 204 " , " tc " ]
2006-06-22 02:01:02 +01:00
# Field codes
L = 0
T = 1
R = 2
B = 3
2006-06-22 17:06:42 +01:00
ZOOM = 4
DESC = 5
2006-06-22 02:01:02 +01:00
import Image , ImageDraw , ImageFont , string , os , sys
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
2005-06-24 23:17:41 +01:00
SIZE = 8
myFont = ImageFont . truetype ( FONT , SIZE )
2006-06-22 18:38:02 +01:00
showbg = not ( len ( sys . argv ) > 1 and sys . argv [ 1 ] == ' --white ' )
2015-07-21 16:59:14 +01:00
mainImage = Image . open ( " pguidemap.png " )
2006-06-22 18:38:02 +01:00
if not showbg :
2006-06-22 17:06:42 +01:00
mainImage = Image . new ( " RGB " , mainImage . size , ' #ffffff ' )
2006-06-22 02:01:02 +01:00
imgs = { }
draws = { }
imgmaps = { }
2006-06-22 17:06:42 +01:00
factors = { }
2006-06-22 02:01:02 +01:00
for maparea in maps . keys ( ) :
m = maps [ maparea ]
if maparea == " all " :
img = mainImage
else :
2006-06-22 17:06:42 +01:00
M = maps [ ' all ' ]
W , H = mainImage . size
2015-07-21 16:59:14 +01:00
l = int ( float ( m [ L ] - M [ L ] ) / ( M [ R ] - M [ L ] ) * W )
t = int ( float ( m [ T ] - M [ T ] ) / ( M [ B ] - M [ T ] ) * H )
r = int ( float ( m [ R ] - M [ L ] ) / ( M [ R ] - M [ L ] ) * W )
b = int ( float ( m [ B ] - M [ T ] ) / ( M [ B ] - M [ T ] ) * H )
2006-06-22 02:01:02 +01:00
img = mainImage . crop ( ( l , t , r , b ) )
2015-07-21 16:59:14 +01:00
w = int ( round ( m [ ZOOM ] * float ( m [ R ] - m [ L ] ) / ( M [ R ] - M [ L ] ) * W ) )
h = int ( round ( m [ ZOOM ] * float ( m [ B ] - m [ T ] ) / ( M [ B ] - M [ T ] ) * H ) )
2006-06-22 02:01:02 +01:00
print " %s : H %d W %d " % ( maparea , h , w )
img = img . resize ( ( w , h ) , Image . BICUBIC )
imgs [ maparea ] = img
draw = ImageDraw . Draw ( img )
draw . setfont ( myFont )
draws [ maparea ] = draw
imgmaps [ maparea ] = [ ]
# Draw scale bar
2015-07-21 16:59:14 +01:00
m100 = int ( 100.0 / ( m [ R ] - m [ L ] ) * img . size [ 0 ] )
2006-06-22 02:01:02 +01:00
draw . line ( [ 10 , SIZE * 3 , 10 , SIZE * 2 ] , fill = ' #000000 ' )
draw . line ( [ 10 , SIZE * 2 , 10 + m100 , SIZE * 2 ] , fill = ' #000000 ' )
draw . line ( [ 10 + m100 , SIZE * 3 , 10 + m100 , SIZE * 2 ] , fill = ' #000000 ' )
label = " 100m "
draw . text ( [ 10 + ( m100 - draw . textsize ( label ) [ 0 ] ) / 2 , SIZE / 2 ] , label , fill = ' #000000 ' )
2006-06-22 17:06:42 +01:00
factors [ maparea ] = img . size [ 0 ] / ( m [ R ] - m [ L ] ) , img . size [ 1 ] / ( m [ T ] - m [ B ] )
2006-06-22 02:01:02 +01:00
def mungecoord ( x , y , mapcode ) :
2005-06-24 23:17:41 +01:00
# 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)
2015-06-19 23:51:19 +01:00
# FACTOR = (FACTOR1 + FACTOR2)/2
2005-06-24 23:17:41 +01:00
# 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)
2006-06-22 02:01:02 +01:00
m = maps [ mapcode ]
2006-06-22 17:06:42 +01:00
return ( ( x - m [ L ] ) * factors [ mapcode ] [ 0 ] , ( m [ T ] - y ) * factors [ mapcode ] [ 1 ] )
2005-06-24 23:17:41 +01:00
def plot ( loctuple , number , area , label ) :
shortnumber = number . replace ( " — " , " " )
2006-06-22 02:01:02 +01:00
2006-06-22 17:06:42 +01:00
if area in areacolours :
fillcol = areacolours [ area ]
else :
fillcol = 6
2006-06-22 02:01:02 +01:00
for maparea in maps . keys ( ) :
( x , y ) = map ( int , mungecoord ( loctuple [ 0 ] , loctuple [ 1 ] , maparea ) )
draw = draws [ maparea ]
imgmaps [ maparea ] . append ( [ x - 4 , y - SIZE / 2 , x + 4 + draw . textsize ( shortnumber ) [ 0 ] , y + SIZE / 2 , shortnumber , label ] )
draw . rectangle ( [ ( x + 4 , y - SIZE / 2 ) , ( x + 4 + draw . textsize ( shortnumber ) [ 0 ] , y + SIZE / 2 ) ] , fill = " #ffffff " )
draw . text ( ( x + 6 , y - SIZE / 2 ) , shortnumber , fill = " #000000 " )
2006-06-22 17:06:42 +01:00
draw . ellipse ( [ ( x - 4 , y - 4 ) , ( x + 4 , y + 4 ) ] , fill = fillcol , outline = " #000000 " )
2005-06-24 23:17:41 +01:00
def writeout_imagemap ( data , mapname ) :
# Munge the list of coordinates into a proper image map.
2015-06-19 23:51:19 +01:00
# There is a wrinkle here: the HTML spec gives priority
2005-06-24 23:17:41 +01:00
# to the _first_ defined elt, so we swap the order!
n = len ( data )
htmlfile . write ( " <map id= \" %s \" name= \" %s \" > " % ( mapname , mapname ) )
for j in xrange ( n ) :
try :
i = data [ n - j - 1 ]
htmlfile . write ( " <area shape= \" rect \" coords= \" %d , %d , %d , %d \" href= \" #id %s \" title= \" %s \" /> \n " % ( i [ 0 ] , i [ 1 ] , i [ 2 ] , i [ 3 ] , i [ 4 ] , i [ 5 ] ) )
except :
print " Died on " , repr ( data [ n - j - 1 ] )
#raise
htmlfile . write ( " </map> " )
import csv , re , time
cavetabfile = file ( " ../CAVETAB2.CSV " )
fieldnames = chomp ( cavetabfile . next ( ) ) . replace ( ' " ' , ' ' ) . split ( " , " )
cavetab = csv . DictReader ( cavetabfile , fieldnames )
2006-06-21 00:58:09 +01:00
2005-06-24 23:17:41 +01:00
print " Munging lengths.dat "
2007-02-21 15:31:51 +00:00
lengthsfile = file ( " ../lengths.dat " )
2005-06-24 23:17:41 +01:00
lengths = { }
for l in lengthsfile :
t = l . replace ( " \" " , " " ) . replace ( " \n " , " " ) . split ( " \t " )
lengths [ t [ 0 ] ] = ( t [ 1 ] , t [ 2 ] )
print " Done "
2006-06-21 00:58:09 +01:00
# Draw cave passage
2006-06-22 02:01:02 +01:00
print " Munging dump3d output "
2013-06-19 03:21:41 +01:00
if exists_in_path ( " dump3d " ) :
dump3d_binary = " dump3d "
else :
# assume it's in this directory
dump3d_binary = os . path . join ( os . path . dirname ( os . path . realpath ( __file__ ) ) , " ./dump3d " )
2006-06-22 02:01:02 +01:00
positions = { }
surfacecolour = " #808080 "
repath = re . compile ( r ' ^(?:182to(?:tc|184)|tctocol|82to97|vd1to161d|161ftod|161etof|161etog|40entlink2|surfnr161|surf161|kansurf)$ ' )
2013-06-19 03:21:41 +01:00
for fnm in ( " ../all.3d " , " ../alltracks.3d " ) :
2006-06-22 02:01:02 +01:00
for mapcode in draws . keys ( ) :
2013-08-01 16:06:38 +01:00
file3d = os . popen ( dump3d_binary + " " + fnm )
2006-06-22 02:01:02 +01:00
draw = draws [ mapcode ]
lastx , lasty = 0 , 0
for l in file3d :
2015-06-20 00:43:34 +01:00
# Quickly skip data we aren't interested in
if l . startswith ( " ERROR_INFO " ) : continue
if l . startswith ( " XSECT " ) : continue
2013-06-19 03:35:59 +01:00
match = re . match ( r '''
^ #start
2015-06-20 00:43:34 +01:00
( MOVE | LINE | NODE ) #data type
2013-06-19 03:35:59 +01:00
\s + ( - ? [ 0 - 9. ] + ) #X-co-ord
\s + ( - ? [ 0 - 9. ] + ) #Y-co-ord
\s + ( - ? [ 0 - 9. ] + ) #altitude
2013-06-19 03:50:45 +01:00
( ? : #grouping without saving result - for station name
\s + #at least one space
\[ #opening [
( \S * ) #the station name we want to save
\] #closing ]
) ? #end of optional station name group
( ? : #grouping without saving result - for flags
\s + #at least one space separating from [station]
( . * ) #all the flags, including spaces
) ? #end of optional flags group
$ #end of the line
2013-06-19 03:35:59 +01:00
''' , l, re.VERBOSE)
2015-06-19 23:51:19 +01:00
if not match :
2013-08-01 16:06:38 +01:00
print " Unknown: " + l
2013-06-19 03:21:41 +01:00
continue
2015-06-19 23:51:19 +01:00
2006-06-22 02:01:02 +01:00
act , E , N , alt , name , flags = match . groups ( )
2013-06-19 03:21:41 +01:00
# print "act:%s, E:%s, N:%s, name:%s flags:%s" % (act,E,N,name,flags)
2006-06-22 02:01:02 +01:00
# Only need to process NODEs once
if act == " NODE " and mapcode != " all " : continue
if not flags : flags = " "
E , N = map ( float , ( E , N ) )
if act == " NODE " :
positions [ name ] = ( E , N , float ( alt ) )
continue
x , y = map ( int , mungecoord ( E , N , mapcode ) )
if act == " LINE " :
2006-06-26 21:05:11 +01:00
if re . search ( r ' \ bSURFACE \ b ' , flags ) :
if re . search ( repath , name ) :
2006-06-22 02:01:02 +01:00
draw . line ( [ lastx , lasty , x , y ] , fill = ' #008000 ' )
else :
draw . line ( [ lastx , lasty , x , y ] , fill = ' #808080 ' )
else :
draw . line ( [ lastx , lasty , x , y ] , fill = " #800080 " )
lastx , lasty = x , y
2014-08-05 13:08:03 +01:00
#if not file3d.close():
# FIXME: If dump3d can't give an error and exits with non-zero status, this
2013-08-01 16:06:38 +01:00
# doesn't get triggered...
2014-08-05 13:08:03 +01:00
#print "Running command: %s %s failed: %s" % (dump3d_binary, fnm, file3d)
2006-06-22 02:01:02 +01:00
surfacecolour = " #008000 "
repath = re . compile ( r ' ^ ' )
print " Done "
2015-06-19 23:51:19 +01:00
2006-06-21 00:58:09 +01:00
cavestoplot = [ ]
2005-06-24 23:17:41 +01:00
for cave in cavetab :
if cave [ " Link file " ] : continue
number = find_effective_number ( cave )
2015-06-20 00:06:52 +01:00
if cave [ " Multiple entrances " ] not in [ " " , " yes " ] :
2005-06-24 23:17:41 +01:00
number = " — " + cachednumber + cave [ " Entrances " ]
shortnumber = cachednumber
if not cave [ " Area " ] : cave [ " Area " ] = cachedarea
if not cave [ " Name " ] : cave [ " Name " ] = cachedname
2015-06-19 23:51:19 +01:00
else :
2005-06-24 23:17:41 +01:00
cachednumber = number
shortnumber = number
cachedname = cave [ " Name " ] or cave [ " Unofficial Name " ]
cachedarea = cave [ " Area " ]
2015-06-19 23:51:19 +01:00
2005-06-24 23:17:41 +01:00
area = cave [ " Area " ]
2015-06-19 23:51:19 +01:00
# We have some areas like '2b or 4 (unclear)' - just chop the space
2006-06-21 00:58:09 +01:00
# and everything after it for these.
area = re . sub ( r ' .* ' , " " , area )
if area == ' 1626 ' or area == ' nonexistent ' : continue
2013-08-01 16:06:38 +01:00
try :
2013-06-19 03:21:41 +01:00
loctuple = find_location ( cave )
2005-06-24 23:17:41 +01:00
except :
2013-06-19 03:21:41 +01:00
print " Unable to find location for %s " % ( number )
else :
2015-06-19 23:51:19 +01:00
label = find_label ( cave , shortnumber )
2013-06-19 03:21:41 +01:00
if ( cave [ " Multiple entrances " ] == " yes " ) :
locn = " <td colspan= \" 3 \" > </td> "
elif ( loctuple ) :
2015-06-19 23:51:19 +01:00
locn = " <td class= \" locn good \" > %d </td><td class= \" locn good \" > %d </td><td class= \" locn good \" > %d </td> " % loctuple
2013-06-19 03:21:41 +01:00
cavestoplot . append ( ( loctuple , number , area , label ) )
else :
locn = " <td colspan= \" 3 \" class= %s > " % findability_color ( cave ) + ( cave [ " Findability " ] or ' ? ' ) + " </td> "
try :
cavelists [ area ] . append ( ( number , cave , locn ) )
except :
print " Bad area ' %s ' for cave %s " % ( area , number )
2005-06-24 23:17:41 +01:00
2006-09-07 03:28:03 +01:00
if showbg :
htmlfile = file ( " /dev/null " , " w " )
else :
htmlfile = file ( " ../../handbook/prospecting_guide.html " , " w " )
2005-06-24 23:17:41 +01:00
2013-06-19 04:05:46 +01:00
htmlfile . write ( " <html><head><meta http-equiv= \" Content-type \" content= \" text/html;charset=UTF-8 \" ><title>Prospecting Guide</title> \n " )
2015-06-19 23:44:17 +01:00
htmlfile . write ( " <script lang= \" Javascript \" ><!-- \n " )
2015-06-19 23:30:46 +01:00
for maparea in mapcodes :
2015-06-19 23:44:17 +01:00
htmlfile . write ( " bg %s = false; \n " % maparea )
htmlfile . write ( " //--> \n </script> \n " )
2006-06-22 02:01:02 +01:00
htmlfile . write ( """
< style type = " text/css " >
. locn { font - size : x - small }
. bad { background - color : #ff9955; text-align: center }
2012-08-17 15:57:41 +01:00
. good { background - color : #99f<p><b>Notes:</b></p><ul><li>A marking status of \"Retag\" means a tag is in place but it carries a provisional number, or in some cases an incorrect number, and needs replacing with a new tag.</li>\n<li>Kataster status codes indicate the size of a cave, its character and its exploration status, as described <a href=\"../katast.htm\">here</a>.</li><li>For more info on each cave, see the links to detailed description pages.</li></ul>\nf99; text-align: center }
2006-06-22 02:01:02 +01:00
. awful { background - color : #ff5555; text-align: center }
2006-06-26 21:05:11 +01:00
. notours . good { background - color : #ffffff; }
. notours . bad { background - color : #ffffff; }
. notours . awful { background - color : #ffffff; }
2020-04-11 16:21:42 +01:00
< / style >
< meta name = " keywords " content = " NOEDIT " >
< / head > """ )
2015-06-19 23:30:46 +01:00
htmlfile . write ( " <body><h1>Prospecting Guide</h1> " )
2006-09-07 03:27:57 +01:00
htmlfile . write ( " <p><small>Generated " + time . strftime ( " % Y- % m- %d % H: % M: % S % Z " ) + " by " + sys . argv [ 0 ] + " </small></p> \n " )
2006-06-22 02:01:02 +01:00
htmlfile . write ( " <p><b>Notes:</b></p><ul><li>A marking status of \" Retag \" means a tag is in place but it carries a provisional number, or in some cases an incorrect number, and needs replacing with a new tag.</li> \n <li>Kataster status codes indicate the size of a cave, its character and its exploration status, as described <a href= \" ../katast.htm \" >here</a>.</li><li>For more info on each cave, see the links to detailed description pages.</li></ul> \n " )
for maparea in mapcodes :
filename = get_img_name ( maparea )
if maparea != " all " :
2006-06-22 17:06:42 +01:00
htmlfile . write ( " <h3 id= \" idsubmap %s \" > %s area detail</h3> \n " % ( maparea , maps [ maparea ] [ DESC ] ) )
2006-06-22 18:38:02 +01:00
basename = filename [ 0 : - 3 ]
htmlfile . write ( " <button onclick= \" if (bg %s ) img %s .src = ' %s png ' ; else img %s .src = ' ../noinfo/ %s jpg ' ; bg %s = !bg %s ; \" >Toggle Background</button> \n " % ( maparea , maparea , basename , maparea , basename , maparea , maparea ) )
2006-06-22 17:22:50 +01:00
htmlfile . write ( " <small>Note: this requires a login to work!</small> \n " )
2006-06-22 17:06:42 +01:00
htmlfile . write ( " <p><img src= \" %s \" usemap= \" #map %s \" ismap= \" ismap \" name= \" img %s \" " % ( filename , maparea , maparea ) )
htmlfile . write ( " width= \" %d \" height= \" %d \" /></p> \n " % imgs [ maparea ] . size )
2005-06-24 23:17:41 +01:00
2006-06-21 00:58:09 +01:00
cachednumber = " "
cachedarea = " "
cachedname = " "
2005-06-24 23:17:41 +01:00
2006-06-21 00:58:09 +01:00
# Plot the subareas on the full map
2006-06-22 02:01:02 +01:00
for maparea in maps . keys ( ) :
if maparea == " all " :
continue
m = maps [ maparea ]
l , t = mungecoord ( m [ L ] , m [ T ] , " all " )
r , b = mungecoord ( m [ R ] , m [ B ] , " all " )
text = maparea + " map "
textlen = draws [ ' all ' ] . textsize ( text ) [ 0 ] + 3
draws [ ' all ' ] . rectangle ( [ l , t , l + textlen , t + SIZE + 2 ] , fill = ' #ffffff ' )
draws [ ' all ' ] . text ( ( l + 2 , t + 1 ) , text , fill = " #000000 " )
imgmaps [ ' all ' ] . append ( [ l , t , l + textlen , t + SIZE + 2 , " submap " + maparea , maparea + " subarea map " ] )
draws [ ' all ' ] . rectangle ( [ l , t , r , b ] , outline = ' #777777 ' )
draws [ ' all ' ] . rectangle ( [ l , t , l + textlen , t + SIZE + 2 ] , outline = ' #777777 ' )
2005-06-24 23:17:41 +01:00
2006-06-21 00:58:09 +01:00
# Plot faked positions first so that real caves go on top of the large circles
2005-06-24 23:17:41 +01:00
fakedpositions = file ( " fakedpositions.dat " )
for p in fakedpositions :
try :
2005-08-08 18:55:04 +01:00
( x , y , d , name ) = re . match ( r ' \ (([0-9.]*?), \ t([0-9.]*?), \ t([0-9.]*?) \ ) \ t(.*?)[ \ t ]*# ' , chomp ( p ) ) . groups ( )
2005-06-24 23:17:41 +01:00
except :
print " Couldn ' t understand " + repr ( chomp ( p ) )
continue
2006-06-21 00:58:09 +01:00
2015-06-19 23:51:19 +01:00
# Find the area with this cave in
2005-08-08 18:55:04 +01:00
area = ' '
for tryarea in areas :
for ( number , cave , locn ) in cavelists [ tryarea ] :
if name == number :
area = tryarea
break
# FIXME really want to break from both loops at once
# but I don't know how to in Python
if area != ' ' :
break
2015-06-19 23:51:19 +01:00
2006-06-21 00:58:09 +01:00
( x , y , d ) = map ( float , ( x , y , d ) )
2006-06-22 02:01:02 +01:00
for maparea in maps . keys ( ) :
lo = mungecoord ( x - d , y + d , maparea )
hi = mungecoord ( x + d , y - d , maparea )
lpos = mungecoord ( x - d , y , maparea )
draw = draws [ maparea ]
draw . ellipse ( [ lo , hi ] , outline = " #000000 " )
draw . ellipse ( [ lo [ 0 ] + 1 , lo [ 1 ] + 1 , hi [ 0 ] - 1 , hi [ 1 ] - 1 ] , outline = areacolours [ area ] )
draw . ellipse ( [ lo [ 0 ] + 2 , lo [ 1 ] + 2 , hi [ 0 ] - 2 , hi [ 1 ] - 2 ] , outline = areacolours [ area ] )
draw . rectangle ( [ lpos [ 0 ] , lpos [ 1 ] - SIZE / 2 , lpos [ 0 ] + draw . textsize ( name ) [ 0 ] , lpos [ 1 ] + SIZE / 2 ] , fill = " #ffffff " )
imgmaps [ maparea ] . append ( [ lpos [ 0 ] , lpos [ 1 ] - SIZE / 2 , lpos [ 0 ] + draw . textsize ( name ) [ 0 ] , lpos [ 1 ] + SIZE / 2 , name , " Approx position of %s " % name ] )
draw . text ( ( lpos [ 0 ] , lpos [ 1 ] - SIZE / 2 ) , name , fill = " #000000 " )
2006-06-21 00:58:09 +01:00
2006-09-07 03:28:54 +01:00
plot ( positions [ " laser.0_7 " ] , " BNase " , " 6 " , " Bräuning Nase laser point " )
2006-06-21 00:58:09 +01:00
plot ( positions [ " 226-96 " ] , " BZkn " , " 6 " , " Bräuning Zinken trig point " )
plot ( positions [ " vd1 " ] , " VD1 " , " 6 " , " VD1 survey point " )
2015-06-19 23:51:19 +01:00
plot ( positions [ " laser.kt114_96 " ] , " HSK " , " 6 " , " Hinterer Schwarzmooskogel trig point " )
2006-06-21 00:58:09 +01:00
plot ( positions [ " 2000 " ] , " Nipple " , " 6 " , " Nipple (Weiße Warze) " )
plot ( positions [ " 3000 " ] , " VSK " , " 6 " , " Vorderer Schwarzmooskogel summit " )
plot ( positions [ " topcamp " ] , " TC " , " 6 " , " Top Camp " )
2006-06-22 02:01:02 +01:00
plot ( positions [ " laser.0 " ] , " LSR0 " , " 6 " , " Laser Point 0 " )
2006-06-21 00:58:09 +01:00
plot ( positions [ " laser.0_1 " ] , " LSR1 " , " 6 " , " Laser Point 0/1 " )
2006-09-07 03:28:41 +01:00
plot ( positions [ " laser.0_3 " ] , " LSR3 " , " 6 " , " Laser Point 0/3 " )
2006-06-21 00:58:09 +01:00
plot ( positions [ " laser.0_5 " ] , " LSR5 " , " 6 " , " Laser Point 0/5 " )
2006-09-07 03:28:41 +01:00
plot ( positions [ " 225-96 " ] , " BAlm " , " 6 " , " Bräuning Alm trig point " )
2006-06-21 00:58:09 +01:00
for ( loctuple , number , area , label ) in cavestoplot :
2006-06-22 17:06:42 +01:00
plot ( loctuple , number , area , label )
2006-06-21 00:58:09 +01:00
for area in areas :
if area :
htmlfile . write ( " <h3><span style= \" background-color: %s ; border: 1px solid black \" > </span> %s </h3> " % ( areacolours . get ( area , " #ffffff " ) , areanames [ area ] ) )
else :
htmlfile . write ( " <h3>Location unclear</h3> " )
2006-06-22 02:01:02 +01:00
htmlfile . write ( " <table border= \" 1 \" > \n " )
htmlfile . write ( " <tr><th>Cave Number</th><th>Name</th><th>Finished</th><th>Survey<br>Data</th><th>Survey<br>Drawn</th><th>Marked</th><th>Photo</th><th>E</th><th>N</th><th>Alt</th><th>Location</th> " )
2006-06-21 00:58:09 +01:00
for ( number , cave , locn ) in cavelists [ area ] :
2006-06-26 21:05:11 +01:00
# We only check the "oursness" for the first entrance.
if cave [ " Multiple entrances " ] in [ " " , " yes " ] :
2006-06-26 22:16:06 +01:00
notours = not re . search ( r ' CUCC ' , cave [ ' Explorers ' ] )
2006-06-26 21:05:11 +01:00
if notours :
htmlfile . write ( " <tr class= \" notours \" > " )
else :
htmlfile . write ( " <tr> " )
2006-06-21 00:58:09 +01:00
if cave [ " Autogen file " ] :
2006-06-26 21:05:11 +01:00
htmlfile . write ( " <td><a href= \" ../ %s \" > %s </a></td><td><a id= \" id %s \" > %s </a></td> " % ( cave [ " Autogen file " ] , longnumber ( cave , number ) , number . replace ( " — " , " " ) , cave [ " Name " ] or cave [ " Unofficial Name " ] ) )
2006-06-21 00:58:09 +01:00
else :
2015-06-19 23:51:19 +01:00
htmlfile . write ( " <td> %s </td><td><a id= \" id %s \" > %s </a></td> " % ( longnumber ( cave , number ) , number . replace ( " — " , " " ) , cave [ " Name " ] or cave [ " Unofficial Name " ] ) )
2006-06-22 02:01:02 +01:00
htmlfile . write ( is_explored ( cave ) )
htmlfile . write ( have_survey_data ( cave ) )
htmlfile . write ( is_underground_surveyed ( cave ) )
htmlfile . write ( is_tagged ( cave ) )
htmlfile . write ( has_photo ( cave ) )
htmlfile . write ( locn )
2015-06-20 00:06:52 +01:00
if cave [ " Findability " ] != " Surveyed " and cave [ " Multiple entrances " ] != " yes " :
2006-06-21 00:58:09 +01:00
htmlfile . write ( " <td class= \" locn \" > %s %s </td> " % ( cave [ " Location " ] , cave [ " Bearings " ] ) )
htmlfile . write ( " </tr> \n " )
2015-06-19 23:51:19 +01:00
2006-06-21 00:58:09 +01:00
htmlfile . write ( " </table> \n " )
2006-06-22 02:01:02 +01:00
for maparea in imgmaps . keys ( ) :
writeout_imagemap ( imgmaps [ maparea ] , " map " + maparea )
2005-06-24 23:17:41 +01:00
htmlfile . write ( " </body></html> " )
htmlfile . close ( )
2006-09-07 03:27:51 +01:00
if showbg :
imgpath = " ../ "
else :
imgpath = " ../../handbook/ "
2006-06-22 02:01:02 +01:00
for maparea in imgs . keys ( ) :
del draws [ maparea ]
filename = get_img_name ( maparea )
2006-09-07 03:27:51 +01:00
imgs [ maparea ] . save ( imgpath + filename )
2005-06-24 23:17:41 +01:00
2006-06-22 02:01:02 +01:00
# vim:syntax=python:set ts=4: