melhorias nos gráficos

This commit is contained in:
José Henrique 2023-10-03 15:29:40 -03:00
parent aa4b1e9709
commit 6f2d9c1f78
1 changed files with 13 additions and 7 deletions

View File

@ -1,6 +1,5 @@
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import os
from common import API_REQUESTS, FRAMEWORKS from common import API_REQUESTS, FRAMEWORKS
FRAMEWORKS = [f for f, _ in FRAMEWORKS] FRAMEWORKS = [f for f, _ in FRAMEWORKS]
@ -26,10 +25,10 @@ def plot_resource_graph(x_data, y_data, title, x_label, y_label, filename):
frameworks[framework] = y_data[i] frameworks[framework] = y_data[i]
x = np.arange(len(requests)) x = np.arange(len(requests))
width = 0.10 width = 0.2
multiplier = 0 multiplier = 0
fig, ax = plt.subplots(layout='constrained') fig, ax = plt.subplots(layout='constrained', figsize=(7.5, 5))
print(x) print(x)
for framework, measurements in frameworks.items(): for framework, measurements in frameworks.items():
@ -46,9 +45,9 @@ def plot_resource_graph(x_data, y_data, title, x_label, y_label, filename):
ax.set_xlabel(x_label) ax.set_xlabel(x_label)
ax.set_ylabel(y_label) ax.set_ylabel(y_label)
ax.set_title(title) ax.set_title(title)
ax.set_xticks(x + (width/2), requests) ax.set_xticks(x + (width*1.5), requests)
ax.legend(loc='upper left', ncols=len(frameworks.items())) ax.legend(loc='upper left', ncols=len(frameworks.items()))
ax.set_ylim(0, 120) ax.set_ylim(0, 115)
plt.savefig(f'{filename}.png') plt.savefig(f'{filename}.png')
@ -80,8 +79,15 @@ def get_resource_data(filename):
for line in lines: for line in lines:
line = line.strip().split(',') line = line.strip().split(',')
if line: if line:
r = [round(float(line[1])*100), round(float(line[2])*100)]
if r[0] > 100:
r[0] = 100
if r[1] > 100:
r[1] = 100
x.append(int(line[0])) # requests x.append(int(line[0])) # requests
y.append([float(v)*100 for v in line[1:]]) # cpu, ram y.append(r) # cpu, ram
return x, y return x, y
@ -110,7 +116,7 @@ def generate_resource_graph(filename, framework_name, endpoint_name):
y.append([data[resource_index] for data in y_data]) y.append([data[resource_index] for data in y_data])
graph_file = f'{resource}_{endpoint_name.replace("/", "").replace("?", "")}' graph_file = f'{resource}_{endpoint_name.replace("/", "").replace("?", "")}'
plot_resource_graph(x, y, f'Uso de {resource.upper()} - {endpoint_name}', 'Número de requisições', 'Uso (%)', graph_file) plot_resource_graph(x, y, f'Uso de {resource.upper()} - {endpoint_name}', 'Número de requisições', f'Uso de {resource.upper()} (%)', graph_file)
if __name__ == '__main__': if __name__ == '__main__':
endpoints = [config[0] for config in API_REQUESTS] endpoints = [config[0] for config in API_REQUESTS]