Created
April 29, 2021 11:26
-
-
Save MrCrambo/89673d1b6fef4e36112fd64e84a8aefb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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