<commit_before>//__________________________________________________________________________
// Author(s): <NAME>, <NAME> - October 2013
// email:  <EMAIL>
//         <EMAIL>
//
// DO NOT REDISTRIBUTE WITHOUT PERMISSION
//__________________________________________________________________________
//

#include <vector>
using std::vector;
#include <string>
using std::string;
#include <iostream>
using std::cout;
using std::endl;
#include <sstream>
using std::stringstream;
#include <stdlib.h>

#include "EMGDataFromFile.h"

template <typename EMGgenerator>
EMGDataFromFile<EMGgenerator>::EMGDataFromFile(const string& EMGDataFilename, const std::string& emgGeneratorFile)
:EMGDataFile_(EMGDataFilename.c_str()), EMGgenerator_(emgGeneratorFile) {
 
  if (!EMGDataFile_.is_open()) {
    cout << "ERROR emg file: " << EMGDataFilename << " could not be open\n";
    exit(EXIT_FAILURE);
  }
  
  // reading number of columns/rows
  string trash;
  EMGDataFile_ >> trash; 
  int noColumns;
  EMGDataFile_ >> noColumns;
  noMuscles_ = noColumns-1;
  EMGDataFile_ >> trash;
  EMGDataFile_ >> noTimeSteps_;

  // reading muscles
  string line;
  getline(EMGDataFile_, line, '\n'); getline(EMGDataFile_, line, '\n');  
  stringstream myStream(line);
  string nextMuscleName;
  // --- Read Interpolation Data
  string timeName;
  myStream >> timeName;
  // 1. first their names
  do {
    nextMuscleName.clear();
    myStream >> nextMuscleName;
    if (nextMuscleName!="")
        muscleNames_.push_back(nextMuscleName);
  } while (!myStream.eof());

  if (noMuscles_ != muscleNames_.size()) {
    cout << "Something is wrong. " << noMuscles_ << " muscles should be in the file "
         << "and we have : " << muscleNames_.size();
    exit(EXIT_FAILURE);
  } 
  
  if ( !EMGgenerator_.checkInputSignalsNames(muscleNames_) ) {
	  vector<string> musclesNamesFromGenerator;
	  EMGgenerator_.getInputSignalsNames(musclesNamesFromGenerator);
	  std::cout << " generator names - file names\n";
		for(unsigned i = 0; i < musclesNamesFromGenerator.size() && i < muscleNames_.size() ; ++i) {
			string genName(musclesNamesFromGenerator.at(i)), fileName(muscleNames_.at(i)), separator("  -  ");
			if(genName != fileName) separator = "  <>  ";
			std::cout << genName << separator <<  fileName << std::endl;
		}
    cout << "THE EMG generator is not able to generate EMG for your muscles starting from muscle in the file! (muscle names are different)\n";

    exit(EXIT_FAILURE);
  }
  
//TODO fix resize
  currentReadEMG_.resize(EMGgenerator_.getNoInputSignals());
  currentEMGData_.resize(EMGgenerator_.getNoExcitations());
  currentDataTime_ = 0.;
  currentTimeStep_ = 0;
}

template <typename EMGgenerator>
void EMGDataFromFile<EMGgenerator>::readNextEmgData()  {

  // first we build a vector of emg read from the file
 
  string line;
  getline(EMGDataFile_, line, '\n');
  stringstream myStream(line);
  double value;
  currentReadEMG_.clear();
  myStream >>  currentDataTime_;
 // cout << "EMGdatafromfile in emg.txt: time step "<< currentDataTime_ << endl;
  int noReadMuscles=0;
  do {
    myStream >> value;
  //  cout << "EMGdatafromfile in emg.txt: value "<< value << endl;
    currentReadEMG_.push_back(value);
  } while (!myStream.eof() && ++noReadMuscles<noMuscles_);
 // cout << "EMGDataFromFile: just read " << currentReadEMG_.size() << " values\n"; 
  EMGgenerator_.convert(currentReadEMG_, currentEMGData_);
 
/*
  int noFromMuscles = EMGgenerator_.getNoFromMuscles();
  // 1. first their names
  for (int i = 0; i < noFromMuscles; ++i) {
    double value;
    EMGDataFile_ >> value; 
    currentReadEMG_[i] = value;
  } 

  // then we convert them on what they need
  EMGgenerator_.convert(currentReadEMG_, currentEMGData_);
*/
  ++currentTimeStep_;

}

template <typename EMGgenerator>
EMGDataFromFile<EMGgenerator>::~EMGDataFromFile() {
  EMGDataFile_.close();
}


#include "policyTemplates.h"

<commit_msg>Read EMG files in .mot format<commit_after>//__________________________________________________________________________
// Author(s): <NAME>, <NAME> - October 2013
// email:  <EMAIL>
//         <EMAIL>
//
// DO NOT REDISTRIBUTE WITHOUT PERMISSION
//__________________________________________________________________________
//

#include <vector>
using std::vector;
#include <string>
using std::string;
#include <iostream>
using std::cout;
using std::endl;
#include <sstream>
using std::stringstream;
#include <stdlib.h>

