#ifndef WIFIMEASUREMENTS_H #define WIFIMEASUREMENTS_H #include #include "WiFiMeasurement.h" /** * group of several wifi measurements */ struct WiFiMeasurements { /** all contained measurements */ std::vector entries; /** convert to string */ std::string asString() const { std::string res; for (const WiFiMeasurement& m : entries) { res += m.getAP().getMAC().asString() + ": " + std::to_string(m.getRSSI()) + "\n"; } return res; } /** get the measurements for the given MAC [if available] otherwise null */ const WiFiMeasurement* getForMac(const MACAddress& mac) const { for (const WiFiMeasurement& m : entries) { if (m.getAP().getMAC() == mac) { return &m; } } return nullptr; } /** remove the entry for the given MAC (if any) */ void remove(const MACAddress& mac) { for (size_t i = 0; i < entries.size(); ++i) { if (entries[i].getAP().getMAC() == mac) { entries.erase(entries.begin() + i); break; } } } /** create a combination */ static WiFiMeasurements mix(const WiFiMeasurements& a, const WiFiMeasurements& b, float sec = 3) { Timestamp max; WiFiMeasurements res; for (const WiFiMeasurement& m : a.entries) { res.entries.push_back(m); if (m.getTimestamp() > max) {max = m.getTimestamp();} } for (const WiFiMeasurement& m : b.entries) { res.entries.push_back(m); if (m.getTimestamp() > max) {max = m.getTimestamp();} } std::vector tmp; std::swap(res.entries, tmp); for (const WiFiMeasurement& m : tmp) { if ((max - m.getTimestamp()).sec() < sec) { res.entries.push_back(m); } } return res; } }; #endif // WIFIMEASUREMENTS_H