ArffUtil.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // ArffUtil.cpp
  2. #include "ArffUtil.h"
  3. #include <algorithm>
  4. /*static*/ unsigned long int ArffUtil::FindPosition(const Arff *pArff, const int &attIndex, const double &value)
  5. {
  6. arffData::const_iterator pos = lower_bound(pArff->cbegin(), pArff->cend(), value, [&attIndex](const vector<double>& a, const long double& b) { return a.at(attIndex) < b;});
  7. // if the provided time is higher than all times in the data, pos points to
  8. // the first element after the vector. Thus outside of its range. It is
  9. // changed to last valid point
  10. unsigned int res = pos - pArff->cbegin();
  11. if (pos == pArff->cend())
  12. return res-1;
  13. else
  14. return res;
  15. }
  16. /*static*/ bool ArffUtil::GetTXYCindex(const Arff *pArff, int &timeInd, int &xInd, int &yInd, int &confInd)
  17. {
  18. bool res = true;
  19. res &= pArff->GetAttIndex("time", timeInd);
  20. res &= pArff->GetAttIndex("x", xInd);
  21. res &= pArff->GetAttIndex("y", yInd);
  22. res &= pArff->GetAttIndex("confidence", confInd);
  23. return res;
  24. }
  25. /*static*/ double ArffUtil::GetSamplingPeriod(const Arff *pArff)
  26. {
  27. int timeInd;
  28. pArff->GetAttIndex("time", timeInd);
  29. int rows, columns;
  30. pArff->Size(rows, columns);
  31. double startTime = pArff->cbegin()[0][timeInd];
  32. double endTime = pArff->cend()[-1][timeInd];
  33. double dur = endTime - startTime;
  34. return dur / rows;
  35. }