Академический Документы
Профессиональный Документы
Культура Документы
std::vector<DataBlock> FileReader::GetValues()
{
return m_values;
}
DataBlock FileReader::Tokenize(std::string& input, std::vector<std::string> colu
mns, bool mode)
{
DataBlock block;
std::vector<std::string> data;
//added a bool to make it easier to check multiple types of data file
//without writing more functions
if(mode) data = GetColumnData(input);
else data = GetRSColumnNames(input);
//add columns to the blocks for each column in the data
for(unsigned i = 0; i < columns.size(); i++)
block.AddColumn(columns[i], data[i]);
return block;
}
bool NotDelim(std::string delims, char character)
{
//make sure the character is not a delimiter
for(unsigned i = 0; i < delims.size(); i++)
{
if(delims[i] == character)
return false;
}
return true;
}
std::vector<std::string> BreakItUp(unsigned start_point, std::string delims, con
st std::string& input)
{
std::vector<std::string> return_vec;
std::string push_this_into_vector;
//put all of the characters into a new vector
for(unsigned i = start_point; i < input.size(); i++)
{
//don't put any deliminators in, and no quotation marks
if(NotDelim(delims, input[i]) && input[i] != '\"' && input[i] != '(' && inpu
t[i] != ')')
push_this_into_vector += input[i];
else if(input[i] != '\"' && input[i] != '(' && input[i] != ')') //if you fin
d a delimiter, that is the end of that word
{
return_vec.push_back(push_this_into_vector);
push_this_into_vector.clear();
}
}
//for words that are at the end but do not have delimiters
if(push_this_into_vector.size() > 0)
return_vec.push_back(push_this_into_vector);
return return_vec;
}
std::vector<std::string> FileReader::GetColumnNames(const std::string& input)
{
//because the header in the gyroscope data has some characters i don't want
//i have the "break up" start at index 2 instead of index 0
std::vector<std::string> return_vec;
std::string delims = " ";
return_vec = BreakItUp(2, delims, input);
return return_vec;
}
std::vector<std::string> FileReader::GetColumnData(const std::string& input)
{
std::vector<std::string> return_vec;
std::string delims = ",";
return_vec = BreakItUp(0, delims, input);
return return_vec;
}
std::vector<std::string> FileReader::GetRSColumnNames(const std::string& input)
{
std::vector<std::string> return_vec;
std::string delims = ":";
return_vec = BreakItUp(0, delims, input);
return return_vec;
}
void OutputToFile(std::string filename, Centroid& group)
{
std::ofstream output(filename);
std::vector<std::string> names = group.GetCenter().GetColumnNames();
for (unsigned i = 0; i < names.size(); i++)
{
if (i != names.size() - 1)
output << names[i] << ",";
else
output << names[i] << std::endl;
}
std::vector<DataBlock> blocks = group.GetAllPoints();
for (unsigned i = 0; i < blocks.size(); i++)
{
for (unsigned j = 0; j < blocks[i].GetSize(); j++)
{
if (j != blocks[i].GetSize() - 1)
output << blocks[i][j] << ",";
else
output << blocks[i][j] << std::endl;
}
}
}
void OutputToFile(std::string filename, std::vector<Centroid> centroids, std::ve
ctor<std::string> variables)
{
std::ofstream output(filename);