import tensorflow as tf

TIMESERIES_INPUT_LAYER = 'rawdata'
TIMESERIES_COL = '{}_input'.format(TIMESERIES_INPUT_LAYER)
# In each sequence, column index 0 to N_INPUTS - 1 are features, and column index N_INPUTS to SEQ_LEN are labels
N_OUTPUTS = 1
N_INPUTS = SEQ_LEN - N_OUTPUTS
LSTM_SIZE = 3  # number of hidden layers in each of the LSTM cells

# Read data and convert to needed format
def read_dataset(filename, mode, batch_size):
    def _input_fn():
        # Provide the ability to decode a CSV
        def decode_csv(line):
            # all_data is a list of scalar tensors
            all_data = tf.decode_csv(line, record_defaults = DEFAULTS)
            inputs = all_data[:len(all_data) - N_OUTPUTS]  # first N_INPUTS values
            labels = all_data[len(all_data) - N_OUTPUTS:] # last N_OUTPUTS values

            # Convert each list of rank R tensors to one rank R+1 tensor
            inputs = tf.stack(inputs, axis = 0)
            labels = tf.stack(labels, axis = 0)

            # Convert input R+1 tensor into a feature dictionary of one R+1 tensor
            features = {TIMESERIES_COL: inputs}

            return features, labels

