[tor-commits] [metrics-tasks/master] Fix calculate_2mo_avg (#9889).

karsten at torproject.org karsten at torproject.org
Mon Mar 31 13:25:43 UTC 2014


commit 2136868ce6632d3bfe1c2dd27d8013691262feb2
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Wed Mar 26 12:31:17 2014 +0100

    Fix calculate_2mo_avg (#9889).
---
 task-9889/tshirt.py |   16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/task-9889/tshirt.py b/task-9889/tshirt.py
index ec67881..581fac3 100755
--- a/task-9889/tshirt.py
+++ b/task-9889/tshirt.py
@@ -98,18 +98,8 @@ def calculate_2mo_avg(response, response_type):
       if data['values'][i] not in [None, 'null']:
         _sum += (data['values'][i])
         count += 1
-  # Find number of values between last and today
-  time_interval = int((today - last).total_seconds())
-  last_today_values = time_interval/data['interval']
   # Calculate the result
-  if response_type == 'uptime':
-    total_up_time = _sum * data['factor'] * data['interval']
-    uptime_percent = round(total_up_time * 100 / TWO_MONTHS, 2)
-    return uptime_percent
-  elif response_type == 'bandwidth':
-    total_values = count + last_today_values
-    result = (_sum * data['factor'])/total_values
-    return round(result/1000.0, 2)
+  return (_sum * data['factor'])/count
 
 
 def check_in_ports(ports):
@@ -139,13 +129,13 @@ def check_exit_port(response):
 def get_uptime_percent(response):
   """ Calculates the relay's uptime from onionoo's uptime document """
 
-  return calculate_2mo_avg(response, 'uptime')
+  return round(calculate_2mo_avg(response, 'uptime') * 100, 2)
 
 
 def get_avg_bandwidth(response):
   """ Calculates average bandwidth of traffic through the relay """
 
-  return calculate_2mo_avg(response, 'bandwidth')
+  return round(calculate_2mo_avg(response, 'bandwidth') / 1000.0, 2)
   
 
 def check_tshirt(search_query):





More information about the tor-commits mailing list