Refactored code to walk multiple runs
This commit is contained in:
122
code/main.cpp
122
code/main.cpp
@@ -50,7 +50,7 @@ std::vector<std::tuple<float, float, float>> getFtmValues(Offline::FileReader& f
|
||||
|
||||
if (wifi.getAP().getMAC() == nuc)
|
||||
{
|
||||
Point3 apPos = Settings::data.CurrentPath.NUCs.find(wifi.getAP().getMAC())->second.position;
|
||||
Point3 apPos = Settings::CurrentPath.NUCs.find(wifi.getAP().getMAC())->second.position;
|
||||
float apDist = gtPos.getDistance(apPos);
|
||||
float ftmDist = wifi.getFtmDist();
|
||||
float rssi = wifi.getRSSI();
|
||||
@@ -155,9 +155,9 @@ void exportFtmValues(Offline::FileReader& fr, Interpolator<uint64_t, Point3>& gt
|
||||
|
||||
auto wifi = fr.getWifiFtm()[e.idx].data;
|
||||
|
||||
int nucid = Settings::data.CurrentPath.NUCs.at(wifi.getAP().getMAC()).ID;
|
||||
float ftm_offset = Settings::data.CurrentPath.NUCs.at(wifi.getAP().getMAC()).ftm_offset;
|
||||
float rssi_pathloss = Settings::data.CurrentPath.NUCs.at(wifi.getAP().getMAC()).rssi_pathloss;
|
||||
int nucid = Settings::CurrentPath.NUCs.at(wifi.getAP().getMAC()).ID;
|
||||
float ftm_offset = Settings::CurrentPath.NUCs.at(wifi.getAP().getMAC()).ftm_offset;
|
||||
float rssi_pathloss = Settings::CurrentPath.NUCs.at(wifi.getAP().getMAC()).rssi_pathloss;
|
||||
|
||||
float rssiDist = LogDistanceModel::rssiToDistance(-40, rssi_pathloss, wifi.getRSSI());
|
||||
float ftmDist = wifi.getFtmDist() + ftm_offset; //in m; plus static offset
|
||||
@@ -165,7 +165,7 @@ void exportFtmValues(Offline::FileReader& fr, Interpolator<uint64_t, Point3>& gt
|
||||
int numMeas = wifi.getNumAttemptedMeasurements();
|
||||
int numSuccessMeas = wifi.getNumSuccessfulMeasurements();
|
||||
|
||||
Point3 apPos = Settings::data.CurrentPath.NUCs.find(wifi.getAP().getMAC())->second.position;
|
||||
Point3 apPos = Settings::CurrentPath.NUCs.find(wifi.getAP().getMAC())->second.position;
|
||||
float apDist = gtPos.getDistance(apPos);
|
||||
|
||||
fs << ts.ms() << ";" << nucid << ";" << apDist << ";" << rssiDist << ";" << ftmDist << ";" << ftmStdDev << ";" << numMeas << ";" << numSuccessMeas << "\n";
|
||||
@@ -214,6 +214,13 @@ static CombinedStats<float> run(Settings::DataSetup setup, int walkIdx, std::str
|
||||
std::ofstream errorFile;
|
||||
errorFile.open (evalDir.string() + "/" + std::to_string(walkIdx) + "_" + std::to_string(t) + ".csv");
|
||||
|
||||
// Output dir
|
||||
auto outputDir = std::filesystem::path(Settings::outputDir);
|
||||
outputDir.append(Settings::CurrentPath.name + "_" + std::to_string(walkIdx));
|
||||
|
||||
if (!std::filesystem::exists(outputDir)) {
|
||||
std::filesystem::create_directories(outputDir);
|
||||
}
|
||||
|
||||
// wifi
|
||||
auto kalmanMap = std::make_shared<std::unordered_map<MACAddress, Kalman>>();
|
||||
@@ -245,10 +252,10 @@ static CombinedStats<float> run(Settings::DataSetup setup, int walkIdx, std::str
|
||||
plot.setGroundTruth(gtPath);
|
||||
plot.setView(30, 0);
|
||||
// APs Positions
|
||||
plot.addCircle(100000 + 0, Settings::data.CurrentPath.nucInfo(0).position.xy(), 0.05);
|
||||
plot.addCircle(100000 + 1, Settings::data.CurrentPath.nucInfo(1).position.xy(), 0.05);
|
||||
plot.addCircle(100000 + 2, Settings::data.CurrentPath.nucInfo(2).position.xy(), 0.05);
|
||||
plot.addCircle(100000 + 3, Settings::data.CurrentPath.nucInfo(3).position.xy(), 0.05);
|
||||
plot.addCircle(100000 + 0, Settings::CurrentPath.nucInfo(0).position.xy(), 0.1);
|
||||
plot.addCircle(100000 + 1, Settings::CurrentPath.nucInfo(1).position.xy(), 0.1);
|
||||
plot.addCircle(100000 + 2, Settings::CurrentPath.nucInfo(2).position.xy(), 0.1);
|
||||
plot.addCircle(100000 + 3, Settings::CurrentPath.nucInfo(3).position.xy(), 0.1);
|
||||
plot.plot();
|
||||
|
||||
// particle-filter
|
||||
@@ -283,8 +290,8 @@ static CombinedStats<float> run(Settings::DataSetup setup, int walkIdx, std::str
|
||||
std::vector<int> timestamps;
|
||||
std::vector<std::array<float, 4>> gtDistances, ftmDistances, rssiDistances; // distance per AP
|
||||
|
||||
Plotta::Plotta errorPlot("errorPlot", Settings::plotDataDir + "errorData.py");
|
||||
Plotta::Plotta distsPlot("distsPlot", Settings::plotDataDir + "distances.py");
|
||||
Plotta::Plotta errorPlot("errorPlot", outputDir.string() + "/errorData.py");
|
||||
Plotta::Plotta distsPlot("distsPlot", outputDir.string() + "/distances.py");
|
||||
|
||||
for (const Offline::Entry& e : fr.getEntries())
|
||||
{
|
||||
@@ -305,10 +312,10 @@ static CombinedStats<float> run(Settings::DataSetup setup, int walkIdx, std::str
|
||||
Point2 gtPos = gtInterpolator.get(static_cast<uint64_t>(ts.ms())).xy();
|
||||
plot.setGroundTruth(Point3(gtPos.x, gtPos.y, 0.1));
|
||||
|
||||
gtDistances.push_back({ gtPos.getDistance(Settings::data.CurrentPath.nucInfo(0).position.xy()),
|
||||
gtPos.getDistance(Settings::data.CurrentPath.nucInfo(1).position.xy()),
|
||||
gtPos.getDistance(Settings::data.CurrentPath.nucInfo(2).position.xy()),
|
||||
gtPos.getDistance(Settings::data.CurrentPath.nucInfo(3).position.xy()) });
|
||||
gtDistances.push_back({ gtPos.getDistance(Settings::CurrentPath.nucInfo(0).position.xy()),
|
||||
gtPos.getDistance(Settings::CurrentPath.nucInfo(1).position.xy()),
|
||||
gtPos.getDistance(Settings::CurrentPath.nucInfo(2).position.xy()),
|
||||
gtPos.getDistance(Settings::CurrentPath.nucInfo(3).position.xy()) });
|
||||
|
||||
Point3 estPos;
|
||||
float distErrorFtm = 0;
|
||||
@@ -339,10 +346,10 @@ static CombinedStats<float> run(Settings::DataSetup setup, int walkIdx, std::str
|
||||
{
|
||||
WiFiMeasurement wifi2 = obs.ftm[i];
|
||||
|
||||
Point3 apPos = Settings::data.CurrentPath.nuc(wifi2.getAP().getMAC()).position;
|
||||
Point3 apPos = Settings::CurrentPath.nuc(wifi2.getAP().getMAC()).position;
|
||||
|
||||
K::GnuplotColor color;
|
||||
switch (Settings::data.CurrentPath.nuc(wifi2.getAP().getMAC()).ID)
|
||||
switch (Settings::CurrentPath.nuc(wifi2.getAP().getMAC()).ID)
|
||||
{
|
||||
case 1: color = K::GnuplotColor::fromRGB(0, 255, 0); break;
|
||||
case 2: color = K::GnuplotColor::fromRGB(0, 0, 255); break;
|
||||
@@ -390,6 +397,18 @@ static CombinedStats<float> run(Settings::DataSetup setup, int walkIdx, std::str
|
||||
|
||||
printErrorStats(errorStats);
|
||||
|
||||
std::ofstream plot_out;
|
||||
plot_out.open(outputDir.string() + "/plot.gp");
|
||||
|
||||
plot.clearDistanceCircles();
|
||||
plot.saveToFile(plot_out);
|
||||
|
||||
std::ofstream errorStats_out;
|
||||
errorStats_out.open(outputDir.string() + "/error_stats.txt");
|
||||
printErrorStats(errorStats_out, errorStats);
|
||||
|
||||
errorPlot.frame();
|
||||
|
||||
//system("pause");
|
||||
|
||||
return errorStats;
|
||||
@@ -417,45 +436,58 @@ int main(int argc, char** argv)
|
||||
CombinedStats<float> tmp;
|
||||
|
||||
std::string evaluationName = "prologic/tmp";
|
||||
|
||||
std::vector<Settings::DataSetup> setupsToRun = { Settings::data.Path7,
|
||||
Settings::data.Path8,
|
||||
Settings::data.Path9 };
|
||||
|
||||
for (size_t walkIdx = 0; walkIdx < 1 /*Settings::data.CurrentPath.training.size()*/; walkIdx++)
|
||||
for (Settings::DataSetup setupToRun : setupsToRun)
|
||||
{
|
||||
std::cout << "Executing walk " << walkIdx << "\n";
|
||||
for (int i = 0; i < 5; ++i)
|
||||
Settings::CurrentPath = setupToRun;
|
||||
|
||||
|
||||
for (size_t walkIdx = 0; walkIdx < 1 /*Settings::CurrentPath.training.size()*/; walkIdx++)
|
||||
{
|
||||
std::cout << "Start of iteration " << i << "\n";
|
||||
std::cout << "Executing walk " << walkIdx << "\n";
|
||||
for (int i = 0; i < 1; ++i)
|
||||
{
|
||||
std::cout << "Start of iteration " << i << "\n";
|
||||
|
||||
tmp = run(Settings::data.CurrentPath, walkIdx, evaluationName);
|
||||
tmp = run(Settings::CurrentPath, walkIdx, evaluationName);
|
||||
|
||||
statsAVG.ftm.add(tmp.ftm.getAvg());
|
||||
statsMedian.ftm.add(tmp.ftm.getMedian());
|
||||
statsSTD.ftm.add(tmp.ftm.getStdDev());
|
||||
statsQuantil.ftm.add(tmp.ftm.getQuantile(0.75));
|
||||
statsAVG.ftm.add(tmp.ftm.getAvg());
|
||||
statsMedian.ftm.add(tmp.ftm.getMedian());
|
||||
statsSTD.ftm.add(tmp.ftm.getStdDev());
|
||||
statsQuantil.ftm.add(tmp.ftm.getQuantile(0.75));
|
||||
|
||||
statsAVG.rssi.add(tmp.rssi.getAvg());
|
||||
statsMedian.rssi.add(tmp.rssi.getMedian());
|
||||
statsSTD.rssi.add(tmp.rssi.getStdDev());
|
||||
statsQuantil.rssi.add(tmp.rssi.getQuantile(0.75));
|
||||
statsAVG.rssi.add(tmp.rssi.getAvg());
|
||||
statsMedian.rssi.add(tmp.rssi.getMedian());
|
||||
statsSTD.rssi.add(tmp.rssi.getStdDev());
|
||||
statsQuantil.rssi.add(tmp.rssi.getQuantile(0.75));
|
||||
|
||||
std::cout << "Iteration " << i << " completed" << std::endl;
|
||||
std::cout << "Iteration " << i << " completed" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Results for path " << Settings::CurrentPath.name << std::endl;
|
||||
std::cout << "==========================================================" << std::endl;
|
||||
std::cout << "Average of all statistical data FTM: " << std::endl;
|
||||
std::cout << "Median: " << statsMedian.ftm.getAvg() << std::endl;
|
||||
std::cout << "Average: " << statsAVG.ftm.getAvg() << std::endl;
|
||||
std::cout << "Standard Deviation: " << statsSTD.ftm.getAvg() << std::endl;
|
||||
std::cout << "75 Quantil: " << statsQuantil.ftm.getAvg() << std::endl;
|
||||
std::cout << "==========================================================" << std::endl;
|
||||
|
||||
std::cout << "==========================================================" << std::endl;
|
||||
std::cout << "Average of all statistical data RSSI: " << std::endl;
|
||||
std::cout << "Median: " << statsMedian.rssi.getAvg() << std::endl;
|
||||
std::cout << "Average: " << statsAVG.rssi.getAvg() << std::endl;
|
||||
std::cout << "Standard Deviation: " << statsSTD.rssi.getAvg() << std::endl;
|
||||
std::cout << "75 Quantil: " << statsQuantil.rssi.getAvg() << std::endl;
|
||||
std::cout << "==========================================================" << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "==========================================================" << std::endl;
|
||||
std::cout << "Average of all statistical data FTM: " << std::endl;
|
||||
std::cout << "Median: " << statsMedian.ftm.getAvg() << std::endl;
|
||||
std::cout << "Average: " << statsAVG.ftm.getAvg() << std::endl;
|
||||
std::cout << "Standard Deviation: " << statsSTD.ftm.getAvg() << std::endl;
|
||||
std::cout << "75 Quantil: " << statsQuantil.ftm.getAvg() << std::endl;
|
||||
std::cout << "==========================================================" << std::endl;
|
||||
|
||||
std::cout << "==========================================================" << std::endl;
|
||||
std::cout << "Average of all statistical data RSSI: " << std::endl;
|
||||
std::cout << "Median: " << statsMedian.rssi.getAvg() << std::endl;
|
||||
std::cout << "Average: " << statsAVG.rssi.getAvg() << std::endl;
|
||||
std::cout << "Standard Deviation: " << statsSTD.rssi.getAvg() << std::endl;
|
||||
std::cout << "75 Quantil: " << statsQuantil.rssi.getAvg() << std::endl;
|
||||
std::cout << "==========================================================" << std::endl;
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user