[修改]修改了错误的exporter名称
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
add_library(
|
||||
periodic-interference
|
||||
INTERFACE
|
||||
)
|
||||
|
||||
target_sources(
|
||||
periodic-interference
|
||||
INTERFACE
|
||||
periodic_interference.cpp
|
||||
periodic_interference.h
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
periodic-interference
|
||||
INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
periodic-interference
|
||||
INTERFACE
|
||||
nlohmann_json::nlohmann_json
|
||||
)
|
||||
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// Created by baiguwen on 2022/4/23.
|
||||
//
|
||||
#include <iostream>
|
||||
#include "periodic_interference.h"
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
int main() {
|
||||
periodic_interference algorithm;
|
||||
|
||||
algorithm.set_config(
|
||||
{
|
||||
{"PERIODIC_INTERFERENCE_AMPLITUDE", 20},
|
||||
{"PERIODIC_INTERFERENCE_AMPLITUDE_BASE", 1},
|
||||
{"CYCLE_", 20}
|
||||
|
||||
}
|
||||
);
|
||||
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_data5.csv", std::ios::out);
|
||||
outfile<<"origin"<<','<<"periodic_interference"<<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;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Created by baiguwen on 2022/4/23.
|
||||
//
|
||||
#include "periodic_interference.h"
|
||||
#include <math.h>
|
||||
#include <numbers>
|
||||
#include <random>
|
||||
|
||||
void periodic_interference::set_config(const nlohmann::json &config) {
|
||||
try {
|
||||
eval_time_ = 0;
|
||||
amplitude_ = jsonValue(config, "PERIODIC_INTERFERENCE_AMPLITUDE");
|
||||
amplitude_base_ = jsonValue(config, "PERIODIC_INTERFERENCE_AMPLITUDE_BASE");
|
||||
cycle_ = jsonValue(config, "CYCLE_");
|
||||
config_ = config;
|
||||
} catch (...) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
nlohmann::json periodic_interference::config() {
|
||||
return config_;
|
||||
}
|
||||
|
||||
|
||||
double periodic_interference::eval(double value) {
|
||||
return value + amplitude_base_ * sin((2 * std::numbers::pi / cycle_) * eval_time_++) + amplitude_;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Created by baiguwen on 2022/4/23.
|
||||
//
|
||||
|
||||
#ifndef FAULT_SIMULATION_ALGORITHM_PERIODIC_INTERFERENCE_H
|
||||
#define FAULT_SIMULATION_ALGORITHM_PERIODIC_INTERFERENCE_H
|
||||
|
||||
|
||||
#include <algorithm.hpp>
|
||||
|
||||
class periodic_interference : public algorithm {
|
||||
public:
|
||||
void set_config(const nlohmann::json &config) override;
|
||||
|
||||
nlohmann::json config() override;
|
||||
|
||||
double eval(double value) override;
|
||||
|
||||
protected:
|
||||
nlohmann::json config_{};
|
||||
double amplitude_{0};
|
||||
double amplitude_base_{0};
|
||||
double cycle_{0};
|
||||
uint64_t eval_time_{0};
|
||||
};
|
||||
|
||||
|
||||
#endif //FAULT_SIMULATION_ALGORITHM_PERIODIC_INTERFERENCE_H
|
||||
Reference in New Issue
Block a user