diff --git a/.htconfig.php b/.htconfig.php index 6752b9cd..3e70ecda 100644 --- a/.htconfig.php +++ b/.htconfig.php @@ -13,6 +13,14 @@ $default_timezone = 'Europe/Amsterdam'; // What is your site name? $a->config['sitename'] = "EXPERIMENTAL Friendica public directory"; +//Statistic display settings. +$a->config['stats'] = array( + + //For site health, the max age for which to display data. + 'maxDataAge' => 3600*24*30*4 //120 days = ~4 months + +); + //Settings related to the syncing feature. $a->config['syncing'] = array( @@ -46,7 +54,7 @@ $a->config['site-health'] = array( //Wait for at least ... before probing a site again. //The longer this value, the more "stable" site-healths will be over time. //Note: If a bad (negative) health site submits something, a probe will be performed regardless. - 'min_probe_delay' => 3*24*3600, // 3 days + 'min_probe_delay' => 24*3600, // 1 day //Probes get a simple /friendica/json file from the server. //Feel free to set this timeout to a very tight value. diff --git a/include/smoothing.js b/include/smoothing.js new file mode 100644 index 00000000..9f1d918d --- /dev/null +++ b/include/smoothing.js @@ -0,0 +1,81 @@ +(function(){ + + window.Smoothing = { + + /** + * Applies both a moving average bracket and and exponential smoothing. + * @param {array} raw The raw Y values. + * @param {float} factor The exponential smoothing factor to apply (between o and 1). + * @param {int} bracket The amount of datapoints to add to the backet on each side! (2 = 5 data points) + * @return {array} The smoothed Y values. + */ + exponentialMovingAverage: function(raw, factor, bracket){ + + var output = []; + var smoother = new ExponentialSmoother(factor); + + //Transform each data point with the smoother. + for (var i = 0; i < raw.length; i++){ + + var input = raw[i]; + + //See if we should bracket. + if(bracket > 0){ + + //Cap our start and end so it doesn't go out of bounds. + var start = Math.max(i-bracket, 0); + var end = Math.min(i+bracket, raw.length); + + //Push the range to our input. + input = []; + for(var j = start; j < end; j++){ + input.push(raw[j]); + } + + } + + output.push( + smoother.transform(input) + ); + }; + + return output; + + } + + }; + + // Exponential Smoother class. + var ExponentialSmoother = function(factor){ + this.currentValue = null; + this.smoothingFactor = factor || 1; + }; + + ExponentialSmoother.prototype.transform = function(input){ + + // In case our input is a bracket, first average it. + if(input.length){ + var len = input.length; + var sum = 0; + for (var i = input.length - 1; i >= 0; i--) + sum += input[i] + input = sum/len; + } + + // Start with our initial value. + if(this.currentValue === null){ + this.currentValue = input; + } + + // Our output is basically an updated value. + return this.currentValue = + + // Weigh our current value with the smoothing factor. + (this.currentValue * this.smoothingFactor) + + + // Add the input to it with the inverse value of the smoothing factor. + ( (1-this.smoothingFactor) * input ); + + }; + +})(); \ No newline at end of file diff --git a/mod/health.php b/mod/health.php index 6f285326..4d5fa102 100644 --- a/mod/health.php +++ b/mod/health.php @@ -129,6 +129,42 @@ function health_summary(&$a){ function health_details($a, $id) { + //Max data age in MySQL date. + $maxDate = date('Y-m-d H:i:s', time()-($a->config['stats']['maxDataAge'])); + + //Include graphael line charts. + $a->page['htmlhead'] .= ''.PHP_EOL; + $a->page['htmlhead'] .= ''.PHP_EOL; + $a->page['htmlhead'] .= ''.PHP_EOL; + $a->page['htmlhead'] .= ''.PHP_EOL; + $a->page['htmlhead'] .= ''; + //The overall health status. $r = q( "SELECT * FROM `site-health` @@ -196,62 +232,14 @@ function health_details($a, $id) //Get probe speed data. $r = q( - "SELECT `request_time`, `dt_performed` FROM `site-probe` - WHERE `site_health_id` = %u", - intval($site['id']) + "SELECT AVG(`request_time`) as `avg_time`, date(`dt_performed`) as `date` FROM `site-probe` + WHERE `site_health_id` = %u + AND `dt_performed` > '%s' + GROUP BY `date`", + intval($site['id']), + $maxDate ); if(count($r)){ - //Include graphael line charts. - $a->page['htmlhead'] .= ''.PHP_EOL; - $a->page['htmlhead'] .= ''.PHP_EOL; - $a->page['htmlhead'] .= ''; - $speeds = array(); - $times = array(); - $mintime = time(); - foreach($r as $row){ - $speeds[] = $row['request_time']; - $time = strtotime($row['dt_performed']); - $times[] = $time; - if($mintime > $time) $mintime = $time; - } - for($i=0; $i < count($times); $i++){ - $times[$i] -= $mintime; - $times[$i] = floor($times[$i] / (24*3600)); - } - $a->page['htmlhead'] .= - ''; - } - - //Get scrape speed data. - $r = q( - "SELECT AVG(`total_time`) as `avg_time`, date(`dt_performed`) as `date` FROM `site-scrape` - WHERE `site_health_id` = %u GROUP BY `date`", - intval($site['id']) - // date('Y-m-d H:i:s', time()-(3*24*3600)) //Max 3 days old. - ); - if($r && count($r)){ - //Include graphael line charts. - $a->page['htmlhead'] .= ''.PHP_EOL; - $a->page['htmlhead'] .= ''.PHP_EOL; - $a->page['htmlhead'] .= ''; $speeds = array(); $times = array(); $mintime = time(); @@ -267,21 +255,66 @@ function health_details($a, $id) } $a->page['htmlhead'] .= ''; + } + + //Get scrape speed data. + $r = q( + "SELECT AVG(`total_time`) as `avg_time`, date(`dt_performed`) as `date` FROM `site-scrape` + WHERE `site_health_id` = %u + AND `dt_performed` > '%s' + GROUP BY `date`", + intval($site['id']), + $maxDate + ); + if($r && count($r)){ + $speeds = array(); + $times = array(); + $mintime = time(); + foreach($r as $row){ + $speeds[] = $row['avg_time']; + $time = strtotime($row['date']); + $times[] = $time; + if($mintime > $time) $mintime = $time; + } + for($i=0; $i < count($times); $i++){ + $times[$i] -= $mintime; + $times[$i] = floor($times[$i] / (24*3600)); + } + $a->page['htmlhead'] .= + ''; diff --git a/view/health_details.tpl b/view/health_details.tpl index 7d6f694e..99cd4ebf 100644 --- a/view/health_details.tpl +++ b/view/health_details.tpl @@ -28,8 +28,9 @@
Profile speed: $avg_profile_timems
Scrape speed: $avg_scrape_timems
Submit speed: $avg_submit_timems
- $no_scrape_support + $no_scrape_support
+ Toggle raw data -
Probe speed
-
Submit speed
+
Probe speed in ms
(last 120 days)
+
Submit speed in ms
(last 120 days)