diff --git a/owlps-positioner/src/measurement.cc b/owlps-positioner/src/measurement.cc index 1048584..8f882a6 100644 --- a/owlps-positioner/src/measurement.cc +++ b/owlps-positioner/src/measurement.cc @@ -127,6 +127,9 @@ void Measurement::clear() float Measurement::similarity(const Measurement &source) const { + assert(! ss_list.empty()) ; + assert(! source.ss_list.empty()) ; + string algorithm( Configuration::string_value("positioning.ss-similarity")) ; @@ -134,24 +137,27 @@ float Measurement::similarity(const Measurement &source) const return ss_square_distance(source) ; if (algorithm == "interval") - { - float std_dev = get_std_deviation() ; - - // Count the number of SS of source that are within the interval - unsigned int nb_values = 0 ; - for (map::const_iterator ss = - source.ss_list.begin() ; ss != source.ss_list.end() ; ++ss) - if (PosUtil::is_in_interval(average_dbm, std_dev, ss->second)) - ++nb_values ; - - return 1 / nb_values ; - } + return 1 / nb_in_interval(source, get_std_deviation()) ; throw bad_configuration( "Bad SS similarity algorithm name \""+ algorithm +"\"!") ; } +unsigned int Measurement:: +nb_in_interval(const Measurement &source, float bound) const +{ + unsigned int nb_values = 0 ; + + for (map::const_iterator ss = + source.ss_list.begin() ; ss != source.ss_list.end() ; ++ss) + if (PosUtil::is_in_interval(average_dbm, bound, ss->second)) + ++nb_values ; + + return nb_values ; +} + + void Measurement::recalculate_average() { average_dbm = 0 ; diff --git a/owlps-positioner/src/measurement.hh b/owlps-positioner/src/measurement.hh index b6228f2..8f0ceea 100644 --- a/owlps-positioner/src/measurement.hh +++ b/owlps-positioner/src/measurement.hh @@ -44,6 +44,10 @@ protected: void recalculate_average(void) ; /// Update the average and variance with a new SS void update_average(ss_t ss_dbm) ; + /// \brief Counts the number of SS of source that are within the + /// interval [average_dbm-bound;average_dbm+bound] + unsigned int nb_in_interval( + const Measurement &source, float bound) const ; //@}