更新前
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
#include "../Base/global_include.h"
|
||||
#include "global.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
namespace Psc {
|
||||
class Base_Statistics {
|
||||
protected:
|
||||
@@ -77,13 +80,18 @@ public:
|
||||
};
|
||||
class Value_Statistics : public Base_Statistics {
|
||||
public:
|
||||
static constexpr std::size_t recent_value_count = 64;
|
||||
double max{};
|
||||
double min{};
|
||||
double average{};
|
||||
double smooth{};
|
||||
double variation{};
|
||||
double instant{};
|
||||
double p95{};
|
||||
size_t times{};
|
||||
size_t recent_count{};
|
||||
size_t recent_index{};
|
||||
std::array<double, recent_value_count> recent_values{};
|
||||
bool init{};
|
||||
Value_Statistics() {
|
||||
clear();
|
||||
@@ -95,7 +103,11 @@ public:
|
||||
smooth = 0.0;
|
||||
variation = 0.0;
|
||||
instant = 0.0;
|
||||
p95 = 0.0;
|
||||
times = 0;
|
||||
recent_count = 0;
|
||||
recent_index = 0;
|
||||
recent_values.fill(0.0);
|
||||
init = false;
|
||||
}
|
||||
[[nodiscard]] JSON to_json() const override {
|
||||
@@ -106,10 +118,12 @@ public:
|
||||
Ret_J(smooth)
|
||||
Ret_J(variation)
|
||||
Ret_J(instant)
|
||||
Ret_J(p95)
|
||||
Ret_J(times)
|
||||
return ret;
|
||||
}
|
||||
[[nodiscard]] std::string to_string() const {
|
||||
return VAR_STR_7(min, max, average, smooth, variation, instant, times);
|
||||
return VAR_STR_8(min, max, average, smooth, variation, instant, p95, times);
|
||||
}
|
||||
void update(double value) {
|
||||
constexpr double average_times = 10.0;
|
||||
@@ -131,8 +145,20 @@ public:
|
||||
variation = variation * (1.0 - variation_gain) + deviation * variation_gain;
|
||||
smooth = smooth * (1.0 - smooth_gain) + value * smooth_gain;
|
||||
}
|
||||
update_recent(value);
|
||||
++times;
|
||||
}
|
||||
private:
|
||||
void update_recent(double value) {
|
||||
recent_values[recent_index] = value;
|
||||
recent_index = (recent_index + 1) % recent_value_count;
|
||||
if(recent_count < recent_value_count) ++recent_count;
|
||||
std::array<double, recent_value_count> sorted = recent_values;
|
||||
std::sort(sorted.begin(), sorted.begin() + static_cast<std::ptrdiff_t>(recent_count));
|
||||
auto index = static_cast<std::size_t>(std::ceil(static_cast<double>(recent_count) * 0.95));
|
||||
if(index > 0) --index;
|
||||
p95 = sorted[index];
|
||||
}
|
||||
};
|
||||
class Probability_Statistics : public Base_Statistics {
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user