优化
This commit is contained in:
@@ -80,6 +80,8 @@ public:
|
||||
double max{};
|
||||
double min{};
|
||||
double average{};
|
||||
double smooth{};
|
||||
double variation{};
|
||||
double instant{};
|
||||
size_t times{};
|
||||
bool init{};
|
||||
@@ -90,6 +92,8 @@ public:
|
||||
max = 0.0;
|
||||
min = 0.0;
|
||||
average = 0.0;
|
||||
smooth = 0.0;
|
||||
variation = 0.0;
|
||||
instant = 0.0;
|
||||
times = 0;
|
||||
init = false;
|
||||
@@ -99,25 +103,33 @@ public:
|
||||
Ret_J(max)
|
||||
Ret_J(min)
|
||||
Ret_J(average)
|
||||
Ret_J(smooth)
|
||||
Ret_J(variation)
|
||||
Ret_J(instant)
|
||||
return ret;
|
||||
}
|
||||
[[nodiscard]] std::string to_string() const {
|
||||
return VAR_STR_5(min, max, average, instant, times);
|
||||
return VAR_STR_7(min, max, average, smooth, variation, instant, times);
|
||||
}
|
||||
void update(double value) {
|
||||
constexpr double average_times = 10.0;
|
||||
constexpr double smooth_gain = 0.125;
|
||||
constexpr double variation_gain = 0.25;
|
||||
instant = value;
|
||||
if (!init) {
|
||||
max = value;
|
||||
min = value;
|
||||
average = value;
|
||||
smooth = value;
|
||||
variation = 0.0;
|
||||
init = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
double deviation = std::abs(value - smooth);
|
||||
max = std::max(max, value);
|
||||
min = std::min(min, value);
|
||||
average = average * (average_times - 1.0) / average_times + instant / average_times;
|
||||
variation = variation * (1.0 - variation_gain) + deviation * variation_gain;
|
||||
smooth = smooth * (1.0 - smooth_gain) + value * smooth_gain;
|
||||
}
|
||||
++times;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user