Skip to content

Commit 5117138

Browse files
author
sandeepmittal
committed
copod unit tests
1 parent 2cff21c commit 5117138

5 files changed

Lines changed: 544 additions & 34 deletions

File tree

include/chimbuko/param/copod_param.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace chimbuko {
1212

13-
13+
1414
/**
1515
* @@brief Implementation of ParamInterface for COPOD based anomaly detection
1616
*/
@@ -60,16 +60,16 @@ namespace chimbuko {
6060

6161
/**
6262
* @brief Set the internal Histogram to match those included in the input map. Overwrite performed only for those keys in input.
63-
* @param hbosstats The input map between global function index and Histogram
63+
* @param copodstats The input map between global function index and Histogram
6464
*/
65-
void assign(const std::unordered_map<unsigned long, Histogram>& hbosstats);
65+
void assign(const std::unordered_map<unsigned long, Histogram>& copodstats);
6666

6767
/**
6868
* @brief Convert a Histogram mapping into a Cereal portable binary representration
69-
* @param hbosstats The Histogram mapping
69+
* @param copodstats The Histogram mapping
7070
* @return Histogram in string format
7171
*/
72-
static std::string serialize_cerealpb(const std::unordered_map<unsigned long, Histogram>& hbosstats);
72+
static std::string serialize_cerealpb(const std::unordered_map<unsigned long, Histogram>& copodstats);
7373

7474
/**
7575
* @brief Get an element of the internal map
@@ -80,17 +80,17 @@ namespace chimbuko {
8080
/**
8181
* @brief Convert a Histogram Cereal portable binary representation string into a map
8282
* @param[in] parameters The parameter string
83-
* @param[out] hbosstats The map between global function index and histogram statistics
83+
* @param[out] copodstats The map between global function index and histogram statistics
8484
*/
8585
static void deserialize_cerealpb(const std::string& parameters,
86-
std::unordered_map<unsigned long, Histogram>& hbosstats);
86+
std::unordered_map<unsigned long, Histogram>& copodstats);
8787

8888

8989
/**
9090
* @brief Update the internal histogram with those included in the input map
91-
* @param[in] hbosstats The map between global function index and histogram
91+
* @param[in] copodstats The map between global function index and histogram
9292
*/
93-
void update(const std::unordered_map<unsigned long, Histogram>& hbosstats);
93+
void update(const std::unordered_map<unsigned long, Histogram>& copodstats);
9494

9595
/**
9696
* @brief Update the internal Histogram with those included in another CopodParam instance.
@@ -100,9 +100,9 @@ namespace chimbuko {
100100

101101
/**
102102
* @brief Update the internal histogram with those included in the input map. Input map is then updated to reflect new state.
103-
* @param[in,out] hbosstats The map between global function index and statistics
103+
* @param[in,out] copodstats The map between global function index and statistics
104104
*/
105-
void update_and_return(std::unordered_map<unsigned long, Histogram>& hbosstats);
105+
void update_and_return(std::unordered_map<unsigned long, Histogram>& copodstats);
106106

107107
/**
108108
* @brief Update the internal histogram with those included in another CopodParam instance. Other CopodParam is then updated to reflect new state.

src/param/copod_param.cpp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ using namespace chimbuko;
4444
os << std::endl;
4545
}
4646

47-
void CopodParam::assign(const std::unordered_map<unsigned long, Histogram>& hbosstats)
47+
void CopodParam::assign(const std::unordered_map<unsigned long, Histogram>& copodstats)
4848
{
4949
std::lock_guard<std::mutex> _(m_mutex);
50-
for (auto& pair: hbosstats) {
50+
for (auto& pair: copodstats) {
5151
m_copodstats[pair.first] = pair.second;
5252
}
5353
}
5454

5555
void CopodParam::assign(const std::string& parameters)
5656
{
57-
std::unordered_map<unsigned long, Histogram> hbosstats;
57+
std::unordered_map<unsigned long, Histogram> copodstats;
5858

59-
deserialize_cerealpb(parameters, hbosstats);
60-
assign(hbosstats);
59+
deserialize_cerealpb(parameters, copodstats);
60+
assign(copodstats);
6161
}
6262

6363
std::string CopodParam::serialize() const
@@ -67,10 +67,10 @@ using namespace chimbuko;
6767
return serialize_cerealpb(m_copodstats);
6868
}
6969

70-
std::string CopodParam::serialize_cerealpb(const std::unordered_map<unsigned long, Histogram>& hbosstats)
70+
std::string CopodParam::serialize_cerealpb(const std::unordered_map<unsigned long, Histogram>& copodstats)
7171
{
7272
std::unordered_map<unsigned long, Histogram::Data> histdata;
73-
for(auto const& e : hbosstats)
73+
for(auto const& e : copodstats)
7474
histdata[e.first] = e.second.get_histogram();
7575
std::stringstream ss;
7676
{
@@ -80,7 +80,7 @@ using namespace chimbuko;
8080
return ss.str();
8181
}
8282

83-
void CopodParam::deserialize_cerealpb(const std::string& parameters, std::unordered_map<unsigned long, Histogram>& hbosstats)
83+
void CopodParam::deserialize_cerealpb(const std::string& parameters, std::unordered_map<unsigned long, Histogram>& copodstats)
8484
{
8585
std::stringstream ss; ss << parameters;
8686
std::unordered_map<unsigned long, Histogram::Data> histdata;
@@ -89,36 +89,36 @@ using namespace chimbuko;
8989
rd(histdata);
9090
}
9191
for(auto const& e : histdata)
92-
hbosstats[e.first] = Histogram::from_hist_data(e.second);
92+
copodstats[e.first] = Histogram::from_hist_data(e.second);
9393
}
9494

9595
std::string CopodParam::update(const std::string& parameters, bool return_update)
9696
{
97-
std::unordered_map<unsigned long, Histogram> hbosstats;
98-
deserialize_cerealpb(parameters, hbosstats);
97+
std::unordered_map<unsigned long, Histogram> copodstats;
98+
deserialize_cerealpb(parameters, copodstats);
9999
if(return_update){
100-
update_and_return(hbosstats); //update hbosstats to reflect changes
101-
return serialize_cerealpb(hbosstats);
100+
update_and_return(copodstats); //update copodstats to reflect changes
101+
return serialize_cerealpb(copodstats);
102102
}else{
103-
update(hbosstats);
103+
update(copodstats);
104104
return "";
105105
}
106106
}
107107

108-
void CopodParam::update(const std::unordered_map<unsigned long, Histogram>& hbosstats)
108+
void CopodParam::update(const std::unordered_map<unsigned long, Histogram>& copodstats)
109109
{
110110
std::lock_guard<std::mutex> _(m_mutex);
111-
for (auto& pair: hbosstats) {
111+
for (auto& pair: copodstats) {
112112
m_copodstats[pair.first] += pair.second;
113113
}
114114
}
115115

116-
void CopodParam::update_and_return(std::unordered_map<unsigned long, Histogram>& hbosstats)
116+
void CopodParam::update_and_return(std::unordered_map<unsigned long, Histogram>& copodstats)
117117
{
118118
std::lock_guard<std::mutex> _(m_mutex);
119-
for (auto& pair: hbosstats) {
119+
for (auto& pair: copodstats) {
120120
m_copodstats[pair.first] += pair.second;
121-
pair.second = hbosstats[pair.first];
121+
pair.second = copodstats[pair.first];
122122
}
123123

124124
}
@@ -135,5 +135,3 @@ using namespace chimbuko;
135135
}
136136
return 1;
137137
}
138-
139-

0 commit comments

Comments
 (0)