worked on wifi-scanner for linux
new time-grouping for vap grouper adjusted test-cases minor changes/fixes/improvements
This commit is contained in:
@@ -40,6 +40,20 @@ public:
|
||||
|
||||
};
|
||||
|
||||
/** how to determine the grouped timestamp */
|
||||
enum class TimeAggregation {
|
||||
|
||||
/** use the smallest timestamp among all grouped APs */
|
||||
MINIMUM,
|
||||
|
||||
/** use the average timestamp among all grouped APs */
|
||||
AVERAGE,
|
||||
|
||||
/** use the maximum timestamp among all grouped APs */
|
||||
MAXIMUM,
|
||||
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
static constexpr const char* name = "VAPGrp";
|
||||
@@ -50,14 +64,17 @@ private:
|
||||
/** the signal-strength aggregation algorithm to use */
|
||||
const Aggregation agg;
|
||||
|
||||
/** how to aggreage the grouped time */
|
||||
const TimeAggregation timeAgg;
|
||||
|
||||
/** respect only outputs with at-least X occurences of one physical hardware [can be used to prevent issues] */
|
||||
int minOccurences;
|
||||
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
VAPGrouper(const Mode mode, const Aggregation agg, const int minOccurences = 2) :
|
||||
mode(mode), agg(agg), minOccurences(minOccurences) {
|
||||
VAPGrouper(const Mode mode, const Aggregation agg, const TimeAggregation timeAgg = TimeAggregation::AVERAGE, const int minOccurences = 2) :
|
||||
mode(mode), agg(agg), timeAgg(timeAgg), minOccurences(minOccurences) {
|
||||
;
|
||||
}
|
||||
|
||||
@@ -127,6 +144,15 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
struct FieldRSSI {
|
||||
static float get(const WiFiMeasurement& m) { return m.getRSSI(); }
|
||||
};
|
||||
struct FieldTS {
|
||||
static Timestamp get(const WiFiMeasurement& m) { return m.getTimestamp(); }
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** combine all of the given VAPs into one entry using the configured aggregation method */
|
||||
WiFiMeasurement groupVAPs(const MACAddress& baseMAC, const std::vector<WiFiMeasurement>& vaps) const {
|
||||
|
||||
@@ -134,17 +160,27 @@ private:
|
||||
const AccessPoint baseAP(baseMAC);
|
||||
|
||||
// the resultign timestamp
|
||||
const Timestamp baseTS = vaps.front().getTimestamp();
|
||||
//Timestamp baseTS = vaps.front().getTimestamp();
|
||||
|
||||
// calculate the rssi using the configured aggregate function
|
||||
float rssi = NAN;
|
||||
switch(agg) {
|
||||
case Aggregation::AVERAGE: rssi = getAVG(vaps); break;
|
||||
case Aggregation::MEDIAN: rssi = getMedian(vaps); break;
|
||||
case Aggregation::MAXIMUM: rssi = getMax(vaps); break;
|
||||
default: throw Exception("unsupported vap-aggregation method");
|
||||
case Aggregation::AVERAGE: rssi = getAVG<float, FieldRSSI>(vaps); break;
|
||||
case Aggregation::MEDIAN: rssi = getMedian(vaps); break;
|
||||
case Aggregation::MAXIMUM: rssi = getMax<float, FieldRSSI>(vaps); break;
|
||||
default: throw Exception("unsupported rssi-aggregation method");
|
||||
}
|
||||
|
||||
// calculate the time using the configured aggregate function
|
||||
Timestamp baseTS;
|
||||
switch(timeAgg) {
|
||||
case TimeAggregation::MINIMUM: baseTS = getMin<Timestamp, FieldTS>(vaps); break;
|
||||
case TimeAggregation::AVERAGE: baseTS = getAVG<Timestamp, FieldTS>(vaps); break;
|
||||
case TimeAggregation::MAXIMUM: baseTS = getMax<Timestamp, FieldTS>(vaps); break;
|
||||
default: throw Exception("unsupported time-aggregation method");
|
||||
}
|
||||
|
||||
|
||||
// create the result measurement
|
||||
return WiFiMeasurement(baseAP, rssi, baseTS);
|
||||
|
||||
@@ -153,13 +189,18 @@ private:
|
||||
private:
|
||||
|
||||
/** get the average signal strength */
|
||||
inline float getAVG(const std::vector<WiFiMeasurement>& vaps) const {
|
||||
template <typename T, typename Field> inline T getAVG(const std::vector<WiFiMeasurement>& vaps) const {
|
||||
|
||||
float rssi = 0;
|
||||
// T field = T();
|
||||
// for (const WiFiMeasurement& vap : vaps) {
|
||||
// field = field + Field::get(vap);
|
||||
// }
|
||||
// return field / vaps.size();
|
||||
Stats::Average<T> avg;
|
||||
for (const WiFiMeasurement& vap : vaps) {
|
||||
rssi += vap.getRSSI();
|
||||
avg.add(Field::get(vap));
|
||||
}
|
||||
return rssi / vaps.size();
|
||||
return avg.get();
|
||||
|
||||
}
|
||||
|
||||
@@ -174,19 +215,25 @@ private:
|
||||
|
||||
}
|
||||
|
||||
/** get the maximum signal strength */
|
||||
inline float getMax(const std::vector<WiFiMeasurement>& vaps) const {
|
||||
/** get the maximum value */
|
||||
template <typename T, typename Field> inline T getMax(const std::vector<WiFiMeasurement>& vaps) const {
|
||||
|
||||
Stats::Maximum<float> max;
|
||||
Stats::Maximum<T> max;
|
||||
for (const WiFiMeasurement& vap : vaps) {
|
||||
max.add(vap.getRSSI());
|
||||
max.add(Field::get(vap));
|
||||
}
|
||||
return max.get();
|
||||
// float max = -9999999;
|
||||
// for (const WiFiMeasurement& vap : vaps) {
|
||||
// if (vap.getRSSI() > max) {max = vap.getRSSI();}
|
||||
// }
|
||||
// return max;
|
||||
|
||||
}
|
||||
|
||||
/** get the minimum value */
|
||||
template <typename T, typename Field> inline T getMin(const std::vector<WiFiMeasurement>& vaps) const {
|
||||
|
||||
Stats::Minimum<T> min;
|
||||
for (const WiFiMeasurement& vap : vaps) {
|
||||
min.add(Field::get(vap));
|
||||
}
|
||||
return min.get();
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user