
display("training");
source("settings.m");
source("functions.m");


function files = getDataFiles(clsName, numPerClass)
  
  global setDataDir;
  global setTrainRuns;
  
  dir = strcat(setDataDir, clsName, "/");
  lst = readdir(dir);
  files = {};
  cnt = 0;
  for i = 1:numel(lst)
    filename = lst{i};
    if (regexp(filename, ".m$"))         # use only files ending with .m
      file = strcat(dir, filename);
      files = [files file];
      ++cnt;
      if (cnt >= numPerClass)           # use only x input files
        break;
      endif
    endif
  end  
  
end

function samples = getSamplesForClass(clsName, numPerClass, start, percent)
  files = getDataFiles(clsName, numPerClass);
  samples = {};
  for i = 1 : numel(files)
    source(files{i});
    samples = [samples getSamples(Gyro, Accel, Magnet, start, percent)]; # use gyro-sensor readings
  end
  display(strcat("training data for '", clsName, "': ", num2str(length(samples)), " samples"));
end

function data = getTrainData()
  global setTrainRuns;
  numPerClass = setTrainRuns;
  data = {};
  data{1}.samples = getSamplesForClass("forwardbend", numPerClass, 1500, 0.5);
  data{2}.samples = getSamplesForClass("kneebend", numPerClass, 1500, 0.5);
  data{3}.samples = getSamplesForClass("pushups", numPerClass, 1500, 0.5);
  data{4}.samples = getSamplesForClass("situps", numPerClass, 1500, 0.5);
  data{5}.samples = getSamplesForClass("jumpingjack", numPerClass, 1500, 0.5);
end


