import csv
import numpy as np

from this_trainer.ch2017_mimo_trainer import Ch2017MimoTrainer 
from mimo_sequence.mimo_sequence import MimoSequence

class MimoCsvAdaptor():
  def __init__(self):
    self.mimo = []
    self.labels = ['~', 'N', 'A', 'O']
    self.label_map = {}
    self.init_label_map()
  
  def init_label_map(self):
    for i in range(len(self.labels)):
      self.label_map[self.labels[i]] = i 
    print(self.label_map)

  def read_file(self, filename, pad_target=False, out_dec_factor=1):
    print('Reading csv file: ' + filename + '.csv')
    ifile  = open(filename + '.csv', "r")
    read = csv.reader(ifile)
    for row in read:
      ECG=np.asarray([ float(i) for i in row ])
    ECG = ECG[:, None]
      #ECG=np.asarray(row)
    self.mimo = MimoSequence(tag='Test', labels=self.labels, out_dec_factor=out_dec_factor)
    self.mimo.append_input(ECG, 'SingleTest')
    
if __name__ == "__main__":
  mc = MimoCsvAdaptor()
  mc.read_file(sys.argv[1])
  #print('Usage: predict_class [filename]')
   
