-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStatistics.cpp
More file actions
77 lines (54 loc) · 2.84 KB
/
Statistics.cpp
File metadata and controls
77 lines (54 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
///////////////////////////////////////////////////////////
// Statistics.cpp
// Implementation of the Class Statistics
// Created on: 05-Vas-2014 17:36:46
// Original author: Povilas
///////////////////////////////////////////////////////////
#define _ELPP_THREAD_SAFE
#define _ELPP_STL_LOGGING
#define _ELPP_NO_DEFAULT_LOG_FILE
#include "Statistics.h"
#include "HelperMethods.h"
#include "logging/easylogging++.h"
Statistics::Statistics(InitDamisService* initFile):ServeRequest(initFile){
LOG (INFO) << "Statistical data processing has been called";
}
void Statistics::statPrimitives()
{
LOG (INFO) << "Initiating statistical primiteve calculation";
std::vector<std::string> attrNames;
std::string tmp;
tmp = "min";tmp.append(" NUMERIC"); attrNames.push_back(tmp);
tmp = "max"; tmp.append(" NUMERIC"); attrNames.push_back(tmp);
tmp = "mean"; tmp.append(" NUMERIC"); attrNames.push_back(tmp);
tmp = "std"; tmp.append(" NUMERIC"); attrNames.push_back(tmp);
tmp = "median"; tmp.append(" NUMERIC"); attrNames.push_back(tmp);
std::vector<std::string> dummy;
dummy.reserve(0); //pass dummy vector to write function since no attribute after transform are left
for (int i = 0; i < serveFile->getNumberOfAttributes(); i++)
{
for (int j = 0; j < serveFile->getNumberOfObjects(); j++)
{
ServeRequest::tmpDataVector.push_back(serveFile->getDoubleDataAt(j, i));
}
double min = *std::min_element(ServeRequest::tmpDataVector.begin(), ServeRequest::tmpDataVector.end());
double max = *std::max_element(ServeRequest::tmpDataVector.begin(), ServeRequest::tmpDataVector.end());
double mean = HelperMethods::getMean(ServeRequest::tmpDataVector);
double stdev = HelperMethods::getStd(ServeRequest::tmpDataVector); //daliname is N o ne is N-1
size_t n = ServeRequest::tmpDataVector.size() / 2;
nth_element(ServeRequest::tmpDataVector.begin(), ServeRequest::tmpDataVector.begin()+ n, ServeRequest::tmpDataVector.end());
double median = ServeRequest::tmpDataVector.at(n);
ServeRequest::tmpDataVector.clear();
// Statistics::tmpDataVector = {min, max, mean, stdev, median}; if C11 compiler
ServeRequest::tmpDataVector.push_back(min);
ServeRequest::tmpDataVector.push_back(max);
ServeRequest::tmpDataVector.push_back(mean);
ServeRequest::tmpDataVector.push_back(stdev);
ServeRequest::tmpDataVector.push_back(median);
ServeRequest::writeData.push_back(ServeRequest::tmpDataVector);
ServeRequest::tmpDataVector.clear();
}
this->writeDataToFile(outFile->getFilePath(), prepareDataSection(ServeRequest::writeData, dummy), prepareAttributeSection(attrNames, dummy, dummy));
}
Statistics::~Statistics(){
}