From 8a556e999ad8c5566db49f1dafb83a554dc3e5ea Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 24 Mar 2023 11:12:40 +0100 Subject: [PATCH] Encapsulate average_mkn --- plot/main.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/plot/main.py b/plot/main.py index a63b194..df36a68 100644 --- a/plot/main.py +++ b/plot/main.py @@ -7,22 +7,26 @@ nb_files = os.listdir(".." + os.sep + "export") size = len(nb_files) -# main array -averages = np.empty((size, 2)) -nb = 0 -for i in nb_files: - data = pd.read_csv(".." + os.sep + "export" + os.sep + i, delimiter=';').to_numpy() - rb = data[:, 4] - total = 0.0 - for x in rb: - total = total + x - average = total / len(rb) - nb_users = i.split(".")[0] - averages[nb, 0] = int(nb_users) - averages[nb, 1] = average - nb += 1 +def mean_mkn() -> np.ndarray: + averages_mkn = np.empty((size, 2)) + nb = 0 + for i in nb_files: + data = pd.read_csv(".." + os.sep + "export" + os.sep + i, delimiter=';').to_numpy() + rb = data[:, 4] + total = 0.0 + for x in rb: + total = total + x + average = total / len(rb) + nb_users = i.split(".")[0] + averages_mkn[nb, 0] = int(nb_users) + averages_mkn[nb, 1] = average + nb += 1 + return averages_mkn + + +averages = mean_mkn() # Data for plotting averages.sort(axis=0) x = averages[:, 0]