Skip to content

Commit

Permalink
TEMP deletion existing .json functionality
Browse files Browse the repository at this point in the history
need to check, replace unittests with geofabrik ones, ...
  • Loading branch information
treee111 committed Feb 19, 2023
1 parent 77136ef commit ff4a8ff
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 288 deletions.
133 changes: 0 additions & 133 deletions tests/test_osm_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@

from wahoomc.osm_maps_functions import OsmData
from wahoomc.osm_maps_functions import OsmMaps
from wahoomc.osm_maps_functions import get_tile_by_one_xy_combination_from_jsons
from wahoomc.osm_maps_functions import get_xy_coordinates_from_input
from wahoomc.osm_maps_functions import TileNotFoundError
from wahoomc.input import InputData
from wahoomc import file_directory_functions as fd_fct
from wahoomc import constants_functions as const_fct
from wahoomc import constants


Expand Down Expand Up @@ -151,24 +149,6 @@ class TestStaticJsons(unittest.TestCase):
tests for static .json files
"""

def test_tiles_via_static_json(self):
"""
Test the retrieval of tiles via geofabrik URL against hardcoded data for germany
"""
expected_tiles = [{'x': 138, 'y': 100, 'left': 14.0625, 'top': 36.597889,
'right': 15.46875, 'bottom': 35.46067, 'countries': ['malta']}]
self.calculate_tiles_via_static_json('malta', expected_tiles)

def calculate_tiles_via_static_json(self, country, expected_result):
"""
use static json files in the repo to calculate relevant tiles
"""

json_file_path = const_fct.get_path_to_static_tile_json(country)
tiles = fd_fct.read_json_file(json_file_path)

self.assertEqual(tiles, expected_result)

def test_splitting_of_single_xy_coordinate(self):
"""
use static json files in the repo to calculate relevant tiles
Expand Down Expand Up @@ -239,119 +219,6 @@ def test_encoding_open_sea_osm(self):

self.assertEqual(sea_data_no_encoding, sea_data_utf8)

def test_path_of_tile_via_static_json_china(self):
"""
test function to find .json file for china against static path
"""

country = 'china'
exp_path = os.path.join('asia', country)

self.calculate_path_to_static_tile_json(country, exp_path)

def test_path_of_tile_via_static_json_malta(self):
"""
test function to find .json file for malta against static path
"""

country = 'malta'
exp_path = os.path.join('europe', country)

self.calculate_path_to_static_tile_json(country, exp_path)

def test_path_of_tile_via_static_json_mexico(self):
"""
test function to find .json file for mexico against static path
"""

country = 'mexico'
exp_path = os.path.join('north_america', country)

self.calculate_path_to_static_tile_json(country, exp_path)

def test_path_of_tile_via_static_json_bahamas(self):
"""
test function to find .json file for bahamas against static path
"""

country = 'bahamas'
exp_path = os.path.join('north_america', country)

self.calculate_path_to_static_tile_json(country, exp_path)

def test_path_of_tile_via_static_json_chile(self):
"""
test function to find .json file for chile against static path
"""

country = 'chile'
exp_path = os.path.join('south_america', country)

self.calculate_path_to_static_tile_json(country, exp_path)

def calculate_path_to_static_tile_json(self, country, exp_path):
"""
evaluated the .json file with get_path_to_static_tile_json function
- check against the static file path
- check if the file exists
"""
json_file_path = const_fct.get_path_to_static_tile_json(country)

expected_path = os.path.join(constants.RESOURCES_DIR, 'json',
exp_path + '.json')

self.assertEqual(json_file_path, expected_path)
self.assertTrue(os.path.isfile(json_file_path))

def test_go_through_folders(self):
"""
go through all files in the wahoo_mc/resources/json directory
- check if correct .json will be evaluated through get_path_to_static_tile_json function
"""
for folder in fd_fct.get_folders_in_folder(os.path.join(constants.RESOURCES_DIR, 'json')):
for file in fd_fct.get_files_in_folder(os.path.join(constants.RESOURCES_DIR, 'json', folder)):
country = os.path.splitext(file)[0]

