147 lines
3.1 KiB
C++
147 lines
3.1 KiB
C++
#include "referencepoint.hh"
|
|
|
|
|
|
|
|
float ReferencePoint::getSsSquareDistance(const vector<Measurement> &m)const
|
|
{
|
|
unsigned int i, j;
|
|
float ret = 0;
|
|
bool found;
|
|
vector<Measurement> ref_m = measurement_list;
|
|
vector<Measurement> test_m = m;
|
|
Measurement new_meas;
|
|
|
|
new_meas.addSsValue(-95);
|
|
|
|
/* Complete measurement vector with unexisting ap (from ref point) */
|
|
for (i = 0 ; i < ref_m.size() ; i++)
|
|
{
|
|
found = false;
|
|
for (j = 0 ; j < test_m.size() && !found ; j++)
|
|
if (test_m[j].getMacAddr() == ref_m[i].getMacAddr())
|
|
found = true;
|
|
if (!found)
|
|
{
|
|
new_meas.setMacAddr(measurement_list[i].getMacAddr());
|
|
test_m.push_back(new_meas);
|
|
}
|
|
}
|
|
|
|
/* Now, complete ref. point meas. */
|
|
for (i = 0 ; i < test_m.size() ; i++)
|
|
{
|
|
found = false;
|
|
for (j = 0 ; j < ref_m.size() && !found ; j++)
|
|
if (test_m[i].getMacAddr() == ref_m[j].getMacAddr())
|
|
found = true;
|
|
if (!found)
|
|
{
|
|
new_meas.setMacAddr(test_m[i].getMacAddr());
|
|
ref_m.push_back(new_meas);
|
|
}
|
|
}
|
|
|
|
/* Now, compute SS distance */
|
|
for (i = 0 ; i < test_m.size() ; i++)
|
|
{
|
|
j = 0;
|
|
found = false;
|
|
while ((j < ref_m.size())&&(found == false))
|
|
{
|
|
if (ref_m[j].getMacAddr() == test_m[i].getMacAddr())
|
|
{
|
|
found = true;
|
|
ret += ref_m[j].getSsSquareDistance(test_m[i].getAverage());
|
|
}
|
|
j++;
|
|
}
|
|
}
|
|
|
|
ref_m.clear();
|
|
test_m.clear();
|
|
|
|
return ret;
|
|
}
|
|
|
|
|
|
|
|
void ReferencePoint::addMeasurement(const string &mac_a, const int &value)
|
|
{
|
|
unsigned int i;
|
|
Measurement m;
|
|
bool inserted = false;
|
|
|
|
for (i = 0 ; i < measurement_list.size() ; i++)
|
|
if (measurement_list[i].getMacAddr() == mac_a)
|
|
{
|
|
measurement_list[i].addSsValue(value);
|
|
inserted = true;
|
|
break;
|
|
}
|
|
if (inserted == false)
|
|
{
|
|
m.setMacAddr(mac_a);
|
|
m.addSsValue(value);
|
|
measurement_list.push_back(m);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool ReferencePoint::getPowerForAp(const string &ap_mac, float *p)const
|
|
{
|
|
unsigned int i;
|
|
string str = ap_mac;
|
|
string macLowerCase;
|
|
|
|
//Pour convertir les majuscules en miniscules
|
|
const int length = str.length();
|
|
for (int j=0; j < length; ++j)
|
|
str[j] = tolower(str[j]);
|
|
|
|
for (i = 0 ; i < measurement_list.size() ; i++)
|
|
if (measurement_list[i].getMacAddr() == str)
|
|
{
|
|
*p = measurement_list[i].getAverage();
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
|
|
ReferencePoint ReferencePoint::operator=(const ReferencePoint &rp)
|
|
{
|
|
if (this == &rp)
|
|
return *this;
|
|
|
|
coordinates = rp.coordinates;
|
|
measurement_list = rp.measurement_list;
|
|
return *this;
|
|
}
|
|
|
|
|
|
|
|
ostream &operator<<(ostream &os, ReferencePoint &rp)
|
|
{
|
|
unsigned int i;
|
|
|
|
os << rp.coordinates << endl;
|
|
if (rp.measurement_list.size() == 0)
|
|
os << "No measurement" << endl;
|
|
else
|
|
for (i = 0 ; i < rp.measurement_list.size() ; i++)
|
|
os << rp.measurement_list[i] << endl;
|
|
|
|
return os;
|
|
}
|
|
|
|
|
|
|
|
/* Opérateur de cast en Point */
|
|
ReferencePoint::operator Point() const
|
|
{
|
|
return coordinates ;
|
|
}
|