- /**
- *
- * This program will quickly read a CSV file into the correct data types.
- * Testied and working in Win10 and OSX.
- * To compile on OSX use: g++ -std=c++0x parseCSV.cpp -lpthread
- */
- //required so will compile in M$FT VS. Must be listed before
- //the inclusion of "csv.h"
- #define _CRT_SECURE_NO_WARNINGS
- //from https://github.com/ben-strasser/fast-cpp-csv-parser
- #include "csv.h"
- #include <iostream>
- #include <string>
- #include <cmath>
- using namespace std;
- int CountSteps(int MovingAvg[], int start, int end) //Function for countingsteps
- {
- int steps = 0;
- int Mid = (start + end) / 2;
- //cout << "\n" << Mid;
- if ((MovingAvg[Mid] >= MovingAvg[Mid + 1]) && (MovingAvg[Mid] >= MovingAvg[Mid - 1]))
- {
- steps++;
- //cout << "Step @: " << Mid << "\n" << endl;
- } else if (MovingAvg[Mid] < MovingAvg[Mid - 1])
- {
- CountSteps(MovingAvg, start, Mid-1);
- }
- else if (MovingAvg[Mid] < MovingAvg[Mid + 1])
- {
- CountSteps(MovingAvg, Mid+1, end);
- }
- return steps;
- }
- int main()
- {
- //create a string with the full/absolute file path for the data to be read.
- string fileName = "70Steps.csv";
- //create the reader object to parse a file with 3 columns
- io::CSVReader<3> in(fileName);
- //tell the class what are the names of the three columns
- in.read_header(io::ignore_extra_column, "x", "y", "z");
- //create variables to hold the data points for each row
- int x; int y; int z;
- //read through the file and do whatever you like with the data
- bool available = true;
- const int len = 10;
- int Vector[len+1];
- int Diff[len];
- int Square[len];
- int MovingAvg[len];
- int index = 0;
- int counter = 0;
- int totalsteps = 0;
- int time = 0;
- while (available)
- {
- int sum = 0;
- available = in.read_row(x, y, z);
- Vector[index % (len+1)] = sqrt(pow(x, 2) + pow(y, 2) + pow(z, 2));//get the vector of each point and store in the vector array
- Diff[index % len] = Vector[index % (len+1)] - Vector[(index-1) % (len+1)]; //Get difference of i+1 to i
- Square[index % len] = Diff[index % len] * Diff[index % len]; //Get square value of each Diff number
- for (int i = 0; i < len; i++)
- {
- sum += Square[i];
- }
- MovingAvg[index % len] = sum/len;
- //cout << index << ": MovAvg: " << MovingAvg[index & len] << endl;
- //cout << "\n";
- if (index == 7) //waits til 5 data points are filled in array
- {
- if (time == 1) {
- counter = CountSteps(MovingAvg, 0, 20); // Call the function CountSteps
- totalsteps += counter; //addes counter to total steps
- index = 0;
- time = 0;
- }
- else {
- time++;
- index = 0;
- }
- }
- index++;
- }
- cout << "\nStep = " << totalsteps;
- return 0;
- }
[text] step
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new:
File Description
- step
- Paste Code
- 02 Dec-2022
- 2.63 Kb
You can Share it:
Latest Code Pastes