# Path: D3HRE/core/get_hash.py
# def hash_value(data):
#     """
#     Get hash of python object
# 
#     :param data: object or data
#     :return: the hash value for the data (full length)
#     """
#     hashId = hashlib.md5()
#     hashId.update(repr(data).encode('utf-8'))
#     return hashId.hexdigest()
# 
# Path: D3HRE/core/dataframe_utility.py
# def full_day_cut(df):
#     '''
#     Crop dataFrame at the end of the day
# 
#     :param df: pandas data frame
#     :return: pandas data frame that end at full day
#     '''
#     df = df[0 : int(floor(len(df) / 24)) * 24]
#     return df


import numpy as np
import pandas as pd
import nvector as nv
from math import radians, cos, sin, asin, sqrt
from datetime import timedelta
from D3HRE.core.get_hash import hash_value
from D3HRE.core.dataframe_utility import full_day_cut
    # Convert UTC time into local time
    def find_timezone(array, value):
        idx = (np.abs(array - value)).argmin()
        return idx - 12

    lons = np.linspace(-180, 180, 25)

    local_time = []
    for index, row in mission.iterrows():
        local_time.append(index + timedelta(hours=int(find_timezone(lons, row.lon))))
    # time difference into timedelta
    # t_diff = list(map(lambda x: timedelta(hours=x), time_diff))
    # local_time = mission.index + t_diff
    mission['local_time'] = local_time

    return mission


def get_mission(start_time, route, speed):
    """
    Calculate position dataFrame at given start time, route and speed

    :param start_time: str or Pandas Timestamp, the str input should have format YYYY-MM-DD close the day
    :param route: numpy array shape (n,2)  list of way points formatted as [lat, lon]
    :param speed: int, float or (n) list, speed of platform unit in km/h
    :return: Pandas dataFrame
    """
    if type(start_time) == str:
        start_time = pd.Timestamp(start_time)


# Path: D3HRE/core/get_hash.py
# def hash_value(data):
#     """
#     Get hash of python object
# 
#     :param data: object or data
#     :return: the hash value for the data (full length)
#     """
#     hashId = hashlib.md5()
#     hashId.update(repr(data).encode('utf-8'))
#     return hashId.hexdigest()
# 
# Path: D3HRE/core/dataframe_utility.py
# def full_day_cut(df):
#     '''
#     Crop dataFrame at the end of the day
# 
#     :param df: pandas data frame
#     :return: pandas data frame that end at full day
#     '''
#     df = df[0 : int(floor(len(df) / 24)) * 24]
#     return df


# Path: D3HRE/core/mission_utility.py
import numpy as np
import pandas as pd
import nvector as nv
from math import radians, cos, sin, asin, sqrt
from datetime import timedelta
from D3HRE.core.get_hash import hash_value
from D3HRE.core.dataframe_utility import full_day_cut

    # Convert UTC time into local time
    def find_timezone(array, value):
        idx = (np.abs(array - value)).argmin()
        return idx - 12

    lons = np.linspace(-180, 180, 25)

    local_time = []
    for index, row in mission.iterrows():
        local_time.append(index + timedelta(hours=int(find_timezone(lons, row.lon))))
    # time difference into timedelta
    # t_diff = list(map(lambda x: timedelta(hours=x), time_diff))
    # local_time = mission.index + t_diff
    mission['local_time'] = local_time

    return mission


def get_mission(start_time, route, speed):
    """
    Calculate position dataFrame at given start time, route and speed

    :param start_time: str or Pandas Timestamp, the str input should have format YYYY-MM-DD close the day
    :param route: numpy array shape (n,2)  list of way points formatted as [lat, lon]
    :param speed: int, float or (n) list, speed of platform unit in km/h
    :return: Pandas dataFrame
    """
    if type(start_time) == str:
        start_time = pd.Timestamp(start_time)


    position_df = full_day_cut(position_dataframe(start_time, route, speed))