Added plotta, added probabilistic code
This commit is contained in:
127
code/misc.h
Normal file
127
code/misc.h
Normal file
@@ -0,0 +1,127 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
#include <Indoor/math/stats/Statistics.h>
|
||||
|
||||
|
||||
#include <Indoor/data/Timestamp.h>
|
||||
#include <Indoor/sensors/offline/FileReader.h>
|
||||
#include <Indoor/sensors/radio/model/LogDistanceModel.h>
|
||||
|
||||
#include "Settings.h"
|
||||
|
||||
template<typename T, int Size>
|
||||
std::vector<T> asVector(const std::array<T, Size>& src)
|
||||
{
|
||||
std::vector<T> result;
|
||||
result.assign(src.begin(), src.end());
|
||||
return result;
|
||||
}
|
||||
|
||||
struct WifiMeas {
|
||||
Timestamp ts;
|
||||
std::array<float, 4> ftmDists;
|
||||
std::array<float, 4> rssiDists;
|
||||
|
||||
WifiMeas()
|
||||
: ts(Timestamp::fromMS(0)), ftmDists{ NAN, NAN, NAN, NAN }, rssiDists{ NAN, NAN, NAN, NAN }
|
||||
{ }
|
||||
|
||||
int numSucessMeas() const {
|
||||
int count = 0;
|
||||
|
||||
if (!isnan(ftmDists[0])) count++;
|
||||
if (!isnan(ftmDists[1])) count++;
|
||||
if (!isnan(ftmDists[2])) count++;
|
||||
if (!isnan(ftmDists[3])) count++;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct CombinedStats {
|
||||
Stats::Statistics<T> ftm;
|
||||
Stats::Statistics<T> rssi;
|
||||
};
|
||||
|
||||
|
||||
|
||||
static std::vector<WifiMeas> filterOfflineData(const Offline::FileReader& fr)
|
||||
{
|
||||
std::vector<WifiMeas> result;
|
||||
WifiMeas currentItem;
|
||||
|
||||
// parse each sensor-value within the offline data
|
||||
for (const Offline::Entry& e : fr.getEntries())
|
||||
{
|
||||
if (e.type != Offline::Sensor::WIFI_FTM) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// TIME
|
||||
const Timestamp ts = Timestamp::fromMS(e.ts);
|
||||
|
||||
// init last ts
|
||||
if (currentItem.ts.isZero())
|
||||
{
|
||||
currentItem.ts = ts;
|
||||
}
|
||||
|
||||
// new time step?
|
||||
if ((ts - currentItem.ts) > Timestamp::fromMS(10))
|
||||
{
|
||||
result.push_back(currentItem);
|
||||
currentItem = {};
|
||||
}
|
||||
|
||||
currentItem.ts = ts;
|
||||
|
||||
// DISTANCE
|
||||
auto ftm = fr.getWifiFtm()[e.idx].data;
|
||||
|
||||
const MACAddress& mac = ftm.getAP().getMAC();
|
||||
float ftm_offset = Settings::data.CurrentPath.NUCs.at(mac).ftm_offset;
|
||||
float ftmDist = ftm.getFtmDist() + ftm_offset; // in m; plus static offset
|
||||
|
||||
float rssi_pathloss = Settings::data.CurrentPath.NUCs.at(mac).rssi_pathloss;
|
||||
float rssiDist = LogDistanceModel::rssiToDistance(-40, rssi_pathloss, ftm.getRSSI());
|
||||
|
||||
int nucIndex = Settings::nucIndex(mac);
|
||||
currentItem.ftmDists[nucIndex] = ftmDist;
|
||||
currentItem.rssiDists[nucIndex] = rssiDist;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
struct CmdArguments
|
||||
{
|
||||
std::string executableFilename;
|
||||
std::vector<std::string> arguments;
|
||||
|
||||
CmdArguments()
|
||||
{
|
||||
}
|
||||
|
||||
CmdArguments(int argc, char** argv)
|
||||
{
|
||||
if (argc > 0)
|
||||
{
|
||||
executableFilename = std::string(argv[0]);
|
||||
for (size_t i = 1; i < argc; i++)
|
||||
{
|
||||
arguments.push_back(std::string(argv[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool hasFlag(const std::string& arg) const
|
||||
{
|
||||
return std::find(arguments.begin(), arguments.end(), arg) != arguments.end();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user