From e44d3421ded726f48cce2e400602356cdad448a2 Mon Sep 17 00:00:00 2001 From: frank Date: Sat, 27 Jan 2018 12:07:06 +0100 Subject: [PATCH 1/2] fixed issue within file-reader when reading empty data-parts --- sensors/offline/FileReader.h | 21 ++++++++++++++++----- sensors/offline/Splitter.h | 2 ++ tests/Tests.h | 3 ++- tests/data/fileReader1.txt | 5 +++++ tests/sensors/offline/TestReader.cpp | 18 ++++++++++++++++++ 5 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 tests/data/fileReader1.txt create mode 100644 tests/sensors/offline/TestReader.cpp diff --git a/sensors/offline/FileReader.h b/sensors/offline/FileReader.h index 6bf055e..03f7665 100644 --- a/sensors/offline/FileReader.h +++ b/sensors/offline/FileReader.h @@ -156,16 +156,25 @@ namespace Offline { while(!inp.eof() && !inp.bad()) { + // read the next line from the file + // this ensures that we will not read beyond one line within the next steps + std::string line; + std::getline(inp, line); + + // create a stream for the read line + std::stringstream sline(line); + uint64_t ts; char delim; int idx = -1; std::string data; - inp >> ts; - inp >> delim; - inp >> idx; - inp >> delim; - inp >> data; + // split the line + sline >> ts; + sline >> delim; + sline >> idx; + sline >> delim; + sline >> data; // might be "" if there is no data if (idx == (int)Sensor::WIFI) {parseWiFi(ts, data);} else if (idx == (int)Sensor::BEACON) {parseBeacons(ts, data);} @@ -267,6 +276,8 @@ namespace Offline { WiFiMeasurements wifi; Splitter s(data, sep); + //if (s.empty()) {return;} + // the -1 is due to some old files containing a trailing ";" resulting in one additional stray column for (size_t i = 0; i < s.size()-1; i += 3) { diff --git a/sensors/offline/Splitter.h b/sensors/offline/Splitter.h index ae09d43..d78751f 100644 --- a/sensors/offline/Splitter.h +++ b/sensors/offline/Splitter.h @@ -28,6 +28,8 @@ public: size_t size() const {return split.size();} + bool empty() const {return split.empty();} + private: void build() { diff --git a/tests/Tests.h b/tests/Tests.h index 3639618..d75eaa2 100755 --- a/tests/Tests.h +++ b/tests/Tests.h @@ -7,7 +7,8 @@ static inline std::string getDataFile(const std::string& name) { //return "/mnt/data/workspaces/Indoor/tests/data/" + name; - return "/home/toni/Documents/programme/localization/Indoor/tests/data/" + name; + return "/mnt/vm/paper/diss/code/Indoor/tests/data/" + name; + //return "/home/toni/Documents/programme/localization/Indoor/tests/data/" + name; } diff --git a/tests/data/fileReader1.txt b/tests/data/fileReader1.txt new file mode 100644 index 0000000..247ae85 --- /dev/null +++ b/tests/data/fileReader1.txt @@ -0,0 +1,5 @@ +136731;0;1.6424103;2.4756012;14.106628 +136728;8; +136731;1;0.5573883;2.0301208;9.57785 +136733;3;-0.8585968;-1.057785;-1.1313019 +136831;8;68c63a9f81f1;2422;-55;5ccf7fc40df3;2422;-66 diff --git a/tests/sensors/offline/TestReader.cpp b/tests/sensors/offline/TestReader.cpp new file mode 100644 index 0000000..06a0882 --- /dev/null +++ b/tests/sensors/offline/TestReader.cpp @@ -0,0 +1,18 @@ +#ifdef WITH_TESTS + +#include "../../Tests.h" + +#include "../../../sensors/offline/FileReader.h" + +TEST(FileReader, test1) { + + std::string file = "/tmp/FirstTest.csv";//getDataFile("fileReader1.txt"); + Offline::FileReader reader(file); + + int i = 0; (void) i; + +} + + + +#endif From d8b91cf14456f29403ad6fbf16ef13e9d6401964 Mon Sep 17 00:00:00 2001 From: frank Date: Sat, 27 Jan 2018 12:23:37 +0100 Subject: [PATCH 2/2] added walker sanity checks --- navMesh/walk/NavMeshWalkParams.h | 4 ++++ navMesh/walk/NavMeshWalkRandom.h | 6 ++++++ navMesh/walk/NavMeshWalkSemiDirected.h | 8 ++++++++ navMesh/walk/NavMeshWalkSemiRandom.h | 6 ++++++ navMesh/walk/NavMeshWalkSimple.h | 8 ++++++++ 5 files changed, 32 insertions(+) diff --git a/navMesh/walk/NavMeshWalkParams.h b/navMesh/walk/NavMeshWalkParams.h index b569fbc..4a89d87 100644 --- a/navMesh/walk/NavMeshWalkParams.h +++ b/navMesh/walk/NavMeshWalkParams.h @@ -64,6 +64,10 @@ namespace NM { return _toBeWalkedDistance; } + void check() const { + Assert::isFalse(numSteps == 0, "num Steps = 0 is currently not supported. must be >= 1"); + } + private: // precalc diff --git a/navMesh/walk/NavMeshWalkRandom.h b/navMesh/walk/NavMeshWalkRandom.h index 083db2c..8adff15 100644 --- a/navMesh/walk/NavMeshWalkRandom.h +++ b/navMesh/walk/NavMeshWalkRandom.h @@ -50,6 +50,9 @@ namespace NM { ResultEntry getOne(const NavMeshWalkParams& params) const { + // sanity checks + params.check(); + ResultEntry res; res.probability = 0; @@ -94,6 +97,9 @@ namespace NM { ResultList getMany(const NavMeshWalkParams& params) const { + // sanity checks + params.check(); + ResultList res; // to-be-walked distance; diff --git a/navMesh/walk/NavMeshWalkSemiDirected.h b/navMesh/walk/NavMeshWalkSemiDirected.h index 27c35bd..2eb661e 100644 --- a/navMesh/walk/NavMeshWalkSemiDirected.h +++ b/navMesh/walk/NavMeshWalkSemiDirected.h @@ -50,6 +50,9 @@ namespace NM { ResultEntry getOne(const NavMeshWalkParams& params) { + // sanity checks + params.check(); + ResultEntry re; static Distribution::Uniform dHead(-0.10, +0.10, 1337); @@ -117,7 +120,12 @@ namespace NM { } ResultList getMany(const NavMeshWalkParams& params) { + + // sanity checks + params.check(); + return {getOne(params)}; + } diff --git a/navMesh/walk/NavMeshWalkSemiRandom.h b/navMesh/walk/NavMeshWalkSemiRandom.h index f4b95c6..fff38ec 100644 --- a/navMesh/walk/NavMeshWalkSemiRandom.h +++ b/navMesh/walk/NavMeshWalkSemiRandom.h @@ -53,6 +53,9 @@ namespace NM { ResultEntry getOne(const NavMeshWalkParams& params) const { + // sanity checks + params.check(); + static Distribution::Normal dDist(1.0, 0.4); static Distribution::Normal dHead(0.0, 1.0); @@ -106,6 +109,9 @@ namespace NM { ResultList getMany(const NavMeshWalkParams& params) const { + // sanity checks + params.check(); + static Distribution::Normal dDist(1.0, 0.4); static Distribution::Normal dHead(0.0, 1.0); diff --git a/navMesh/walk/NavMeshWalkSimple.h b/navMesh/walk/NavMeshWalkSimple.h index 4184ba0..7819b41 100644 --- a/navMesh/walk/NavMeshWalkSimple.h +++ b/navMesh/walk/NavMeshWalkSimple.h @@ -52,6 +52,9 @@ namespace NM { ResultEntry getOne(const NavMeshWalkParams& params) { + // sanity checks + params.check(); + ResultEntry re; // to-be-walked distance; @@ -103,7 +106,12 @@ namespace NM { } ResultList getMany(const NavMeshWalkParams& params) { + + // sanity checks + params.check(); + return {getOne(params)}; + }