27 #include "../../dataaccess/query_h.h" 28 #include "../../dataaccess/dataset/DataSet.h" 29 #include "../../dataaccess/dataset/DataSetType.h" 30 #include "../../dataaccess/datasource/DataSource.h" 31 #include "../../dataaccess/datasource/DataSourceCapabilities.h" 32 #include "../../dataaccess/datasource/DataSourceTransactor.h" 33 #include "../../dataaccess/utils/Utils.h" 34 #include "../../dataaccess/query_h.h" 35 #include "../../datatype/Property.h" 36 #include "../../maptools/AbstractLayer.h" 37 #include "../../maptools/DataSetLayer.h" 44 #include <boost/lexical_cast.hpp> 59 return (x.real() < y.real()) ||
60 (x.real() == y.real() && x.imag() < y.imag());
70 std::vector<std::string> validValues;
71 for (
size_t i=0; i<values.size(); ++i)
73 if (values[i] != nullValue)
74 validValues.push_back(values[i]);
77 ss.
m_count =
static_cast<int>(values.size());
86 std::sort(values.begin(), values.end());
89 ss.
m_maxVal = values[values.size() - 1];
91 ss.
m_count =
static_cast<int>(values.size());
93 for(std::size_t i = 0; i < values.size(); ++i)
95 if(!values[i].empty())
107 std::vector<double> validValues;
108 for (
size_t i=0; i<values.size(); ++i)
110 if (values[i] != nullValue)
111 validValues.push_back(values[i]);
114 ss.
m_count =
static_cast<int>(values.size());
123 std::sort(values.begin(), values.end());
126 ss.
m_maxVal = values[values.size() - 1];
127 ss.
m_count =
static_cast<int>(values.size());
130 for(std::size_t i = 0; i < values.size(); ++i)
132 ss.
m_sum += values[i];
137 for (
int i = 0; i < ss.
m_count; ++i)
139 double v = values[i];
189 std::map<double, int>::iterator it = values.begin();
190 std::map<double, int>::reverse_iterator it_last = values.rbegin();
197 while(it != values.end())
201 ss.
m_sum += it->first * it->second;
224 double pre_median = 0;
225 int current_count = 0;
226 bool alreadySet =
false;
228 std::vector<double> mode;
229 double occurrence = 0;
231 for (it = values.begin(); it != values.end(); ++it)
234 current_count += it->second;
235 if(current_count >= median_pos && !alreadySet)
238 ss.
m_median = (it->first + pre_median)/2;
244 pre_median = it->first;
249 if(occurrence < it->second)
251 occurrence = it->second;
253 mode.push_back(it->first);
255 else if(occurrence == it->second)
257 mode.push_back(it->first);
265 for (it = values.begin(); it != values.end(); ++it)
267 for(
int i = 0; i < it->second; ++i)
318 ss.
m_maxVal = values[values.size() - 1];
319 ss.
m_count =
static_cast<int>(values.size());
322 for(std::size_t i = 0; i < values.size(); ++i)
324 ss.
m_sum += values[i];
329 for(
int i = 0; i < ss.
m_count; ++i)
331 std::complex<double> v= values[i];
354 std::map<double, int>& values,
double& ,
361 std::map<double, double> percentMap;
363 std::map<double, int>::iterator it = values.begin();
366 while(it != values.end())
372 for(it = values.begin(); it != values.end(); ++it)
374 double percentInter = (double)it->second / (
double)count;
375 percentMap.insert(std::pair<double, double>(it->first, percentInter));
384 std::vector<double> mode;
389 std::map<double, int> mapMode;
391 for(std::size_t i = 0; i < values.size(); ++i)
397 std::map<double, int>::iterator itMode = mapMode.begin();
399 while(itMode != mapMode.end())
401 if(itMode->first == values[i])
411 mapMode.insert( std::map<double, int>::value_type( values[i] , 1 ) );
415 mapMode.insert( std::map<double, int>::value_type( values[i] , 1 ) );
418 std::map<double, int>::iterator itMode = mapMode.begin();
421 while(itMode != mapMode.end())
423 if(itMode->second > 1)
425 if(repeat < itMode->second)
427 repeat = itMode->second;
429 mode.push_back(itMode->first);
431 else if(repeat == itMode->second)
433 mode.push_back(itMode->first);
451 std::map<std::string, int> mapMode;
453 for(std::size_t i = 0; i < values.size(); ++i)
459 std::map<std::string, int>::iterator itMode = mapMode.begin();
461 while(itMode != mapMode.end())
463 if(itMode->first == values[i])
473 mapMode.insert( std::map<std::string, int>::value_type( values[i] , 1 ) );
477 mapMode.insert( std::map<std::string, int>::value_type( values[i] , 1 ) );
480 std::map<std::string, int>::iterator itMode = mapMode.begin();
483 while(itMode != mapMode.end())
485 if(repeat < itMode->second)
487 repeat = itMode->second;
488 mode = itMode->first;
499 const std::string& propName,
502 assert(inDatasource);
511 std::unique_ptr<te::da::DataSet>
ds = inDatasource->
getDataSet(inDataset);
535 fields->push_back(f_min);
536 fields->push_back(f_max);
537 fields->push_back(f_count);
538 fields->push_back(f_validcount);
542 from->push_back(fromItem);
546 std::unique_ptr<te::da::DataSet> dsQuery = inDatasource->
query(select);
551 dsQuery->moveFirst();
553 ss.
m_minVal = dsQuery->getAsString(1);
554 ss.
m_maxVal = dsQuery->getAsString(2);
555 ss.
m_count = dsQuery->getInt16(3);
564 const std::string& propName,
567 assert(inDatasource);
576 std::unique_ptr<te::da::DataSet>
ds = inDatasource->
getDataSet(inDataset);
612 fields->push_back(f_min);
613 fields->push_back(f_max);
614 fields->push_back(f_count);
615 fields->push_back(f_sum);
616 fields->push_back(f_mean);
617 fields->push_back(f_stddev);
618 fields->push_back(f_variance);
619 fields->push_back(f_amplitude);
623 from->push_back(fromItem);
627 std::unique_ptr<te::da::DataSet> dsQuery = inDatasource->
query(select);
632 dsQuery->moveFirst();
634 ss.
m_minVal = boost::lexical_cast<
double>(dsQuery->getAsString(0));
635 ss.
m_maxVal = boost::lexical_cast<
double>(dsQuery->getAsString(1));
636 ss.
m_count = boost::lexical_cast<
int>(dsQuery->getAsString(2));
637 ss.
m_sum = boost::lexical_cast<
double>(dsQuery->getAsString(3));
638 ss.
m_mean = boost::lexical_cast<
double>(dsQuery->getAsString(4));
639 ss.
m_stdDeviation = boost::lexical_cast<
double>(dsQuery->getAsString(5));
640 ss.
m_variance = boost::lexical_cast<
double>(dsQuery->getAsString(6));
641 ss.
m_amplitude = boost::lexical_cast<
double>(dsQuery->getAsString(7));
const std::string & getName() const
It returns the property name.
TESTATEXPORT void GetPercentOfEachClassByArea(std::map< double, int > &values, double &resolutionX, double &resolutionY, double &area, te::stat::NumericStatisticalSummary &ss)
TESTATEXPORT void GetNumericStatisticalSummaryQuery(const std::string &inDataset, te::da::DataSource *inDatasource, const std::string &propName, te::stat::NumericStatisticalSummary &ss)
Configuration flags for the Terrralib Statistic module.
A structure to hold the set of statistics from a set of numerical values.
An abstract class that models a source of data in a query.
The Field class can be used to model an expression that takes part of the output items of a SELECT...
std::complex< double > m_median
A class that models the name of a dataset used in a From clause.
TESTATEXPORT void GetStringStatisticalSummaryQuery(const std::string &inDataset, te::da::DataSource *inDatasource, const std::string &propName, te::stat::StringStatisticalSummary &ss)
A class that models the name of any property of an object.
TEMNTEXPORT te::gm::Point Max(te::gm::Point &p1, te::gm::Point &p2)
std::complex< double > m_stdDeviation
Count statistical function.
std::vector< double > m_mode
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
static te::dt::Date ds(2010, 01, 01)
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Avg statistical function.
std::map< double, double > m_percentEachClass
This is an abstract class that models a query expression.
StdDev statistical function.
TESTATEXPORT std::vector< double > GetNumericData(te::da::DataSet *dataSet, const std::string propName)
Returns the values of a numeric type property in a vector of values.
virtual std::unique_ptr< DataSet > query(const Select &q, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It executes a query that may return some data using a generic query. This method always returns a dis...
std::complex< double > m_sum
A set of functions to calculate the statistic summary from a set of values.
std::complex< double > m_minVal
An exception class for the statistical module.
virtual const DataSourceCapabilities & getCapabilities() const =0
It returns the known capabilities of the data source.
TESAEXPORT double Sum(te::sa::GeneralizedProximityMatrix *gpm, int attrIdx)
Function used to calculate sum of a specific attribute from a gpm.
std::complex< double > m_varCoeff
std::complex< double > m_variance
TESTATEXPORT std::vector< std::string > GetStringData(te::da::DataSet *dataSet, const std::string propName)
Returns the values of a string type property in a vector of values.
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
TESTATEXPORT void GetNumericStatisticalSummary(std::vector< double > &values, te::stat::NumericStatisticalSummary &ss, double nullValue)
Utility functions for the data access module.
A Select models a query to be used when retrieving data from a DataSource.
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
virtual bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
TESTATEXPORT void GetStringStatisticalSummary(std::vector< std::string > &values, te::stat::StringStatisticalSummary &ss, const std::string &nullValue)
The subtraction operator.
virtual std::unique_ptr< DataSet > getDataSet(const std::string &name, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It gets the dataset identified by the given name. This method always returns a disconnected dataset...
A structure to hold the set of statistics from a set of categorical (sample) values.
Variance statistical function.
bool supportsPreparedQueryAPI() const
std::complex< double > m_kurtosis
std::complex< double > m_amplitude
TESTATEXPORT void GetNumericComplexStatisticalSummary(std::vector< std::complex< double > > &values, te::stat::NumericStatisticalComplexSummary &ss)
TEMNTEXPORT te::gm::Point Min(te::gm::Point &p1, te::gm::Point &p2)
std::complex< double > m_skewness
std::complex< double > m_mean
std::complex< double > m_maxVal
TESTATEXPORT void Mode(const std::vector< double > &values, te::stat::NumericStatisticalSummary &ss)
bool DoubleComplexCompare(std::complex< double > x, std::complex< double > y)