def test_color_box(self): for cfg in (NullConfig(), WmtConfig): with self.subTest(i=cfg): f = ShieldFactory(['.color_box'], cfg) self.assertIsNone(f.create({}, '')) self.assert_shield( f.create({'color' : '#f0f0f0'}, ''), 'cbox_None_f0f0f0')
def test_nordic_symbol(self): for cfg in (NullConfig(), WmtConfig): with self.subTest(i=cfg): f = ShieldFactory(['.nordic_symbol'], cfg) self.assertIsNone(f.create({'color' : '#f0f0f0'}, '')) self.assertIsNone(f.create({'piste:type' : 'nordic'}, '')) self.assert_shield( f.create({'piste:type' : 'nordic', 'color' : '#f0f0f0'}, ''), 'nordic_None_f0f0f0')
def test_slope_symbol(self): for cfg in (ShieldConfig({'slope_colors' : WmtConfig.slope_colors}, {}), WmtConfig): with self.subTest(i=cfg): f = ShieldFactory(['.slope_symbol'], cfg) self.assertIsNone(f.create({}, '')) self.assert_shield( f.create({'piste:type' : 'downhill'}, '', difficulty=0), 'slope_None_0') self.assert_shield( f.create({'piste:type' : 'downhill', 'piste:ref' : 'A'}, '', difficulty=9), 'slope_None_9_0041')
def create_tables(self): symbol_factory = ShieldFactory(self.site_config.ROUTES.symbols, self.site_config.SYMBOLS) # all the route stuff we take from the RoutesDB implmentation tables = self.create_table_dict(symbol_factory, PisteRoutes) # now create the additional joined ways tabname = self.site_config.DB_TABLES subset = and_(text(self.site_config.DB_WAY_SUBSET), column('id').notin_(select([tables['relway'].c.id]))) filt = FilteredTable(self.metadata, tabname.way_table + '_view', self.osmdata.way, subset) tables['norelway_filter'] = filt ways = PisteWayInfo(self.metadata, tabname.way_table, filt, self.osmdata, self.site_config.ROUTES, symbol_factory) tables['ways'] = ways cols = ('name', 'symbol', 'difficulty', 'piste') joins = GroupedWayTable(self.metadata, tabname.joinedway, ways, cols) tables['joined_ways'] = joins _RouteTables = namedtuple('_RouteTables', tables.keys()) return _RouteTables(**tables)
def create_tables(self): symbol_factory = ShieldFactory(self.site_config.ROUTES.symbols, self.site_config.SYMBOLS) tables = self.create_table_dict(symbol_factory) _RouteTables = namedtuple('_RouteTables', tables.keys()) return _RouteTables(**tables)
def test_kct_symbol(self): f = ShieldFactory(['.kct_symbol'], NullConfig()) self.assertIsNone(f.create({'kct_major' : 'red'}, '')) mincfg = ShieldConfig({'kct_types' : ('major', ), 'kct_colors' : {'red' : (1, 0, 0)}, 'kct_path' : '{data}/kct'}, {}) for cfg in (mincfg, WmtConfig): f = ShieldFactory(['.kct_symbol'], cfg) self.assertIsNone(f.create({'operator' : 'kst', 'colour' : 'red'}, '')) self.assertIsNone(f.create({'operator' : 'kst', 'symbol' : 'major'}, '')) self.assertIsNone(f.create({'symbol' : 'major', 'colour' : 'red'}, '')) self.assert_shield( f.create({'operator' : 'kst', 'colour' : 'red', 'symbol' : 'major'}, ''), 'kct_None_red-major') self.assert_shield( f.create({'kct_red' : 'major'}, ''), 'kct_None_red-major')
def test_jel_symbol(self): f = ShieldFactory(['.jel_symbol'], NullConfig()) self.assertIsNone(f.create({'jel' : 'flo'}, '')) mincfg = ShieldConfig({'jel_types' : ('flo', ), 'jel_path' : '{data}/jel'}, {}) for cfg in (mincfg, WmtConfig): with self.subTest(i=cfg): f = ShieldFactory(['.jel_symbol'], cfg) self.assertIsNone(f.create({}, '')) self.assertIsNone(f.create({'jel' : 'xx233ssdd'}, '')) self.assert_shield( f.create({'jel' : 'flo'}, ''), 'jel_None_flo')
def test_ref_color_symbol(self): for cfg in (ShieldConfig({'colorbox_names' : WmtConfig.colorbox_names}, {}), WmtConfig): with self.subTest(i=cfg): f = ShieldFactory(['.ref_color_symbol'], cfg) self.assertIsNone(f.create({'ref' : 'A'}, '')) self.assertIsNone(f.create({'color' : '#eeeeee'}, '')) self.assertIsNone(f.create({'ref' : 'A', 'color' : 'greenish'}, '')) self.assert_shield(f.create({'ref' : 'A', 'color' : '#eeeeee'}, ''), 'ctb_None_eeeeee_0041') self.assert_shield(f.create({'ref' : 'AAAAAAAA', 'color' : '#101010'}, ''), 'ctb_None_101010_00410041004100410041') self.assert_shield(f.create({'ref' : 'A', 'color' : 'red'}, ''), 'ctb_None_red_0041')
def test_swiss_mobile(self): f = ShieldFactory(['.swiss_mobile'], WmtConfig) self.assertIsNone(f.create({'ref' : '23'}, '')) self.assertIsNone(f.create({'operator' : 'Swiss mobility'}, '')) self.assertIsNone(f.create({'ref' : '0', 'operator' : 'Swiss mobility'}, '')) self.assert_shield( f.create({'operator' : 'Swiss mobility', 'network' : 'nwn', 'ref' : '7'} , ''), 'swiss_None_0037')
def test_cai_hiking_symbol(self): for cfg in (NullConfig(), WmtConfig): with self.subTest(i=cfg): f = ShieldFactory(['.cai_hiking_symbol'], cfg) self.assertIsNone(f.create({}, 'it')) self.assertIsNone(f.create({'osmc:symbol' : 'red:red:white_bar:2:black'}, '')) self.assertIsNone(f.create({'osmc:symbol' : 'red:red:white_cross:2:black'}, 'it')) self.assert_shield( f.create({'osmc:symbol' : 'red:red:white_bar:2:black'}, 'it'), 'cai_None_bar_0032') self.assert_shield( f.create({'osmc:symbol' : 'red:red:white_stripe:2:black'}, 'it'), 'cai_None_stripe_0032')
def test_ref_symbol(self): for cfg in (NullConfig(), WmtConfig): with self.subTest(i=cfg): f = ShieldFactory(['.ref_symbol'], cfg) self.assertIsNone(f.create({}, '')) self.assert_shield(f.create({'ref' : 'A'}, ''), 'ref_None_0041') self.assert_shield(f.create({'ref' : '.'}, '', style='red'), 'ref_red_002e') self.assert_shield(f.create({'ref' : 'AAAAAAAA'}, ''), 'ref_None_00410041004100410041')
def test_factory(self): f = ShieldFactory([RefFactory(), NameFactory()], NullConfig()) self.assertIsNone(f.create({}, '')) s = f.create({'name': 'x'}, '') self.assertIsInstance(s, NameFactory) s = f.create({'ref': 'x'}, '') self.assertIsInstance(s, RefFactory) s = f.create({'name': 'x', 'ref': '5'}, '') self.assertIsInstance(s, RefFactory)
def init_globals(cls, mapname): """ Initialise the global context available for all calls. The context is saved in the form of class variables. `mapname` describes the name of the map to initialise. The wmt_db and wmt_api configurations with the corresponding name are loaded and used. """ cls.mapname = mapname try: cls.db_config = importlib.import_module(f'wmt_db.config.{mapname}') except ModuleNotFoundError: log.error("Cannot find DB config for route map named '%s'.", mapname) raise try: api_config = importlib.import_module('wmt_local_config.api') cls.dem = Path(api_config.DEM_FILE) except ModuleNotFoundError: log.warning( "Cannot find API config. Elevation profiles not available.") cls.dem = None cls.shield_factory = ShieldFactory(cls.db_config.ROUTES.symbols, cls.db_config.SYMBOLS) cls.thread_data = threading.local() try: mapdb_pkg = importlib.import_module( f'wmt_db.maptype.{cls.db_config.MAPTYPE}') except ModuleNotFoundError: log.error("Unknown map type '%s'.", cls.db_config.MAPTYPE) raise class Options: no_engine = True cls.tables = mapdb_pkg.create_mapdb(cls.db_config, Options()) cls.create_engine()
def test_image_symbol(self): for cfg in (NullConfig(), WmtConfig()): with self.subTest(i=cfg): f = ShieldFactory(['.image_symbol'], cfg) self.assertIsNone(f.create({}, '')) setattr(cfg, 'shield_names', {'wheel' : {'tag1' : 'foo', 'tag2' : 'bar'}}) setattr(cfg, 'shield_path', str(base_dir / 'wmt_shields' / 'data' / 'osmc')) f = ShieldFactory(['.image_symbol'], cfg) self.assertIsNone(f.create({'tag1' : 'foo'}, '')) self.assert_shield( f.create({'tag1' : 'foo', 'tag2' : 'bar'}, ''), 'shield_None_wheel')
if __name__ == "__main__": if len(sys.argv) < 2: print("Usage: python symbol.py <outdir>") sys.exit(-1) conf = GlobalConfig() factory = ShieldFactory( ('.slope_symbol', '.nordic_symbol', '.image_symbol', '.cai_hiking_symbol', '.swiss_mobile', '.jel_symbol', '.kct_symbol', '.osmc_symbol', '.ref_color_symbol', '.ref_symbol', filters.tags_all('.color_box', {'operator' : 'Norwich City Council',}), '.color_box' ), conf) # Testing outdir = sys.argv[1] testsymbols = [ ('INT', '', { 'operator':'wheely'}), ('INT', '', { 'ref' : '10' }), ('LOC', '', { 'ref' : '15' }), ('REG', '', { 'ref' : 'WWWW' }),
def test_osmc_symbol(self): f = ShieldFactory(['.osmc_symbol'], NullConfig()) self.assertIsNone(f.create({'osmc:symbol' : 'black::black_stripe'}, '')) mincfg = ShieldConfig({'osmc_colors' : WmtConfig.osmc_colors, 'osmc_path' : '{data}/osmc'}, {}) for cfg in (mincfg, WmtConfig): with self.subTest(i=cfg): f = ShieldFactory(['.osmc_symbol'], cfg) self.assertIsNone(f.create({}, '')) for fg in ('arch', 'backslash', 'bar', 'circle', 'corner', 'cross', 'diamond_line', 'diamond', 'dot', 'fork', 'lower', 'right', 'pointer', 'rectangle_line', 'rectangle', 'red_diamond', 'slash', 'stripe', 'triangle_line', 'triangle', 'triangle_turned', 'turned_T', 'x', 'hexagon', 'shell', 'shell_modern', 'hiker', 'wheel'): self.assert_shield( f.create({'osmc:symbol' : f'black::black_{fg}'}, ''), f'osmc_None_empty_{fg}_black') for bg in ('circle', 'frame', 'round'): self.assert_shield( f.create({'osmc:symbol' : f'black:red_{bg}'}, ''), f'osmc_None_red_{bg}') self.assert_shield( f.create({'osmc:symbol' : 'white:black::45:black'}, ''), 'osmc_None_black_00340035_black') self.assert_shield( f.create({'osmc:symbol' : 'white:black:blue_stripe:orange_stripe_right'} , ''), 'osmc_None_black_stripe_blue_orange') self.assert_shield( f.create({'osmc:symbol' : 'white:black:wheel'}, ''), 'osmc_None_black_wheel_black')
def setup_tables(db, route_class=Routes): if not db.get_option('no_engine'): country = CountryGrid(MetaData(), db.site_config.DB_TABLES.country) if not country.data.exists(db.engine): raise RuntimeError("No country table found.") db.set_metadata('srid', db.site_config.DB_SRID) db.set_metadata('num_threads', db.get_option('numthreads')) tabname = db.site_config.DB_TABLES # first the update table: stores all modified routes, points uptable = db.add_table('updates', UpdatedGeometriesTable(db.metadata, tabname.change)) # First we filter all route relations into an extra table. rfilt = db.add_table( 'relfilter', FilteredTable(db.metadata, tabname.route_filter, db.osmdata.relation, text(f"({db.site_config.DB_ROUTE_SUBSET})"))) # Then we create the connection between ways and relations. # This also adds geometries. relway = db.add_table( 'relway', RelationWayTable(db.metadata, tabname.way_relation, db.osmdata.way, rfilt, osmdata=db.osmdata)) # From that create the segmented table. segments = db.add_table( 'segments', SegmentsTable(db.metadata, tabname.segment, relway, (relway.c.rels, ))) # hierarchy table for super relations rtree = db.add_table( 'hierarchy', RelationHierarchy(db.metadata, tabname.hierarchy, rfilt)) # routes table: information about each route routes = db.add_table( 'routes', route_class( db.metadata, rfilt, relway, rtree, CountryGrid(MetaData(), tabname.country), db.site_config.ROUTES, ShieldFactory(db.site_config.ROUTES.symbols, db.site_config.SYMBOLS))) # finally the style table for rendering db.add_table( 'style', StyleTable(db.metadata, routes, segments, rtree, db.site_config.DEFSTYLE, uptable)) # optional table for guide posts if db.site_config.GUIDEPOSTS is not None: cfg = db.site_config.GUIDEPOSTS filt = db.add_table( 'gp_filter', FilteredTable(db.metadata, cfg.table_name + '_view', db.osmdata.node, text(cfg.node_subset), view_only=True)) db.add_table('guideposts', GuidePosts(db.metadata, filt, cfg))\ .set_update_table(uptable) # optional table for network nodes if db.site_config.NETWORKNODES is not None: cfg = db.site_config.NETWORKNODES filt = db.add_table( 'nnodes_filter', FilteredTable(db.metadata, cfg.table_name + '_view', db.osmdata.node, db.osmdata.node.c.tags.has_key(cfg.node_tag), view_only=True)) db.add_table('networknodes', NetworkNodes(db.metadata, filt, cfg))