Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUpClass(cls):
# preparations which have to be made only once
print("\nSTARTING PACKAGE TESTS\n\n")
cls.print_tf_class_props(cls)
global in_memory_mode
in_memory_mode = cls.in_memory_mode
t = timeit.timeit("TimezoneFinder(in_memory=in_memory_mode)", globals=globals(), number=1)
print('startup time:', time_preprocess(t), '\n')
cls.timezone_finder = TimezoneFinder(bin_file_location=cls.bin_file_dir, in_memory=cls.in_memory_mode)
# create an array of points where timezone_finder finds something (realistic queries)
print('collecting and storing', N, 'realistic points for the tests...')
cls.realistic_points = []
ps_for_10percent = int(N / 10)
percent_done = 0
i = 0
while i < N:
lng, lat = random_point()
# a realistic point is a point where certain_timezone_at() finds something
if cls.timezone_finder.certain_timezone_at(lng=lng, lat=lat):
i += 1
cls.realistic_points.append((lng, lat))
if i % ps_for_10percent == 0:
percent_done += 10
class PackageEqualityTest(unittest.TestCase):
# do the preparations which have to be made only once
if SHAPELY:
print('shapely: ON (tzwhere)')
else:
print('shapely: OFF (tzwhere)')
if TimezoneFinder.using_numba():
print('Numba: ON (timezonefinder)')
else:
print('Numba: OFF (timezonefinder)')
start_time = datetime.now()
timezone_finder = TimezoneFinder()
end_time = datetime.now()
my_time = end_time - start_time
print('Starting tz_where. This could take a moment...')
# integrated start up time test:
# (when doing this for multiple times things are already cached and therefore produce misleading results)
start_time = datetime.now()
tz_where = tzwhere(shapely=SHAPELY)
end_time = datetime.now()
his_time = end_time - start_time
print('\nStartup times:')
print('tzwhere:', his_time)
print('timezonefinder:', my_time)
try:
def list_of_random_points(length):
return [random_point() for i in range(length)]
duration_idle_mem_test = 20
duration_in_use_mem_test = 20
if __name__ == '__main__':
if TimezoneFinder.using_numba():
print('Numba: ON (timezonefinder)')
else:
print('Numba: OFF (timezonefinder)')
start_time = datetime.now()
timezone_finder = TimezoneFinder()
end_time = datetime.now()
my_time = end_time - start_time
print('\nStartup time:')
print('timezonefinder:', my_time)
print("Check the memory usage of python in your process list (Task Manager, Activity Manager...)")
print("time remaining:")
while duration_idle_mem_test > 0:
print(duration_idle_mem_test, 's')
time.sleep(1)
duration_idle_mem_test -= 1
print("package is now in use.")
print("Check the memory usage of python in your process list (Task Manager, Activity Manager)")
seconds_registered = 0
return random.uniform(-180, 180), random.uniform(-84, 84)
def list_of_random_points(length):
return [random_point() for i in range(length)]
class PackageEqualityTest(unittest.TestCase):
# do the preparations which have to be made only once
if SHAPELY:
print('shapely: ON (tzwhere)')
else:
print('shapely: OFF (tzwhere)')
if TimezoneFinder.using_numba():
print('Numba: ON (timezonefinder)')
else:
print('Numba: OFF (timezonefinder)')
start_time = datetime.now()
timezone_finder = TimezoneFinder()
end_time = datetime.now()
my_time = end_time - start_time
print('Starting tz_where. This could take a moment...')
# integrated start up time test:
# (when doing this for multiple times things are already cached and therefore produce misleading results)
start_time = datetime.now()
tz_where = tzwhere(shapely=SHAPELY)
end_time = datetime.now()
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description='parse training parameters')
parser.add_argument('lng', type=float, help='longitude to be queried')
parser.add_argument('lat', type=float, help='latitude to be queried')
parser.add_argument('-v', action='store_true', help='verbosity flag')
parser.add_argument('-f', '--function', type=int, choices=[0, 1], default=0,
help='function to be called. 0: timezone_at(...) 1: certain_timezone_at(...)')
# takes input from sys.argv
parsed_args = parser.parse_args()
tf = TimezoneFinder()
functions = [tf.timezone_at, tf.certain_timezone_at]
tz = functions[parsed_args.function](lng=parsed_args.lng, lat=parsed_args.lat)
if parsed_args.v:
print('Looking for TZ at lat=', parsed_args.lat, ' lng=', parsed_args.lng)
print('Function:', ['timezone_at()', 'certain_timezone_at()'][parsed_args.function])
print('Timezone=', tz)
else:
print(tz)