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>
58 std::vector<std::string> validValues;
59 for (
size_t i=0; i<values.size(); ++i)
61 if (values[i] != nulValue)
62 validValues.push_back(values[i]);
74 std::sort(values.begin(), values.end());
77 ss.
m_maxVal = values[values.size() - 1];
81 for(std::size_t i = 0; i < values.size(); ++i)
83 if(!values[i].empty())
97 std::vector<double> validValues;
98 for (
size_t i=0; i<values.size(); ++i)
100 if (values[i] != nulValue)
101 validValues.push_back(values[i]);
113 std::sort(values.begin(), values.end());
116 ss.
m_maxVal = values[values.size() - 1];
120 for(std::size_t i = 0; i < values.size(); ++i)
122 ss.
m_sum += values[i];
127 for(
int i = 0; i < ss.
m_count; ++i)
155 std::vector<double> mode;
160 std::map<double, int> mapMode;
162 for(std::size_t i = 0; i < values.size(); ++i)
168 std::map<double, int>::iterator itMode = mapMode.begin();
170 while(itMode != mapMode.end())
172 if(itMode->first == values[i])
182 mapMode.insert( std::map<double, int>::value_type( values[i] , 1 ) );
186 mapMode.insert( std::map<double, int>::value_type( values[i] , 1 ) );
189 std::map<double, int>::iterator itMode = mapMode.begin();
192 while(itMode != mapMode.end())
194 if(itMode->second > 1)
196 if(repeat < itMode->second)
198 repeat = itMode->second;
200 mode.push_back(itMode->first);
202 else if(repeat == itMode->second)
204 mode.push_back(itMode->first);
220 std::string mode =
"";
221 std::map<std::string, int> mapMode;
223 for(std::size_t i = 0; i < values.size(); ++i)
229 std::map<std::string, int>::iterator itMode = mapMode.begin();
231 while(itMode != mapMode.end())
233 if(itMode->first == values[i])
243 mapMode.insert( std::map<std::string, int>::value_type( values[i] , 1 ) );
247 mapMode.insert( std::map<std::string, int>::value_type( values[i] , 1 ) );
250 std::map<std::string, int>::iterator itMode = mapMode.begin();
253 while(itMode != mapMode.end())
255 if(repeat < itMode->second)
257 repeat = itMode->second;
258 mode = itMode->first;
269 const std::string& propName,
272 assert(inDatasource);
281 std::auto_ptr<te::da::DataSet> ds = inDatasource->
getDataSet(inDataset);
305 fields->push_back(f_min);
306 fields->push_back(f_max);
307 fields->push_back(f_count);
308 fields->push_back(f_validcount);
312 from->push_back(fromItem);
316 std::auto_ptr<te::da::DataSet> dsQuery = inDatasource->
query(select);
321 dsQuery->moveFirst();
323 ss.
m_minVal = dsQuery->getAsString(1);
324 ss.
m_maxVal = dsQuery->getAsString(2);
325 ss.
m_count = dsQuery->getInt16(3);
334 const std::string& propName,
337 assert(inDatasource);
346 std::auto_ptr<te::da::DataSet> ds = inDatasource->
getDataSet(inDataset);
382 fields->push_back(f_min);
383 fields->push_back(f_max);
384 fields->push_back(f_count);
385 fields->push_back(f_sum);
386 fields->push_back(f_mean);
387 fields->push_back(f_stddev);
388 fields->push_back(f_variance);
389 fields->push_back(f_amplitude);
393 from->push_back(fromItem);
397 std::auto_ptr<te::da::DataSet> dsQuery = inDatasource->
query(select);
402 dsQuery->moveFirst();
404 ss.
m_minVal = boost::lexical_cast<
double>(dsQuery->getAsString(0));
405 ss.
m_maxVal = boost::lexical_cast<
double>(dsQuery->getAsString(1));
406 ss.
m_count = boost::lexical_cast<
int>(dsQuery->getAsString(2));
407 ss.
m_sum = boost::lexical_cast<
double>(dsQuery->getAsString(3));
408 ss.
m_mean = boost::lexical_cast<
double>(dsQuery->getAsString(4));
409 ss.
m_stdDeviation = boost::lexical_cast<
double>(dsQuery->getAsString(5));
410 ss.
m_variance = boost::lexical_cast<
double>(dsQuery->getAsString(6));
411 ss.
m_amplitude = boost::lexical_cast<
double>(dsQuery->getAsString(7));
TESTATEXPORT void GetNumericStatisticalSummary(std::vector< double > &values, te::stat::NumericStatisticalSummary &ss, double nullVal)
const std::string & getName() const
It returns the property name.
TESTATEXPORT void GetNumericStatisticalSummaryQuery(const std::string &inDataset, te::da::DataSource *inDatasource, const std::string &propName, te::stat::NumericStatisticalSummary &ss)
A structure to hold the set of statistics from a set of numerical values.
Utility functions for the data access module.
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...
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)
TESTATEXPORT std::vector< double > Mode(const std::vector< double > &values)
virtual std::auto_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...
A class that models the name of any property of an object.
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...
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Avg statistical function.
Min statistical function.
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.
A set of functions to calculate the statistic summary from a set of values.
TESAEXPORT double Sum(te::sa::GeneralizedProximityMatrix *gpm, int attrIdx)
Function used to calculate sum of a specific attribute from a gpm.
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.
virtual std::auto_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...
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
virtual const DataSourceCapabilities & getCapabilities() const =0
It returns the known capabilities of the data source.
TESTATEXPORT void GetStringStatisticalSummary(std::vector< std::string > &values, te::stat::StringStatisticalSummary &ss)
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.
The subtraction operator.
A structure to hold the set of statistics from a set of categorical (sample) values.
Variance statistical function.
bool supportsPreparedQueryAPI() const
An exception class for the statistical module.
Max statistical function.
Configuration flags for the Terrralib Statistic module.