ArffUtil.cpp 1018 B

1234567891011121314151617181920212223242526272829303132
  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. }