From 47a304c1297ce72504d1c2e70ded488c9ff3bab4 Mon Sep 17 00:00:00 2001 From: Andreas Tsouchlos Date: Thu, 29 May 2025 23:22:20 -0400 Subject: [PATCH] Add approximate_response_time.py --- scripts/approximate_response_time.py | 88 ++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 scripts/approximate_response_time.py diff --git a/scripts/approximate_response_time.py b/scripts/approximate_response_time.py new file mode 100644 index 0000000..ae14bd5 --- /dev/null +++ b/scripts/approximate_response_time.py @@ -0,0 +1,88 @@ +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()