aboutsummaryrefslogtreecommitdiff
path: root/src/lib/ndpi_analyze.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/ndpi_analyze.c')
-rw-r--r--src/lib/ndpi_analyze.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/lib/ndpi_analyze.c b/src/lib/ndpi_analyze.c
index 176f4eeef..1f72cb978 100644
--- a/src/lib/ndpi_analyze.c
+++ b/src/lib/ndpi_analyze.c
@@ -38,18 +38,14 @@
/* ********************************************************************************* */
void ndpi_init_data_analysis(struct ndpi_analyze_struct *ret, u_int16_t _max_series_len) {
- u_int32_t len;
-
memset(ret, 0, sizeof(*ret));
if(_max_series_len > MAX_SERIES_LEN) _max_series_len = MAX_SERIES_LEN;
ret->num_values_array_len = _max_series_len;
if(ret->num_values_array_len > 0) {
- len = sizeof(u_int64_t) * ret->num_values_array_len;
- if((ret->values = ndpi_malloc(len)) != NULL)
- memset(ret->values, 0, len);
- else
+ if((ret->values = (u_int64_t *)ndpi_calloc(ret->num_values_array_len,
+ sizeof(u_int64_t))) == NULL)
ret->num_values_array_len = 0;
}
}
@@ -116,6 +112,12 @@ void ndpi_data_add_value(struct ndpi_analyze_struct *s, const u_int64_t value) {
if(!s)
return;
+ if(s->num_data_entries > 0) {
+ u_int64_t last = ndpi_data_last(s);
+
+ s->jitter_total += (last > value) ? (last - value) : (value - last);
+ }
+
if(s->sum_total == 0)
s->min_val = s->max_val = value;
else {
@@ -205,6 +207,15 @@ float ndpi_data_mean(struct ndpi_analyze_struct *s) {
/* ********************************************************************************* */
+float ndpi_data_jitter(struct ndpi_analyze_struct *s) {
+ if(!s || s->num_data_entries < 2)
+ return(0);
+ else
+ return((float)s->jitter_total / (float)(s->num_data_entries - 1));
+}
+
+/* ********************************************************************************* */
+
/* Compute the average only on the sliding window */
float ndpi_data_window_average(struct ndpi_analyze_struct *s) {
if(s && s->num_values_array_len) {
@@ -1356,9 +1367,16 @@ int ndpi_ses_add_value(struct ndpi_ses_struct *ses, const double _value, double
if(ses->num_values == 0)
*forecast = value;
- else
+ else {
+#if 1
+ /* "Classic" formula */
+ *forecast = (ses->params.alpha * value) + ((1 - ses->params.alpha) * ses->last_forecast);
+#else
+ /* Alternative formula */
*forecast = (ses->params.alpha * (ses->last_value - ses->last_forecast)) + ses->last_forecast;
-
+#endif
+ }
+
error = value - *forecast;
sq_error = error * error;
ses->sum_square_error += sq_error, ses->prev_error.sum_square_error += sq_error;