89 lines
2.3 KiB
Python
89 lines
2.3 KiB
Python
import pandas as pd
|
|
import numpy as np
|
|
|
|
|
|
filename_participants = "res/full_participant_measurement.csv"
|
|
|
|
filename_left = "res/flowrate_left.csv"
|
|
filename_right = "res/flowrate_right.csv"
|
|
filename_both = "res/flowrate_both.csv"
|
|
|
|
arrival_rate = 1 / 36.66 # Measured
|
|
|
|
|
|
def get_response_time_and_utilization(S, arrival_rate):
|
|
df = pd.read_csv(filename_participants)
|
|
|
|
E_S = S.mean()
|
|
E_S2 = (S**2).mean()
|
|
|
|
utilization = arrival_rate * E_S
|
|
|
|
W = E_S + (arrival_rate * E_S2) / 2*(1 - utilization)
|
|
|
|
return W, utilization
|
|
|
|
|
|
def print_response_time():
|
|
df = pd.read_csv(filename_participants)
|
|
S = df["time"]
|
|
|
|
W, rho = get_response_time_and_utilization(S, arrival_rate)
|
|
|
|
print(f"//")
|
|
print(f"// Response time")
|
|
print(f"// ")
|
|
print(f" E{{S}} = {S.mean():.3f} s")
|
|
print(f"1/lambda = {1/arrival_rate:.3f} s")
|
|
print(f" rho = {rho:.3f}")
|
|
print(f" W = {W:.3f} s")
|
|
|
|
|
|
def print_best_achievable_response_time():
|
|
# Get mean flowrates
|
|
|
|
df_left = pd.read_csv(filename_left)
|
|
df_right = pd.read_csv(filename_right)
|
|
df_both = pd.read_csv(filename_both)
|
|
|
|
flowrate_left = np.mean(np.array(df_left["flowrate"]))
|
|
flowrate_right = np.mean(np.array(df_right["flowrate"]))
|
|
flowrate_both = np.mean(np.array(df_both["flowrate"]))
|
|
|
|
# Convert service times to what they would be with the best strategy
|
|
|
|
df_part = pd.read_csv(filename_participants)
|
|
|
|
times_left = np.array(df_part[df_part["button"] == "left"]["time"])
|
|
times_right = np.array(df_part[df_part["button"] == "right"]["time"])
|
|
times_both = np.array(df_part[df_part["button"] == "both"]["time"])
|
|
|
|
sizes_left = times_left * flowrate_left
|
|
sizes_right = times_right * flowrate_right
|
|
sizes_both = times_both * flowrate_both
|
|
|
|
sizes = np.concatenate([sizes_left, sizes_right, sizes_both])
|
|
|
|
S = sizes / flowrate_right
|
|
|
|
# Calculate response time
|
|
|
|
W, rho = get_response_time_and_utilization(S, arrival_rate)
|
|
|
|
print(f"//")
|
|
print(f"// Best possible response time")
|
|
print(f"// ")
|
|
print(f" E{{S}} = {S.mean():.3f} s")
|
|
print(f"1/lambda = {1/arrival_rate:.3f} s")
|
|
print(f" rho = {rho:.3f}")
|
|
print(f" W = {W:.3f} s")
|
|
|
|
|
|
def main():
|
|
print_response_time()
|
|
print_best_achievable_response_time()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|