self.calculate_path_to_static_tile_json(
country, os.path.join(folder, country))

def test_go_through_constants(self):
"""
go through the constant for the GUI / country .json to region assignment
- check if correct .json will be evaluated through get_path_to_static_tile_json function
"""
for country in constants.africa:
self.calculate_path_to_static_tile_json(
country, os.path.join("africa", country))

for country in constants.antarctica:
self.calculate_path_to_static_tile_json(
country, os.path.join("antarctica", country))

for country in constants.asia:
self.calculate_path_to_static_tile_json(
country, os.path.join("asia", country))

for country in constants.europe:
self.calculate_path_to_static_tile_json(
country, os.path.join("europe", country))

for country in constants.northamerica:
self.calculate_path_to_static_tile_json(
country, os.path.join('north_america', country))

for country in constants.oceania:
self.calculate_path_to_static_tile_json(
country, os.path.join("oceania", country))

for country in constants.southamerica:
self.calculate_path_to_static_tile_json(
country, os.path.join("south_america", country))

for country in constants.unitedstates:
self.calculate_path_to_static_tile_json(
country, os.path.join("united_states", country))


class TestConfigFile(unittest.TestCase):
"""
Expand Down
65 changes: 0 additions & 65 deletions wahoomc/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,71 +29,6 @@
VERSION = '4.0.0a0'


africa = ['algeria', 'angola', 'benin', 'botswana', 'burkina_faso', 'burundi',
'cameroon', 'canary_islands', 'cape_verde', 'central_african_republic', 'chad', 'comoros',
'cote_d_ivoire', 'democratic_republic_of_the_congo', 'djibouti', 'egypt',
'equatorial_guinea', 'eritrea', 'ethiopia', 'french_southern_territories', 'gabon',
'gambia', 'ghana', 'guinea-bissau', 'guinea', 'kenya', 'lesotho', 'liberia',
'libya', 'madagascar', 'malawi', 'mali', 'mauritania', 'mauritius', 'mayotte',
'morocco', 'mozambique', 'namibia', 'niger', 'nigeria', 'republic_of_congo',
'reunion', 'rwanda', 'saint_helena', 'sao_tome_and_principe', 'senegal',
'seychelles', 'sierra_leone', 'somalia', 'south_africa', 'sudan', 'swaziland',
'tanzania', 'togo', 'tunisia', 'uganda', 'western_sahara', 'zambia', 'zimbabwe']

antarctica = ['antarctica', 'bouvet_island', 'heard_island_and_mcdonald_islands',
'south_georgia_and_the_south_sandwich_islands']

asia = ['afghanistan', 'armenia', 'azerbaijan', 'bahrain', 'bangladesh', 'bhutan',
'british_indian_ocean_territory', 'brunei', 'cambodia', 'china', 'christmas_island',
'cocos_islands', 'cyprus', 'east_timor', 'hong_kong', 'india', 'indonesia',
'iran', 'iraq', 'israel', 'japan', 'jordan', 'kazakhstan', 'kuwait',
'kyrgyzstan', 'laos', 'lebanon', 'macao', 'malaysia', 'maldives', 'mongolia',
'myanmar', 'nepal', 'north_korea', 'oman', 'pakistan', 'palestina',
'paracel_islands', 'philippines', 'qatar', 'saudi_arabia', 'singapore',
'south_korea', 'spratly_islands', 'sri_lanka', 'syria', 'taiwan', 'tajikistan',
'thailand', 'turkey', 'turkmenistan', 'united_arab_emirates', 'uzbekistan',
'vietnam', 'yemen']

europe = ['albania', 'andorra', 'austria', 'belarus', 'belgium', 'bosnia_and_herzegovina',
'bulgaria', 'croatia', 'czech_republic', 'denmark', 'estonia', 'faroe_islands',
'finland', 'france', 'germany', 'gibraltar', 'greece', 'guernsey', 'hungary',
'iceland', 'ireland', 'isle_of_man', 'italy', 'jersey', 'latvia', 'liechtenstein',
'lithuania', 'luxembourg', 'macedonia', 'malta', 'moldova', 'monaco', 'montenegro',
'netherlands', 'norway', 'poland', 'portugal', 'romania', 'russia', 'san_marino',
'serbia', 'slovakia', 'slovenia', 'spain', 'svalbard_and_jan_mayen', 'sweden',
'switzerland', 'ukraine', 'united_kingdom', 'vatican_city', 'åland']

northamerica = ['anguilla', 'antigua_and_barbuda', 'bahamas', 'barbados', 'belize',
'bermuda', 'british_virgin_islands', 'canada', 'cayman_islands', 'costa_rica',
'cuba', 'dominica', 'dominican_republic', 'el_salvador', 'greenland', 'grenada',
'guadeloupe', 'guatemala', 'haiti', 'honduras', 'jamaica', 'martinique',
'mexico', 'montserrat', 'nicaragua', 'panama', 'saint-barthélemy', 'saint-martin',
'saint_kitts_and_nevis', 'saint_lucia', 'saint_vincent_and_the_grenadines',
'sint_maarten', 'turks_and_caicos_islands', 'virgin_islands_u.s.']

oceania = ['australia', 'cook_islands', 'fiji', 'french_polynesia', 'kiribati',
'marshall_islands', 'micronesia', 'nauru', 'new_caledonia', 'new_zealand', 'niue',
'norfolk_island', 'northern_mariana_islands', 'palau', 'papua_new_guinea',
'pitcairn_islands', 'samoa', 'solomon_islands', 'tokelau', 'tonga', 'tuvalu',
'united_states_minor_outlying_islands', 'vanuatu', 'wallis_and_futuna']

southamerica = ['argentina', 'aruba', 'bolivia', 'bonaire_saint_eustatius_and_saba', 'brazil',
'chile', 'clipperton_island', 'colombia', 'curacao', 'ecuador',
'falkland_islands', 'french_guiana', 'guyana', 'paraguay', 'peru',
'saint_pierre_and_miquelon', 'suriname', 'trinidad_and_tobago',
'uruguay', 'venezuela']

unitedstates = ['alabama', 'alaska', 'american_samoa', 'arizona', 'arkansas',
'california', 'colorado', 'commonwealth_of_the_northern_mariana_islands', 'connecticut',
'delaware', 'district_of_columbia', 'florida', 'georgia', 'guam', 'hawaii',
'idaho', 'illinois', 'indiana', 'iowa', 'kansas', 'kentucky', 'louisiana',
'maine', 'maryland', 'massachusetts', 'michigan', 'minnesota', 'mississippi',
'missouri', 'montana', 'nebraska', 'nevada', 'new_hampshire', 'new_jersey',
'new_mexico', 'new_york', 'north_carolina', 'north_dakota', 'ohio', 'oklahoma',
'oregon', 'pennsylvania', 'puerto_rico', 'rhode_island', 'south_carolina',
'south_dakota', 'tennessee', 'texas', 'united_states_virgin_islands', 'utah',
'vermont', 'virginia', 'washington', 'west_virginia', 'wisconsin', 'wyoming']

block_download = ['dach', 'alps', 'britain-and-ireland', 'south-africa-and-lesotho',
'us-midwest', 'us-northeast', 'us-pacific', 'us-south', 'us-west']

Expand Down
34 changes: 0 additions & 34 deletions wahoomc/constants_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import struct

# import custom python packages
from wahoomc import constants
from wahoomc.constants import RESOURCES_DIR
from wahoomc.constants import TOOLING_WIN_DIR
from wahoomc.constants import USER_CONFIG_DIR
Expand All @@ -27,31 +26,6 @@ class TagsToKeepNotFoundError(Exception):
"""Raised when the specified tags to keep .json file does not exist"""


def get_region_of_country(county):
"""
returns the region / continent of a given country
"""
region = ''
if county in constants.africa:
region = 'africa'
if county in constants.antarctica:
region = 'antarctica'
if county in constants.asia:
region = 'asia'
if county in constants.europe:
region = 'europe'
if county in constants.northamerica:
region = 'north_america'
if county in constants.oceania:
region = 'oceania'
if county in constants.southamerica:
region = 'south_america'
if county in constants.unitedstates:
region = 'united_states'

return region


def translate_tags_to_keep(name_tags=False, sys_platform='', use_repo=False):
"""
translates the given tags to format of the operating system.
Expand Down Expand Up @@ -97,14 +71,6 @@ def translate_tags_to_keep(name_tags=False, sys_platform='', use_repo=False):
return tags_modif


