[修改]修改了错误的exporter名称
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
add_library(
|
||||
temperature-drift
|
||||
INTERFACE
|
||||
)
|
||||
|
||||
target_sources(
|
||||
temperature-drift
|
||||
INTERFACE
|
||||
temperature_drift.cpp
|
||||
temperature_drift.h
|
||||
)
|
||||
|
||||
|
||||
target_include_directories(
|
||||
temperature-drift
|
||||
INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
temperature-drift
|
||||
INTERFACE
|
||||
nlohmann_json::nlohmann_json
|
||||
)
|
||||
@@ -0,0 +1,88 @@
|
||||
#include <iostream>
|
||||
#include "temperature_drift.h"
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
int main() {
|
||||
temperature_drift algorithm;
|
||||
|
||||
algorithm.set_config(
|
||||
{
|
||||
{"TEMPERATURE_DRIFT_AMPLITUDE", 0.01},
|
||||
{"TEMPERATURE_DRIFT_AMPLITUDE_BASE", 10}
|
||||
}
|
||||
);
|
||||
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_data7.csv", std::ios::out);
|
||||
outfile<<"origin"<<','<<"temperature_drift"<<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;
|
||||
}
|
||||
// std::vector<int> x(100);
|
||||
// std::generate(x.begin(), x.end(), []() {
|
||||
// static int i = 0;
|
||||
// return i++;
|
||||
// });
|
||||
// std::vector<double> virtual_data(100, 100.0);
|
||||
// std::vector<double> temperature_drift_data;
|
||||
// sciplot::Plot plot;
|
||||
//
|
||||
// for (auto iter: virtual_data) {
|
||||
// temperature_drift_data.push_back(algorithm.eval(iter));
|
||||
// }
|
||||
//
|
||||
// plot.drawCurve(x, virtual_data).label("org");
|
||||
// plot.drawCurve(x, temperature_drift_data).label("td");
|
||||
// plot.show();
|
||||
//
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
//#include <sciplot/sciplot.hpp>
|
||||
//using namespace sciplot;
|
||||
//
|
||||
//int main(int argc, char** argv)
|
||||
//{
|
||||
// // Create values for your x-axis
|
||||
// Vec x = linspace(0.0, 5.0, 100);
|
||||
//
|
||||
// // Create a Plot object
|
||||
// Plot plot;
|
||||
//
|
||||
// // Set color palette
|
||||
// plot.palette("set2");
|
||||
//
|
||||
// // Draw a sine graph putting x on the x-axis and sin(x) on the y-axis
|
||||
// plot.drawCurve(x, std::sin(x)).label("sin(x)").lineWidth(4);
|
||||
//
|
||||
// // Draw a cosine graph putting x on the x-axis and cos(x) on the y-axis
|
||||
// plot.drawCurve(x, std::cos(x)).label("cos(x)").lineWidth(4);
|
||||
//
|
||||
// // Show the plot in a pop-up window
|
||||
// plot.show();
|
||||
//
|
||||
// // Save the plot to a PDF file
|
||||
// plot.save("plot.pdf");
|
||||
//}
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by fly on 2022/4/6.
|
||||
//
|
||||
|
||||
#include "temperature_drift.h"
|
||||
|
||||
void temperature_drift::set_config(nlohmann::json const &config) {
|
||||
try {
|
||||
eval_time_ = 0;
|
||||
amplitude_ = jsonValue(config, "TEMPERATURE_DRIFT_AMPLITUDE");
|
||||
amplitude_base_ = jsonValue(config, "TEMPERATURE_DRIFT_AMPLITUDE_BASE");
|
||||
config_ = config;
|
||||
} catch (...) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
nlohmann::json temperature_drift::config() {
|
||||
return config_;
|
||||
}
|
||||
|
||||
|
||||
double temperature_drift::eval(double value) {
|
||||
return value + amplitude_base_ + (amplitude_ * ++eval_time_);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by fly on 2022/4/6.
|
||||
//
|
||||
|
||||
#ifndef FAULT_SIMULATION_ALGORITHM_TEMPERATURE_DRIFT_H
|
||||
#define FAULT_SIMULATION_ALGORITHM_TEMPERATURE_DRIFT_H
|
||||
|
||||
#include <algorithm.hpp>
|
||||
|
||||
class temperature_drift : public algorithm {
|
||||
public:
|
||||
void set_config(nlohmann::json const &config) override;
|
||||
|
||||
nlohmann::json config() override;
|
||||
|
||||
double eval(double value) override;
|
||||
|
||||
protected:
|
||||
nlohmann::json config_{};
|
||||
double amplitude_{0};
|
||||
double amplitude_base_{0};
|
||||
uint64_t eval_time_{0};
|
||||
};
|
||||
|
||||
|
||||
#endif //FAULT_SIMULATION_ALGORITHM_TEMPERATURE_DRIFT_H
|
||||
Reference in New Issue
Block a user