src
detail
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>
25
struct
ErrorRateManager
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
detail::ErrorRateManager::ErrorRate::error_num
int error_num
Definition:
error_rate_manager.h:30
detail
Definition:
error_rate_manager.h:19
detail::ErrorRateManager
Definition:
error_rate_manager.h:25
detail::ErrorRateManager::error_rates
std::unordered_map< T, ErrorRate > error_rates
Definition:
error_rate_manager.h:32
detail::ErrorRateManager::issueError
void issueError(T const &id)
Definition:
error_rate_manager.h:58
detail::ErrorRateManager::ErrorRate::total_num
int total_num
Definition:
error_rate_manager.h:29
detail::ErrorRateManager::calculate
float calculate(T const &id) const
Definition:
error_rate_manager.h:37
detail::ErrorRateManager::ErrorRate
Definition:
error_rate_manager.h:27
detail::ErrorRateManager::issueSuccess
void issueSuccess(T const &id)
Definition:
error_rate_manager.h:68
rviz_satellite
Author(s): Gareth Cross
, Andre Schröder
autogenerated on Thu May 4 2023 02:47:22