This repository has been archived on 2023-08-28. You can view files and clone it, but cannot push or open issues or pull requests.
ntr-interferences/plot/main.py
2023-04-07 08:12:46 +02:00

105 lines
3.0 KiB
Python

import os
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
nb_files = os.listdir(".." + os.sep + "export")
size = len(nb_files)
def mean_mkn(arr: list[tuple[int, np.ndarray]]) -> np.ndarray:
averages_mkn = np.empty((size, 2))
nb = 0
for nb_users, data in arr:
rb = data[:, 4]
total = 0.0
for x in rb:
total = total + x
average = total / len(rb)
averages_mkn[nb, 0] = nb_users
averages_mkn[nb, 1] = average
nb += 1
return averages_mkn
def rb_available(arr: list[tuple[int, np.ndarray]]) -> np.ndarray:
available = np.zeros((size, 2))
nb = 0
for nb_users, data in arr:
available[nb, 0] = nb_users
available[nb, 1] = (data.shape[0] / (200 * 10000)) * 100
nb += 1
return available
def delay(arr: list[tuple[int, np.ndarray]]) -> np.ndarray:
delays = np.zeros((size, 2))
nb = 0
for nb_users, data in arr:
d = data[:, 5]
for x in d:
delays[nb, 0] = nb_users
delays[nb, 1] = float(x)
nb += 1
return delays
def rb_allocate_distance(arr: list[tuple[int, np.ndarray]], distance) -> np.ndarray:
allocate = np.zeros((size, 2))
nb = 0
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#(n/ (200 * 10000)) * 100
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, 200)
allocate_lp2 = rb_allocate_distance(np_arr, 400)
delays = delay(np_arr)
delays.sort(axis=0)
# Data for plotting
averages.sort(axis=0)
fig, ax = plt.subplots(2, 2)
ax[0, 0].scatter(averages[:, 0], averages[:, 1])
ax[0, 0].set(xlabel='number of users', ylabel='Efficacité spectrale', title='Efficacité spectrale')
ax[0, 0].grid()
ax[0, 1].scatter(available[:, 0], available[:, 1])
ax[0, 1].set(xlabel='number of users', ylabel='RB utilisés', title='Pourcentage de RB utilisés')
ax[0, 1].grid()
ax[1, 0].scatter(delays[:, 0], delays[:, 1])
ax[1, 0].set(xlabel='number of users', ylabel='delays(ms)', title='Delay')
ax[1, 0].grid()
#ax[1, 1].scatter(available[:, 0], (available[:, 1]/available_lp1[:, 1]/available_lp2[:, 1])*100)
available.sort(axis=0)
ax[1, 1].scatter(available[:, 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(available[:, 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()
plt.show()