Skip to content

Instantly share code, notes, and snippets.

@MrCrambo
Created April 29, 2021 11:26
Show Gist options
  • Save MrCrambo/89673d1b6fef4e36112fd64e84a8aefb to your computer and use it in GitHub Desktop.
Save MrCrambo/89673d1b6fef4e36112fd64e84a8aefb to your computer and use it in GitHub Desktop.
std::vector<SensorMeasurement> parseMeasurements(const std::string& logFile)
{
std::vector<SensorMeasurement> measurements;
std::ifstream is(logFile);
if (!is.is_open())
{
std::cout << "could not open file " << logFile << std::endl;
}
std::string line;
std::getline(is, line); // skip test data
while (std::getline(is, line))
{
SensorMeasurement msr;
std::istringstream iss(line);
if ((iss >> msr.ts >> msr.values.x >> msr.values.y >> msr.values.z))
measurements.emplace_back(msr);
else
break;
}
is.close();
return measurements;
}
int main(int argc, char *argv[])
{
if (argc < 2)
{
std::cout << "can not find configuration file in command line argument! " << std::endl;
exit(-1);
}
std::string logFile = std::string(argv[1]);
std::vector<SensorMeasurement> measuremetns = parseMeasurements(logFile);
Pedometer pedometer;
long stepCounter = 0;
for (SensorMeasurement msr: measuremetns)
{
std::vector<SensorMeasurement> singleMsrVector;
singleMsrVector.emplace_back(msr);
pedometer.update(singleMsrVector);
std::deque<Step> steps = pedometer.calculateSteps();
stepCounter += steps.size();
}
std::cout << "Number of steps: " << stepCounter << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment