diff --git a/.idea/dictionaries/project.xml b/.idea/dictionaries/project.xml new file mode 100644 index 0000000..73eb773 --- /dev/null +++ b/.idea/dictionaries/project.xml @@ -0,0 +1,7 @@ + + + + linemap + + + \ No newline at end of file diff --git a/get_ee_from_region.py b/get_ee_from_region.py index 9bb454b..d9f1384 100755 --- a/get_ee_from_region.py +++ b/get_ee_from_region.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 ''' This is a program to get a url from Google ee api based on supplied region''' +from timerlog import Timerlog import logging import stat @@ -84,27 +85,6 @@ def get_mainland_bbox(country_name, region_name): return item.bbox return None -class Timerlog: - - def __init__(self, name): - self.time_start = 0.0 - self.time_end = 0.0 - self.name = name - - def start(self): - self.time_start = time.perf_counter() - return self - - def end(self): - self.time_end = time.perf_counter() - return self - - def report(self, duration_only=False): - if duration_only: - return "Timer [{}] duration [{:.5f}]".format( - self.name, self.time_end - self.time_start) - return "Timer [{}] begin [{:.5f}] end [{:.5f}] duration [{:.9f}]".format( - self.name, self.time_start, self.time_end, self.time_end - self.time_start) program_name = 'get_ee_from_region.py' @@ -320,6 +300,7 @@ def create_3d_line_chart_svg(data, output_path, svg_size=(800, 800)): cr.line_to(x, y) #cr.stroke() + surface.finish() diff --git a/timerlog.py b/timerlog.py new file mode 100644 index 0000000..2981a6c --- /dev/null +++ b/timerlog.py @@ -0,0 +1,24 @@ +import time + +class Timerlog: + + def __init__(self, name): + self.time_start = 0.0 + self.time_end = 0.0 + self.name = name + + def start(self): + self.time_start = time.perf_counter() + return self + + def end(self): + self.time_end = time.perf_counter() + return self + + def report(self, duration_only=False): + if duration_only: + return "Timer [{}] duration [{:.5f}]".format( + self.name, self.time_end - self.time_start) + return "Timer [{}] begin [{:.5f}] end [{:.5f}] duration [{:.9f}]".format( + self.name, self.time_start, self.time_end, self.time_end - self.time_start) + diff --git a/topologytool.py b/topologytool.py new file mode 100644 index 0000000..36aaf9c --- /dev/null +++ b/topologytool.py @@ -0,0 +1,47 @@ + +from country_iso2ify import get_resolver +import pycountry +from country_bounding_boxes import country_subunits_by_iso_code + + + +class Topology: + def __init__(self, + country=None, + iso_country=None, + subregion=None, + linemap_size=(800,800), + linemap_rows=30, + linemap_cols=30, + linemap_width=1.0, + linemap_roundcap=True, + linemap_transparent=False + ): + self.country = country + self.iso_country = iso_country + self.subregion = subregion + self.linemap_size = linemap_size + self.linemap_rows = linemap_rows + self.linemap_cols = linemap_cols + self.linemap_width = linemap_width + self.linemap_roundcap = linemap_roundcap + self.linemap_transparent = linemap_transparent + if self.country is None and self.iso_country is None: + self.country = "Switzerland" + if self.country is None: + self.iso_country = pycountry.countries.get(alpha_2=self.iso_country) + return + if self.iso_country is None: + self.iso_country = get_resolver.resolve(self.country) + return + + def list_subunits(self): + countries = country_subunits_by_iso_code(self.iso_country) + print("Country is [{}] iso code is [{}]".format(self.country, self.iso_country)) + item = None + if countries: + for item in countries: + print("Subunit of [{}]: [{}]".format(self.country, item.subunit)) + + +