[添加]opcua exporter
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
add_library(
|
||||
white-noise
|
||||
INTERFACE
|
||||
)
|
||||
|
||||
target_sources(
|
||||
white-noise
|
||||
INTERFACE
|
||||
white_noise.cpp
|
||||
white_noise.h
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
white-noise
|
||||
INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
white-noise
|
||||
INTERFACE
|
||||
nlohmann_json::nlohmann_json
|
||||
)
|
||||
@@ -0,0 +1,80 @@
|
||||
//
|
||||
// Created by baiguwen on 2022/4/24.
|
||||
//
|
||||
#include <iostream>
|
||||
#include "white_noise.h"
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
//#include <sciplot/sciplot.hpp>
|
||||
|
||||
int main() {
|
||||
white_noise algorithm;
|
||||
double white_noise_stddev=2;
|
||||
double white_noise_mean=0;
|
||||
|
||||
algorithm.set_config(
|
||||
{
|
||||
{"WHITE_NOISE_MEAN", white_noise_mean},
|
||||
{"WHITE_NOISE_STDDEV", white_noise_stddev},
|
||||
|
||||
}
|
||||
);
|
||||
std::vector <std::vector<double>> user_arr;
|
||||
std::ifstream fp("C:/data/user_data.csv");
|
||||
std::string line;
|
||||
getline(fp,line);
|
||||
while (getline(fp,line)){
|
||||
std::vector <double> data_line;
|
||||
std::string number;
|
||||
std::istringstream readstr(line);
|
||||
for(int j = 0;j < 2814;j++){
|
||||
getline(readstr,number,',');
|
||||
data_line.push_back(atof(number.c_str()));
|
||||
}
|
||||
user_arr.push_back(data_line);
|
||||
}
|
||||
std::ofstream outfile;
|
||||
outfile.open("C:/data/user_data8.csv", std::ios::out);
|
||||
outfile<<"origin"<<','<<"white_noise"<<std::endl;
|
||||
for (int i = 0; i <2814; ++i) {
|
||||
user_arr[i][1]=algorithm.eval(user_arr[i][0]);
|
||||
std::cout << i << "\t" << user_arr[i][1] << std::endl;
|
||||
outfile<<user_arr[i][0]<<','<<user_arr[i][1]<<std::endl;
|
||||
}
|
||||
outfile.close();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// int length=round(white_noise_stddev)*6;
|
||||
// std::vector<int> x(length+1,0);
|
||||
//for(int i=0;i<length+1;i++){
|
||||
// x[i]=100-length/2+round(white_noise_mean)+i;
|
||||
//}
|
||||
//
|
||||
// std::vector<double> virtual_data(10000, 100.0);
|
||||
// std::vector<double> white_noise_data;
|
||||
// std::vector<int> white_noise_data_number(length+1,0);
|
||||
// sciplot::Plot plot;
|
||||
//
|
||||
// for (auto iter: virtual_data) {
|
||||
// double a=algorithm.eval(iter);
|
||||
// white_noise_data.push_back (round(a));
|
||||
// std::cout << iter << "\t" << a << std::endl;
|
||||
// }
|
||||
// for(int k=0;k<virtual_data.size();k++){
|
||||
// for(int l=0;l<length+1;l++){
|
||||
// if(white_noise_data[k]==x[l])
|
||||
// white_noise_data_number[l]++;
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// plot.drawCurve(x, white_noise_data_number).label("td");
|
||||
// plot.show();
|
||||
//
|
||||
// return 0;
|
||||
//}
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Created by baiguwen on 2022/4/24.
|
||||
//
|
||||
#include "white_noise.h"
|
||||
|
||||
void white_noise::set_config(const nlohmann::json &config) {
|
||||
try {
|
||||
mean_ = jsonValue(config, "WHITE_NOISE_MEAN");
|
||||
standard_deviation_ = jsonValue(config, "WHITE_NOISE_STDDEV");
|
||||
normal_distribution_.reset(new std::normal_distribution<>(mean_, standard_deviation_));
|
||||
config_ = config;
|
||||
} catch (...) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
nlohmann::json white_noise::config() {
|
||||
return config_;
|
||||
}
|
||||
|
||||
|
||||
double white_noise::eval(double value) {
|
||||
if (normal_distribution_) {
|
||||
value = value + normal_distribution_->operator()(mt19937_);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by baiguwen on 2022/4/24.
|
||||
//
|
||||
|
||||
#ifndef FAULT_SIMULATION_ALGORITHM_WHITE_NOISE_H
|
||||
#define FAULT_SIMULATION_ALGORITHM_WHITE_NOISE_H
|
||||
#include <algorithm.hpp>
|
||||
#include <math.h>
|
||||
#include <random>
|
||||
class white_noise : public algorithm {
|
||||
public:
|
||||
void set_config(const nlohmann::json &config) override;
|
||||
|
||||
nlohmann::json config() override;
|
||||
|
||||
double eval(double value) override;
|
||||
|
||||
protected:
|
||||
nlohmann::json config_{};
|
||||
std::mt19937 mt19937_{std::random_device()()};
|
||||
std::shared_ptr <std::normal_distribution<>> normal_distribution_;
|
||||
double mean_{0};
|
||||
double standard_deviation_{0};
|
||||
|
||||
};
|
||||
#endif //FAULT_SIMULATION_ALGORITHM_WHITE_NOISE_H
|
||||
Reference in New Issue
Block a user