From 2307fd25672338c50f4bbb8eb3a78d03a8c73ce9 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 13 Apr 2023 12:40:34 +0200 Subject: [PATCH] Add distance to csv, backport changes to python script from master branch --- plot/main.py | 35 ++++++++++++++++++++++++++++++++++ src/main/java/fr/ntr/Cell.java | 2 +- src/main/java/fr/ntr/Main.java | 2 +- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/plot/main.py b/plot/main.py index f60ff1a..e4c3667 100644 --- a/plot/main.py +++ b/plot/main.py @@ -46,12 +46,33 @@ def delay(arr: list[tuple[int, np.ndarray]]) -> np.ndarray: return delays +def rb_allocate_distance(arr: list[tuple[int, np.ndarray]], distance) -> np.ndarray: + allocate = np.zeros((size, 2)) + nb = 0 + arr.sort() + for nb_users, data in arr: + n = 0 + for x in data[:,6]: + if int(x) == distance: + n+=1 + allocate[nb, 0] = nb_users + allocate[nb, 1] = n + # print(n/data.shape[0]) + nb += 1 + return allocate + + np_arr: list[tuple[int, np.ndarray]] = list() for i in nb_files: np_arr.append((int(i.split(".")[0]), pd.read_csv(".." + os.sep + "export" + os.sep + i, delimiter=';').to_numpy())) averages = mean_mkn(np_arr) available = rb_available(np_arr) + +allocate_lp1 = rb_allocate_distance(np_arr, 150) +allocate_lp2 = rb_allocate_distance(np_arr, 500) +allocate_total = allocate_lp1[:, 1] + allocate_lp2[:, 1] + delays = delay(np_arr) delays.sort(axis=0) # Data for plotting @@ -75,4 +96,18 @@ ax[1, 0].plot(delays[:, 0], delays[:, 1], marker="o") ax[1, 0].set(xlabel='number of users', ylabel='delays(ms)', title='Delay') ax[1, 0].grid() +available.sort(axis=0) + +#ax[1, 1].scatter(allocate_lp1[:, 0], (allocate_lp1[:, 1]/(allocate_lp1[:, 1])+allocate_lp2[:, 1])*100) + +ax[1, 1].plot(available[:, 0], (allocate_lp1[:, 1]/(allocate_lp1[:, 1]+allocate_lp2[:, 1])*100)) + +#ax[1, 1].scatter(allocate_lp2[:, 0], (allocate_lp2[:, 1]/(allocate_lp1[:, 1])+allocate_lp2[:, 1])*100) + +ax[1, 1].plot(available[:, 0], (allocate_lp2[:, 1]/(allocate_lp1[:, 1]+allocate_lp2[:, 1])*100)) + +ax[1, 1].set(xlabel='number of users', ylabel='RB utilisés proche/loin/total', title='RB utilisés distance') +ax[1, 1].grid() +ax[1, 1].set_ylim([0, 100]) + plt.show() \ No newline at end of file diff --git a/src/main/java/fr/ntr/Cell.java b/src/main/java/fr/ntr/Cell.java index f373ed6..281d9a1 100644 --- a/src/main/java/fr/ntr/Cell.java +++ b/src/main/java/fr/ntr/Cell.java @@ -120,7 +120,7 @@ public class Cell { for(int j = 0; j < frame[i].length; j++) { ResourceBlock ur = frame[i][j]; if(ur.getUser() != null) { - String data = (tick + ";" + i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";" + delayAverage +";" + id + "\n"); + String data = (tick + ";" + i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";" + delayAverage +";" + ur.getUser().getDistance() + ";" + id + "\n"); try{ outputDataFile.write(data.getBytes()); }catch(IOException e){ diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index 007e8cc..d4ffbb5 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -86,7 +86,7 @@ public class Main { try { //préparation à exportation des données de chaque cellule FileOutputStream output = new FileOutputStream("export" + File.separator + (usersCell1.size()) + ".csv", true); - output.write("tick;x;y;user;bandwidth;delay;cell;\n".getBytes()); + output.write("tick;x;y;user;bandwidth;delay;distance;cell;\n".getBytes()); //création des cellules Cell cell1 = new Cell(0, schedulerCell1, frame1, usersCell1, output);