#include "EMGDataFromFile.h"

template <typename EMGgenerator>
EMGDataFromFile<EMGgenerator>::EMGDataFromFile(const string& EMGDataFilename, const std::string& emgGeneratorFile)
:EMGDataFile_(EMGDataFilename.c_str()), EMGgenerator_(emgGeneratorFile) {
 
  if (!EMGDataFile_.is_open()) {
    cout << "ERROR emg file: " << EMGDataFilename << " could not be open\n";
    exit(EXIT_FAILURE);
  }

  string line;
  getline(EMGDataFile_, line, '\n');
  while (line!="endheader" && line!= "endheader\r" && !EMGDataFile_.eof())
  {
      if( size_t foundInfo=line.find("nRows=")!=string::npos)
      {
          noTimeSteps_=atoi(line.substr(6).c_str());
      }
      if( size_t foundInfo=line.find("datarows ")!=string::npos)
      {
          noTimeSteps_=atoi(line.substr(9).c_str());
      }
      if( size_t foundInfo=line.find("nColumns=")!=string::npos)
      {
          noMuscles_=atoi(line.substr(9).c_str())-1; //nColumns includes the "time" column
      }
      if( size_t foundInfo=line.find("datacolumns ")!=string::npos)
      {
          noMuscles_=atoi(line.substr(12).c_str())-1; //nColumns includes the "time" column
      }
      getline((EMGDataFile_), line, '\n');
  }
  // reading muscles
  getline((EMGDataFile_), line, '\n');  
  stringstream myStream(line);
  string nextColumnName;
    // the first is the "Time"
  string timeName;
  myStream >> timeName;
    // then we have their names
  int noReadColumns = 0;
  do {
      myStream >> nextColumnName;
      muscleNames_.push_back(nextColumnName);
  } while (!myStream.eof() && ++noReadColumns < noMuscles_);


  if (noMuscles_ != muscleNames_.size()) {
    cout << "Something is wrong. " << noMuscles_ << " muscles should be in the file "
         << "and we have : " << muscleNames_.size();
    exit(EXIT_FAILURE);
  } 
  
  if ( !EMGgenerator_.checkInputSignalsNames(muscleNames_) ) {
	  vector<string> musclesNamesFromGenerator;
	  EMGgenerator_.getInputSignalsNames(musclesNamesFromGenerator);
	  std::cout << " generator names - file names\n";
		for(unsigned i = 0; i < musclesNamesFromGenerator.size() && i < muscleNames_.size() ; ++i) {
			string genName(musclesNamesFromGenerator.at(i)), fileName(muscleNames_.at(i)), separator("  -  ");
			if(genName != fileName) separator = "  <>  ";
			std::cout << genName << separator <<  fileName << std::endl;
		}
    cout << "THE EMG generator is not able to generate EMG for your muscles starting from muscle in the file! (muscle names are different)\n";

    exit(EXIT_FAILURE);
  }
  
//TODO fix resize
  currentReadEMG_.resize(EMGgenerator_.getNoInputSignals());
  currentEMGData_.resize(EMGgenerator_.getNoExcitations());
  currentDataTime_ = 0.;
  currentTimeStep_ = 0;
}

template <typename EMGgenerator>
void EMGDataFromFile<EMGgenerator>::readNextEmgData()  {

  // first we build a vector of emg read from the file
 
  string line;
  getline(EMGDataFile_, line, '\n');
  stringstream myStream(line);
  double value;
  currentReadEMG_.clear();
  myStream >>  currentDataTime_;
 // cout << "EMGdatafromfile in emg.txt: time step "<< currentDataTime_ << endl;
  int noReadMuscles=0;
  do {
    myStream >> value;
  //  cout << "EMGdatafromfile in emg.txt: value "<< value << endl;
    currentReadEMG_.push_back(value);
  } while (!myStream.eof() && ++noReadMuscles<noMuscles_);
 // cout << "EMGDataFromFile: just read " << currentReadEMG_.size() << " values\n"; 
  EMGgenerator_.convert(currentReadEMG_, currentEMGData_);
 
/*
  int noFromMuscles = EMGgenerator_.getNoFromMuscles();
  // 1. first their names
  for (int i = 0; i < noFromMuscles; ++i) {
    double value;
    EMGDataFile_ >> value; 
    currentReadEMG_[i] = value;
  } 

  // then we convert them on what they need
  EMGgenerator_.convert(currentReadEMG_, currentEMGData_);
*/
  ++currentTimeStep_;

}

template <typename EMGgenerator>
EMGDataFromFile<EMGgenerator>::~EMGDataFromFile() {
  EMGDataFile_.close();
}


#include "policyTemplates.h"


{'fraction_non_alphanumeric': 0.13603248536964052, 'fraction_numerical': 0.0035829451809387316, 'mean_word_length': 4.1532307692307695, 'pattern_counts': {'":': 0, '<': 138, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4714402', 'n_tokens_mistral': 2799, 'n_tokens_neox': 2728, 'n_words': 610}