@ -52,6 +52,7 @@ class lcl:
self . segments = self . dat_to_dict ( lcldir + ' SEGMENTS.DAT ' , ' ISO 8859-15 ' , ' LCD ' )
self . segments = self . dat_to_dict ( lcldir + ' SEGMENTS.DAT ' , ' ISO 8859-15 ' , ' LCD ' )
self . allocated_codes = self . dat_to_dict ( lcldir + ' LOCATIONCODES.DAT ' , ' ISO 8859-15 ' , ' LCD ' )
self . allocated_codes = self . dat_to_dict ( lcldir + ' LOCATIONCODES.DAT ' , ' ISO 8859-15 ' , ' LCD ' )
self . areas = self . dat_to_dict ( lcldir + ' ADMINISTRATIVEAREA.DAT ' , ' ISO 8859-15 ' , ' LCD ' )
self . areas = self . dat_to_dict ( lcldir + ' ADMINISTRATIVEAREA.DAT ' , ' ISO 8859-15 ' , ' LCD ' )
#code.interact(local=locals())
def lcn_allocated ( self , LCN ) :
def lcn_allocated ( self , LCN ) :
return bool ( self . allocated_codes [ LCN ] [ " ALLOCATED " ] )
return bool ( self . allocated_codes [ LCN ] [ " ALLOCATED " ] )
def get_poffsets ( self , LCD ) :
def get_poffsets ( self , LCD ) :
@ -193,6 +194,29 @@ class tmc_event:
return ( " invalid event, ecn: %i " % self . ecn )
return ( " invalid event, ecn: %i " % self . ecn )
def __repr__ ( self ) :
def __repr__ ( self ) :
return " ecn: %i " % self . ecn
return " ecn: %i " % self . ecn
class tmc_segment :
def __init__ ( self , lcn , tableobj ) :
self . lcn = lcn
self . tableobj = tableobj
self . lcl_obj = tableobj . lcl_obj
self . roadnumber = " "
self . roadname = " "
self . first_name = " "
self . second_name = " "
if self . lcl_obj . lcn_allocated ( lcn ) :
try :
self . loc_dict = self . lcl_obj . get_segment ( lcn )
self . roadnumber = self . loc_dict [ ' ROADNUMBER ' ]
if not self . loc_dict [ ' RNID ' ] == u " " :
self . roadname = self . lcl_obj . get_name ( int ( self . loc_dict [ ' RNID ' ] ) )
if not self . loc_dict [ ' N1ID ' ] == u " " :
self . first_name = self . lcl_obj . get_name ( int ( self . loc_dict [ ' N1ID ' ] ) )
if not self . loc_dict [ ' N2ID ' ] == u " " :
self . second_name = self . lcl_obj . get_name ( int ( self . loc_dict [ ' N2ID ' ] ) )
except KeyError :
print ( " segment ' %i ' not found " % lcn )
elif self . tableobj . log or self . tableobj . debug :
print ( " lcn not allocated %i " % lcn )
class tmc_location :
class tmc_location :
def __ref_locs ( self , lcn , name_string = " " ) :
def __ref_locs ( self , lcn , name_string = " " ) :
if ( lcn == 34196 ) : #europe
if ( lcn == 34196 ) : #europe
@ -200,17 +224,20 @@ class tmc_location:
else :
else :
try :
try :
loc_dict = self . lcl_obj . get_area ( lcn )
loc_dict = self . lcl_obj . get_area ( lcn )
aref = int ( loc_dict [ u ' POL_LCD ' ] )
loc_name = self . lcl_obj . get_name ( int ( self . loc_dict [ ' N1ID ' ] ) )
loc_name = self . lcl_obj . get_name ( int ( self . loc_dict [ ' N1ID ' ] ) )
aref = int ( loc_dict [ u ' POL_LCD ' ] )
return ( self . __ref_locs ( aref , name_string + " , " + loc_name ) )
return ( self . __ref_locs ( aref , name_string + " , " + loc_name ) )
except KeyError :
except KeyError : #no area with lcn
return ( name_string )
return ( name_string )
except ValueError : #POL_LCD was empty (no int)
return ( name_string + loc_name )
def __getitem__ ( self , item ) :
def __getitem__ ( self , item ) :
return self . loc_dict [ item ]
return self . loc_dict [ item ]
def __init__ ( self , lcn , lcl_ obj) :
def __init__ ( self , lcn , table obj) :
self . lcn = lcn
self . lcn = lcn
self . lcl_obj = lcl_obj
self . tableobj = tableobj
self . reflocs = self . __ref_locs ( lcn )
self . lcl_obj = tableobj . lcl_obj
self . reflocs = " "
self . is_valid = False
self . is_valid = False
self . loc_dict = { }
self . loc_dict = { }
self . has_koord = False
self . has_koord = False
@ -218,21 +245,31 @@ class tmc_location:
if self . lcl_obj . lcn_allocated ( lcn ) :
if self . lcl_obj . lcn_allocated ( lcn ) :
try :
try :
self . loc_dict = self . lcl_obj . get_point ( lcn )
self . loc_dict = self . lcl_obj . get_point ( lcn )
self . is_valid = True
self . reflocs = self . __ref_locs ( lcn )
self . ltype = self . loc_dict [ u ' CLASS ' ] + self . loc_dict [ u ' TCD ' ]
self . ltype = self . loc_dict [ u ' CLASS ' ] + self . loc_dict [ u ' TCD ' ]
try :
try :
self . subtype = int ( self . loc_dict [ u ' STCD ' ] )
self . subtype = int ( self . loc_dict [ u ' STCD ' ] )
except ValueError : #should not happen, all rows have int
except ValueError : #should not happen, all rows have int
self . subtype = 0
self . subtype = 0
print ( " location subtype %s is invalid in location %i " % ( self . loc_dict [ u ' STCD ' ] , lcn ) )
print ( " location subtype %s is invalid in location %i " % ( self . loc_dict [ u ' STCD ' ] , lcn ) )
self . roadnumber = " "
if not self . loc_dict [ ' RNID ' ] == u " " :
self . roadname = self . lcl_obj . get_name ( int ( self . loc_dict [ ' RNID ' ] ) )
self . roadname = self . lcl_obj . get_name ( int ( self . loc_dict [ ' RNID ' ] ) )
self . first_name = self . lcl_obj . get_name ( int ( self . loc_dict [ ' N1ID ' ] ) )
else :
self . second_name = self . lcl_obj . get_name ( int ( self . loc_dict [ ' N2ID ' ] ) )
self . roadname = " "
if not self . loc_dict [ ' N1ID ' ] == u " " :
self . first_name = self . lcl_obj . get_name ( int ( self . loc_dict [ ' N1ID ' ] ) )
else :
self . first_name = " "
if not self . loc_dict [ ' N2ID ' ] == u " " :
self . second_name = self . lcl_obj . get_name ( int ( self . loc_dict [ ' N2ID ' ] ) )
else :
self . second_name = " "
if not self . loc_dict [ ' ROA_LCD ' ] == u " " :
if not self . loc_dict [ ' ROA_LCD ' ] == u " " :
self . linRef = tmc_location ( int ( self . loc_dict [ ' ROA_LCD ' ] ) , tableobj )
self . linRef = tmc_segment ( int ( self . loc_dict [ ' ROA_LCD ' ] ) , tableobj )
self . negative_offset = int ( self . lcl_obj . get_poffsets ( lcd ) [ u " NEG_OFF_LCD " ] )
self . negative_offset = self . lcl_obj . get_poffsets ( lcn ) [ u " NEG_OFF_LCD " ]
self . positive_offset = int ( self . lcl_obj . get_poffsets ( lcd ) [ u " POS_OFF_LCD " ] )
self . positive_offset = self . lcl_obj . get_poffsets ( lcn ) [ u " POS_OFF_LCD " ]
try :
try :
#koords stored in WGS84 format with decimal degrees multiplied with 10^5
#koords stored in WGS84 format with decimal degrees multiplied with 10^5
self . xkoord = int ( self . loc_dict [ u " XCOORD " ] ) / 100000.0
self . xkoord = int ( self . loc_dict [ u " XCOORD " ] ) / 100000.0
@ -244,7 +281,7 @@ class tmc_location:
except ValueError :
except ValueError :
self . has_koord = False
self . has_koord = False
self . is_valid = True
self . is_valid = True
if not lcn == 34196 : #Europe does not have an area reference
if not self . loc_dict [ ' POL_LCD ' ] == " " : #Europe (lcn==34196) does not have an area reference
self . aref = tmc_location ( int ( self . loc_dict [ ' POL_LCD ' ] ) , tableobj )
self . aref = tmc_location ( int ( self . loc_dict [ ' POL_LCD ' ] ) , tableobj )
except KeyError :
except KeyError :
print ( " point ' %i ' not found " % lcn )
print ( " point ' %i ' not found " % lcn )
@ -262,6 +299,8 @@ class tmc_location:
#return __recursion_get_extent_location(offset_loc,extent-1,direction)
#return __recursion_get_extent_location(offset_loc,extent-1,direction)
return offset_loc . get_extent_location ( offset_loc , extent - 1 , direction )
return offset_loc . get_extent_location ( offset_loc , extent - 1 , direction )
def __str__ ( self ) :
def __str__ ( self ) :
return unicode ( self ) . encode ( ' utf-8 ' )
def __unicode__ ( self ) :
if not self . is_valid :
if not self . is_valid :
return " invalid lcn: %i " % ( self . lcn )
return " invalid lcn: %i " % ( self . lcn )
elif self . ltype == " P1 " and self . subtype == 1 : #autobahnkreuz TODO:only add if name does not already contain "Kreuz"
elif self . ltype == " P1 " and self . subtype == 1 : #autobahnkreuz TODO:only add if name does not already contain "Kreuz"
@ -430,7 +469,9 @@ class tmc_dict:
def matchFilter ( self , msg , filters ) :
def matchFilter ( self , msg , filters ) :
if not msg . location . is_valid :
if not msg . location . is_valid :
return True #always show invalid messages
return True #always show invalid messages
loc_str = str ( msg . location ) + str ( msg . location . reflocs ) + str ( msg . location . roadnumber )
loc_str = str ( msg . location ) + str ( msg . location . reflocs )
if not msg . location . linRef == None :
loc_str + = str ( msg . location . linRef . roadnumber )
for f in filters : #filters is list of dicts {"type":"event","str":"Stau"}
for f in filters : #filters is list of dicts {"type":"event","str":"Stau"}
@ -605,7 +646,7 @@ class tmc_message:
def end_loc ( self ) :
def end_loc ( self ) :
return self . location . get_extent_location ( self . location , self . tmc_extent , self . tmc_dir )
return self . location . get_extent_location ( self . location , self . tmc_extent , self . tmc_dir )
def location_text ( self ) :
def location_text ( self ) :
text = str ( self . location ) #use __str__ of location if no location_text implemented
text = unicode ( self . location ) #use __str__ of location if no location_text implemented
#TODO add "dreieck" for P1.2 -> done in tmc_message.__str__
#TODO add "dreieck" for P1.2 -> done in tmc_message.__str__
if not self . location . linRef == None : #test
if not self . location . linRef == None : #test
#self.tmc_extent and self.tmc_dir are ints
#self.tmc_extent and self.tmc_dir are ints
@ -617,12 +658,12 @@ class tmc_message:
else :
else :
print ( offset_loc )
print ( offset_loc )
offset_loc_name = " ###INVALID### "
offset_loc_name = " ###INVALID### "
templates = { " de_1 " : " {A} , {B} in Richtung {C} " #coding handbook: zwischen {D} und {E}, sprachdurchsagen(manchmal): zwischen {E} und {D} TODO: swap D and E if offset-dir negative
templates = { " de_1 " : u " {A} , {B} in Richtung {C} " #coding handbook: zwischen {D} und {E}, sprachdurchsagen(manchmal): zwischen {E} und {D} TODO: swap D and E if offset-dir negative
, " de_2a " : " , zwischen {D} und {E} "
, " de_2a " : u " , zwischen {D} und {E} "
, " de_2b " : " , bei {D} " #extent==0
, " de_2b " : u " , bei {D} " #extent==0
, " en_1 " : " {A} , {B} {C} "
, " en_1 " : u " {A} , {B} {C} "
, " en_2a " : " , between {D} and {E} "
, " en_2a " : u " , between {D} and {E} "
, " en_2b " : " , at {D} " } #extent==0
, " en_2b " : u " , at {D} " } #extent==0
text = templates [ language + " _1 " ] . format ( A = self . location . linRef . roadnumber , B = self . location . linRef . second_name , C = self . location . linRef . first_name )
text = templates [ language + " _1 " ] . format ( A = self . location . linRef . roadnumber , B = self . location . linRef . second_name , C = self . location . linRef . first_name )
if self . location . first_name == offset_loc_name : #similar to self.tmc_extent==0 (but some similar location have same same name)
if self . location . first_name == offset_loc_name : #similar to self.tmc_extent==0 (but some similar location have same same name)
text + = templates [ language + " _2b " ] . format ( D = self . location . first_name )
text + = templates [ language + " _2b " ] . format ( D = self . location . first_name )
@ -642,7 +683,7 @@ class tmc_message:
#EventCode: EventText
#EventCode: EventText
#F
#F
#return unicode(text,encoding="utf-8")
#return unicode(text,encoding="utf-8")
return text
return text . encode ( ' utf-8 ' )
def __str__ ( self ) :
def __str__ ( self ) :
return str ( self . event . updateClass ) + " : " + self . getTime ( ) + " : " + self . events_string ( ) + " ; " + self . multi_str ( )
return str ( self . event . updateClass ) + " : " + self . getTime ( ) + " : " + self . events_string ( ) + " ; " + self . multi_str ( )
def __repr__ ( self ) :
def __repr__ ( self ) :