from __future__ import print_function
from __future__ import division
from past.utils import old_div
import time
import functools
import math
import inspect, os
#from geopy.distance import vincenty
from world_engine.world.mapping.map import PixelPair, Coordinate, Map

from world_engine.engine.server.server_conf.config import settings


def timeit(func):
    @functools.wraps(func)
    def newfunc(*args, **kwargs):
        startTime = time.time()
        func(*args, **kwargs)
        elapsedTime = time.time() - startTime
        print('function [{}] finished in {} ms'.format(
            func.__name__, int(elapsedTime * 1000)))

    return newfunc


# todo: whats the best way to share these named tuples?
coordinate_a = Coordinate(lat=36.974117, lon=-122.030796)
coordinate_b = Coordinate(lat=37.411891, lon=-122.052183)

print(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+r"/bayArea.tif")
_map = Map(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+r"/bayArea.tif")


@timeit
def test_map_instance():
    map = Map(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+r"/bayArea.tif")


# todo: gimped this test for the sake of ci. write better tests.
@timeit
def test_lat_lon_to_pixel():
    print("")
    assert _map.lat_lon_to_pixel(coordinate_a) != (0, 0)


@timeit
def test_pixel_to_lat_lon():
    # print map.pixel_to_lat_lon(PixelPair(0, 0))
    pass


@timeit
def test_distance_on_unit_sphere():
    assert (_map.distance_on_unit_sphere(coordinate_a, coordinate_b, units='km') - 48.622 < .05 * 48.622)

# todo: also gimped this test to remove dependency of external lib for verification. Devise a better test.
@timeit
def test_vinc_dist():
    assert (old_div(_map.vinc_inv(_map.flattening, _map.semimajor, coordinate_a, coordinate_b)["distance"], 1000) != 0)


@timeit
def test_vinc_pt():
    assert (_map.vinc_dir(_map.flattening, _map.semimajor, coordinate_a, math.degrees(6.24423422267), 48621.8048816) ==
            coordinate_b, math.degrees(3.10241592286))


@timeit
def test_map_process():
    # test create instance

    # test starting sub-processes

    pass

from __future__ import print_function
from __future__ import division
from past.utils import old_div
import time
import functools
import math
import inspect, os
#from geopy.distance import vincenty
from world_engine.world.mapping.map import PixelPair, Coordinate, Map

from world_engine.engine.server.server_conf.config import settings


def timeit(func):
    @functools.wraps(func)
    def newfunc(*args, **kwargs):
        startTime = time.time()
        func(*args, **kwargs)
        elapsedTime = time.time() - startTime
        print('function [{}] finished in {} ms'.format(
            func.__name__, int(elapsedTime * 1000)))

    return newfunc


# todo: whats the best way to share these named tuples?
coordinate_a = Coordinate(lat=36.974117, lon=-122.030796)
coordinate_b = Coordinate(lat=37.411891, lon=-122.052183)

#print(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+r"/bayArea.tif")
#_map = Map(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+r"/bayArea.tif")

_map = Map(r"CI_HOME/tests/bayArea.tif")



@timeit
def test_map_instance():
    map = Map(r"CI_HOME/tests/bayArea.tif")


# todo: gimped this test for the sake of ci. write better tests.
@timeit
def test_lat_lon_to_pixel():
    print("")
    assert _map.lat_lon_to_pixel(coordinate_a) != (0, 0)


@timeit
def test_pixel_to_lat_lon():
    # print map.pixel_to_lat_lon(PixelPair(0, 0))
    pass


@timeit
def test_distance_on_unit_sphere():
    assert (_map.distance_on_unit_sphere(coordinate_a, coordinate_b, units='km') - 48.622 < .05 * 48.622)

# todo: also gimped this test to remove dependency of external lib for verification. Devise a better test.
@timeit
def test_vinc_dist():
    assert (old_div(_map.vinc_inv(_map.flattening, _map.semimajor, coordinate_a, coordinate_b)["distance"], 1000) != 0)


@timeit
def test_vinc_pt():
    assert (_map.vinc_dir(_map.flattening, _map.semimajor, coordinate_a, math.degrees(6.24423422267), 48621.8048816) ==
            coordinate_b, math.degrees(3.10241592286))


@timeit
def test_map_process():
    # test create instance

    # test starting sub-processes

    pass

Update to map test to allow for relative path to test file