from typing import List
from typing import Tuple


def prepare_time_series_data(source_data: List[float], network_input_size: int,
                             data_interval: int) -> Tuple[List[List[float]], List[float]]:
    """Split raw time series data into inputs and targets for neural network

    Example:

    source_data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
    network_input_size = 3
    data_interval = 2

    results:
    inputs = [[0, 1, 2, 3], [3, 4, 5, 6], [6, 7, 8, 9]]
    targets = [[9], [10], [11], [12]]

    For inputs values 0, 3, 6 targeted output will be 9
    For inputs values 1, 4, 7 targeted output will be 10
    etc...

    :param source_data: time series source data
    :param network_input_size: neural network input size
    :param data_interval: interval between data used for prediction
    :return:
    """
    inputs: List[List[float]] = [[] for _ in range(network_input_size)]
    targets: List[float] = []

    last_element_ind = len(source_data) - network_input_size * (data_interval + 1) - 1
    for _ind in range(network_input_size):
        inputs[_ind] = source_data[_ind*(data_interval + 1):last_element_ind+_ind*(data_interval+1) + 1]
    for elmn_ind in range(last_element_ind + 1):
        targets.append(source_data[elmn_ind + network_input_size * (data_interval + 1)])
    return inputs, targets