start to make it object oriented

This commit is contained in:
admin 2026-01-31 18:38:07 -08:00
parent 6b13480974
commit fe7fccf0ea
4 changed files with 80 additions and 21 deletions

7
.idea/dictionaries/project.xml generated Normal file
View File

@ -0,0 +1,7 @@
<component name="ProjectDictionaryState">
<dictionary name="project">
<words>
<w>linemap</w>
</words>
</dictionary>
</component>

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
''' This is a program to get a url from Google ee api based on supplied region''' ''' This is a program to get a url from Google ee api based on supplied region'''
from timerlog import Timerlog
import logging import logging
import stat import stat
@ -84,27 +85,6 @@ def get_mainland_bbox(country_name, region_name):
return item.bbox return item.bbox
return None 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' 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.line_to(x, y)
#cr.stroke() #cr.stroke()
surface.finish() surface.finish()

24
timerlog.py Normal file
View File

@ -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)

47
topologytool.py Normal file
View File

@ -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))