Files
data-collection-terminal/opcua-expoter/fault-simulation-algorithm/white_noise/main.cpp
2024-08-28 09:26:25 +08:00

80 lines
2.2 KiB
C++

//
// 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;
//}