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