50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
|
|
import random
|
||
|
|
from statistics import mean
|
||
|
|
import time
|
||
|
|
|
||
|
|
class AverageValue():
|
||
|
|
def __init__(self): #initialise list values as zero
|
||
|
|
self.list_2= list()
|
||
|
|
self.list_10= list()
|
||
|
|
self.mean_2 =0.0
|
||
|
|
self.mean_10 =0.0
|
||
|
|
self.max_2 =0.0
|
||
|
|
self.max_10 =0.0
|
||
|
|
|
||
|
|
#insert values into list to calculate 2 minutes average
|
||
|
|
def insert_value_list2(self, val):
|
||
|
|
|
||
|
|
if len(self.list_2)>(2*60):
|
||
|
|
self.list_2.pop(0)
|
||
|
|
self.list_2.append(val)
|
||
|
|
else:
|
||
|
|
self.list_2.append(val)
|
||
|
|
return
|
||
|
|
#insert values into list to calculate 10 minutes average
|
||
|
|
def insert_value_list10(self, val):
|
||
|
|
|
||
|
|
if len(self.list_10)>(10*60):
|
||
|
|
self.list_10.pop(0)
|
||
|
|
self.list_10.append(val)
|
||
|
|
else:
|
||
|
|
self.list_10.append(val)
|
||
|
|
return
|
||
|
|
|
||
|
|
#calculate and return 2 minutes average and max
|
||
|
|
def get_m2(self):
|
||
|
|
self.mean_2 =round(mean(self.list_2),2)
|
||
|
|
return self.mean_2
|
||
|
|
def get_max2(self):
|
||
|
|
self.max_2 =round(max(self.list_2),2)
|
||
|
|
return self.max_2
|
||
|
|
|
||
|
|
#calculate and return 10 minutes average and max
|
||
|
|
def get_m10(self):
|
||
|
|
self.mean_10 =round(mean(self.list_10),2)
|
||
|
|
return self.mean_10
|
||
|
|
def get_max10(self):
|
||
|
|
self.max_10 =round(max(self.list_10),2)
|
||
|
|
return self.max_10
|
||
|
|
|
||
|
|
|