def encode_timeseries_window(source, lag_size, lead_size, input_fields, predict_fields):
    """
    Encode raw data to a time-series window.
    :param source: A 2D array that specifies the source to be encoded.
    :param lag_size: The number of rows uses to predict.
    :param lead_size: The number of rows to be predicted
    :param input_fields: Boolean array that specifies which columns to use for prediction.
    :param predict_fields: Boolean array that specifies which columns to predict.
    :return: A tuple that contains the x (input) & y (expected output) for training.
    """
    result_x = []
    result_y = []

    output_row_count = len(source) - (lag_size + lead_size) + 1

    for raw_index in range(output_row_count):
        encoded_x = []

        for i, use_field in enumerate(input_fields):
            if use_field:
                for j in range(lag_size):
                    encoded_x.append(source[raw_index+j][i])

        result_x.append(encoded_x)

        # Encode y (prediction)
        encoded_y = []

        for i, use_field in enumerate(predict_fields):
            if use_field:
                for j in range(lead_size):
                    encoded_y.append(source[lag_size+raw_index+j][i])

        result_y.append(encoded_y)


    return result_x, result_y