-
Notifications
You must be signed in to change notification settings - Fork 0
/
SystemStats.py
75 lines (52 loc) · 2.11 KB
/
SystemStats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import pandas as pd
import numpy as np, scipy.stats as st
import matplotlib.pyplot as plt
def serverStats(availableServers,totalTime=4800 , numServers = 5):
totalServiceTime =0
avgBusyTime = 0
for server in availableServers:
avgBusyTime += server.TotalServiceTime/totalTime
return avgBusyTime/numServers
def customerStat(queue):
AllCustomers=queue.customerServerd
arrivalTime=[]
timeSpent=[]
numOfSatisfied = 0
for customer in AllCustomers:
arrivalTime.append(customer.interarrival_time)
timeSpent.append(customer.timeSpent)
if(customer.num_of_services == 1):
numOfSatisfied +=1
return arrivalTime,timeSpent,numOfSatisfied
def saveSystemStat(dic,system):
arrivalTime,timeSpent,satisfiedCustomer = customerStat(system.queue)
dic["numCustomer"].append(len(timeSpent))
dic["totalTimeInSys"].append(sum(timeSpent)/len(timeSpent) )
dic["maxTimeInSys"].append(max(timeSpent))
# total num of satisfied customer
dic["numSatisfied"].append(satisfiedCustomer)
# queue stats
dic["avgQueueLen"].append(sum(system.queue.numCustomer)/len(system.queue.numCustomer))
dic["maxQueueLen"].append(system.queue.maxLen)
# average server busy time
dic["meanBusyTime"].append(serverStats(system.servers.availableServers))
# max number of busy server
dic["maxBusyServer"].append(system.queue.maxNumBusyServer)
def showSystemStats(dic):
variables=dic.keys()
dataframe = {"variables":[],"mean":[],"stander deviation":[],"confidence interval 95%":[]}
for variable in list(variables):
mean , std, confidenceInterval = variableStats(dic[variable])
dataframe["variables"].append(variable)
dataframe["mean"].append(mean)
dataframe["stander deviation"].append(std)
dataframe["confidence interval 95%"].append(confidenceInterval)
dataframe=pd.DataFrame(dataframe)
dataframe.set_index("variables")
pd.set_option('display.max_columns', None)
print(dataframe)
def variableStats(list_):
mean=np.mean(list_)
std = np.std(list_)
confidenceInterval = st.t.interval(0.95, len(list_)-1, loc=np.mean(list_), scale=st.sem(list_))
return mean , std , confidenceInterval