NASA Astrobee Robot Software  Astrobee Version:
Flight software for the Astrobee robots operating inside the International Space Station.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
averager.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, United States Government, as represented by the
2  * Administrator of the National Aeronautics and Space Administration.
3  *
4  * All rights reserved.
5  *
6  * The Astrobee platform is licensed under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations
16  * under the License.
17  */
18 
19 #ifndef LOCALIZATION_COMMON_AVERAGER_H_
20 #define LOCALIZATION_COMMON_AVERAGER_H_
21 
22 #include <boost/accumulators/accumulators.hpp>
23 #include <boost/accumulators/statistics/count.hpp>
24 #include <boost/accumulators/statistics/max.hpp>
25 #include <boost/accumulators/statistics/mean.hpp>
26 #include <boost/accumulators/statistics/min.hpp>
27 #include <boost/accumulators/statistics/stats.hpp>
28 #include <boost/accumulators/statistics/variance.hpp>
29 
30 #include <fstream>
31 #include <string>
32 
34 class Averager {
35  public:
36  explicit Averager(const std::string& averager_name = "", const std::string& type_name = "",
37  const std::string& units = "", const bool log_on_destruction = false);
38  ~Averager();
39  void Update(const double value);
40  double average() const;
41  int count() const;
42  double last_value() const;
43  void Log() const;
44  void LogToFile(std::ofstream& ofstream) const;
45  void LogToCsv(std::ofstream& ofstream) const;
46  void LogEveryN(const int num_events_per_log) const;
47  void UpdateAndLog(const double value);
48  void UpdateAndLogEveryN(const double value, const int num_events_per_log);
49  void Vlog(const int level = 2) const;
50  void VlogEveryN(const int num_events_per_log, const int level) const;
51 
52  private:
53  std::string StatsString() const;
54  std::string CsvStatsString() const;
55  std::string LastValueString() const;
56 
57  std::string name_;
58  std::string type_name_;
59  std::string units_;
60  std::string spacer_;
61  double last_value_;
62  bool log_on_destruction_;
63  boost::accumulators::accumulator_set<
64  double, boost::accumulators::stats<boost::accumulators::tag::mean(boost::accumulators::immediate),
65  boost::accumulators::tag::variance(boost::accumulators::immediate),
66  boost::accumulators::tag::min, boost::accumulators::tag::max,
67  boost::accumulators::tag::count>>
68  accumulator_;
69 };
70 } // namespace localization_common
71 
72 #endif // LOCALIZATION_COMMON_AVERAGER_H_
localization_common
Definition: averager.h:33
localization_common::Averager::UpdateAndLogEveryN
void UpdateAndLogEveryN(const double value, const int num_events_per_log)
Definition: averager.cc:84
localization_common::Averager::LogToCsv
void LogToCsv(std::ofstream &ofstream) const
Definition: averager.cc:77
localization_common::Averager::~Averager
~Averager()
Definition: averager.cc:30
localization_common::Averager
Definition: averager.h:34
localization_common::Averager::Update
void Update(const double value)
Definition: averager.cc:34
localization_common::Averager::VlogEveryN
void VlogEveryN(const int num_events_per_log, const int level) const
Definition: averager.cc:100
localization_common::Averager::UpdateAndLog
void UpdateAndLog(const double value)
Definition: averager.cc:79
localization_common::Averager::LogEveryN
void LogEveryN(const int num_events_per_log) const
Definition: averager.cc:94
localization_common::Averager::Log
void Log() const
Definition: averager.cc:70
localization_common::Averager::Averager
Averager(const std::string &averager_name="", const std::string &type_name="", const std::string &units="", const bool log_on_destruction=false)
Definition: averager.cc:23
localization_common::Averager::count
int count() const
Definition: averager.cc:41
localization_common::Averager::LogToFile
void LogToFile(std::ofstream &ofstream) const
Definition: averager.cc:75
localization_common::Averager::last_value
double last_value() const
Definition: averager.cc:43
localization_common::Averager::Vlog
void Vlog(const int level=2) const
Definition: averager.cc:89
localization_common::Averager::average
double average() const
Definition: averager.cc:39