import time


def get_totalized_value(current_value, current_time, prev_value, prev_time, prev_totalized_value):
    time_diff = ((current_time - prev_time) / 1000) / 60
    if time_diff <= 60:
        totalized_value = (time_diff / 60) * ((prev_value + current_value) / 2)
    else:
        totalized_value = (time_diff / 60) * ((0 + current_value) / 2)

    if totalized_value < 0:
        totalized_value = 0

    # TODO: TIME BASED LOGIC TO SET prev_totalized_value = 0
    start = time.strptime(time.strftime(
        '%Y-%m-%d %H:%M:%S', time.localtime(prev_time / 1000)), '%Y-%m-%d %H:%M:%S')
    end = time.strptime(time.strftime('%Y-%m-%d %H:%M:%S',
                                      time.localtime(current_time / 1000)), '%Y-%m-%d %H:%M:%S')
    start_day = start.tm_mday
    end_day = end.tm_mday
    if start_day != end_day:
        prev_totalized_value = 0
    else:
        pass

    prev_totalized_value += totalized_value
    return prev_totalized_value
