1 /* Copyright (C) 2018 Federico Simmross Wattenberg,
2 * Manuel Rodríguez Cayetano,
3 * Javier Royuela del Val,
4 * Elena Martín González,
6 * Marcos Martín Fernández and
7 * Carlos Alberola López
9 * This file is part of OpenCLIPER.
11 * OpenCLIPER is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 3 of the License.
15 * OpenCLIPER is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with OpenCLIPER; If not, see <http://www.gnu.org/licenses/>.
26 * Federico Simmross Wattenberg
27 * E.T.S.I. Telecomunicación
28 * Universidad de Valladolid
30 * 47011 Valladolid, Spain.
36 * Created on: 15 de nov. de 2016
40 #ifndef INCLUDE_OPENCLIPER_SAMPLECOLLECTION_HPP_
41 #define INCLUDE_OPENCLIPER_SAMPLECOLLECTION_HPP_
46 #include <LPISupport/InfoItems.hpp>
48 namespace LPISupport {
50 * @brief Class that stores a group of samples of some measurement and provides methods for calculation of statistics and storing this information (using an InfoItem object)
53 class SampleCollection {
55 /// @brief Class for configuring summary output of stored samples
56 struct OutputConfigTraits {
57 /// samples are shown in summary output if true
58 bool showSamples = true;
59 /// mean samples is shown in summary output if true
61 /// variance of samples is shown in summary output if true
62 bool showVariance = true;
65 SampleCollection(std::string name);
66 SampleCollection(std::string name, std::shared_ptr<OutputConfigTraits> pOutputConfigTraits);
67 virtual ~SampleCollection();
70 * @brief Gets the name associated to this sample collection
71 * @return the name of the collection
73 std::string getSampleName() const {return sampleName;}
75 * @brief Sets the name associated to this sample collection
76 * @param[in] sampleName name for the collection
78 void setSampleName(std::string sampleName) {this->sampleName = sampleName;}
80 * @brief Removes all the samples of the collection and sets flags showing that mean and variance are not valid
82 void clearSamples() {samples.clear(); meanValid = false; varianceValid = false;}
84 * @brief Appends a sample to the collection
85 * @param[in] sample of the sample (double)
87 void appendSample(double sample) {samples.push_back(sample); meanValid = false; varianceValid = false;}
88 void addSamples(SampleCollection newSamples);
90 * @brief Returns number of samples of the collection
91 * @return the number of samples
93 unsigned long getNumOfSamples() const {return samples.size();};
95 * @brief Gets the value of a sample in some position
96 * @param[in] position index of the sample in the vector of samples (beginning at 0)
97 * @return the value of the sample
99 double getSample (unsigned long position) const {return samples.at(position);}
101 double getVariance();
102 std::unique_ptr<InfoItems> to_infoItems(unsigned int numDigitsPrec);
107 /// Flag that shows if stored mean value is valid (otherwise, it must be recalculated)
108 bool meanValid = false;
109 /// Flag that shows if stored variance value is valid (otherwise, it must be recalculated)
110 bool varianceValid = false;
111 /// Vector storing the samples
112 std::vector<double> samples;
113 /// Mean of stored samples
115 /// Variance of stored samples
116 double variance = 0.0;
117 /// Name of sample collection
118 std::string sampleName = "";
119 /// Smart pointer to object for configuring summary output of the sample collection
120 std::shared_ptr<OutputConfigTraits> pOutputConfigTraits;
123 } /* namespace OpenCLIPER */
125 #endif /* INCLUDE_OPENCLIPER_SAMPLECOLLECTION_HPP_ */