error_rate_manager.h
Go to the documentation of this file.
1 /* Copyright 2018-2019 TomTom N.V.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7 http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License. */
14 
15 #pragma once
16 
17 #include <unordered_map>
18 
19 namespace detail
20 {
24 template <typename T>
26 {
27  struct ErrorRate
28  {
29  int total_num;
30  int error_num;
31  };
32  std::unordered_map<T, ErrorRate> error_rates;
33 
37  float calculate(T const& id) const
38  {
39  auto it = error_rates.find(id);
40  if (it == error_rates.end())
41  {
42  return 0;
43  }
44 
45  auto const& rate = it->second;
46 
47  if (rate.total_num == 0)
48  {
49  return 0;
50  }
51 
52  return static_cast<float>(rate.error_num) / rate.total_num;
53  }
54 
58  void issueError(T const& id)
59  {
60  auto& rate = error_rates[id];
61  ++rate.total_num;
62  ++rate.error_num;
63  }
64 
68  void issueSuccess(T const& id)
69  {
70  ++error_rates[id].total_num;
71  }
72 };
73 } // namespace detail
std::unordered_map< T, ErrorRate > error_rates
float calculate(T const &id) const
void issueError(T const &id)
void issueSuccess(T const &id)


rviz_satellite
Author(s): Gareth Cross , Andre Schröder
autogenerated on Thu May 4 2023 02:31:43