def get_path_to_static_tile_json(country):
"""
return the path to the static .json file with the files for the given country
"""
return os.path.join(RESOURCES_DIR, 'json',
get_region_of_country(country), country + '.json')


def transl_tag_value(sys_platform, separator, tag, value):
"""
translates one tag with value(s) to a "common" format
Expand Down
57 changes: 1 addition & 56 deletions wahoomc/osm_maps_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# import custom python packages
from wahoomc.file_directory_functions import read_json_file, \
get_folders_in_folder, get_filenames_of_jsons_in_folder, create_empty_directories, write_json_file_generic
from wahoomc.constants_functions import get_path_to_static_tile_json, translate_tags_to_keep, \
from wahoomc.constants_functions import translate_tags_to_keep, \
get_tooling_win_path, get_tag_wahoo_xml_path, TagWahooXmlNotFoundError

from wahoomc.constants import USER_WAHOO_MC
Expand Down Expand Up @@ -57,29 +57,6 @@ def get_xy_coordinates_from_input(input_xy_coordinates):
return xy_combinations


def get_tile_by_one_xy_combination_from_jsons(xy_combination):
"""
get tile from json files by given X/Y coordinate combination
"""
# go through all files in all folders of the "json" directory
file_path_jsons = os.path.join(RESOURCES_DIR, 'json')

for folder in get_folders_in_folder(file_path_jsons):
for file in get_filenames_of_jsons_in_folder(os.path.join(file_path_jsons, folder)):

# get content of json in folder
content = read_json_file(
os.path.join(file_path_jsons, folder, file + '.json'))

# check tiles values against input x/y combination
for tile in content:
if tile['x'] == xy_combination['x'] and tile['y'] == xy_combination['y']:
return tile

# if function is processed until here, there is no tile found for the x/y combination --> Exception
raise TileNotFoundError


def run_subprocess_and_log_output(cmd, error_message, cwd=""):
"""
run given cmd-subprocess and issue error message if wished
Expand Down Expand Up @@ -204,12 +181,6 @@ def calc_tiles_country(self, o_input_data):
o_geofabrik = Geofabrik(o_input_data.country)
self.tiles = o_geofabrik.get_tiles_of_country()

# option 1b: use static json files in the repo to calculate relevant tiles
else:
json_file_path = get_path_to_static_tile_json(
o_input_data.country)
self.tiles = read_json_file(json_file_path)

def calc_tiles_xy(self, o_input_data):
"""
option 2: input a x/y combinations as parameter, e.g. 134/88 or 133/88,130/100
Expand All @@ -232,20 +203,6 @@ def calc_tiles_xy(self, o_input_data):
except TileNotFoundError:
pass

# option 2b: use static json files in the repo to get relevant tiles
else:
xy_coordinates = get_xy_coordinates_from_input(
o_input_data.xy_coordinates)

# loop through x/y combinations and find each tile in the json files
for xy_comb in xy_coordinates:
try:
self.tiles.append(get_tile_by_one_xy_combination_from_jsons(
xy_comb))

except TileNotFoundError:
pass

def calc_border_countries_country(self, o_input_data):
"""
calculate the border countries for the given tiles when input is a country
Expand Down Expand Up @@ -283,18 +240,6 @@ def log_border_countries(self):
if len(self.border_countries) > 1:
log.info('+ Border countries will be processed')

def find_tiles_for_xy_combinations(self, xy_coordinates):
"""
loop through x/y combinations and find each tile in the json files
"""
for xy_comb in xy_coordinates:
try:
self.tiles.append(get_tile_by_one_xy_combination_from_jsons(
xy_comb))

except TileNotFoundError:
pass

def calc_country_name_xy(self):
"""
country name is the X/Y combinations separated by minus
Expand Down

0 comments on commit ff4a8ff

Please sign in to comment.