Bug 2911 - répondre au questionnaire ur1 sur les besoins en informatique

- added a graph that show the age pyramid of the machines
This commit is contained in:
Guillaume Raffy 2020-06-18 15:30:30 +00:00
parent 6e35053852
commit 79741a248d
1 changed files with 37 additions and 0 deletions

View File

@ -235,6 +235,40 @@ def draw_dp_gflops_price_over_time_over_time_graph(inventory, from_date, to_date
ax.grid(True)
return fig
def draw_age_pyramid_graph(inventory):
"""
:param Inventory inventory: the inventory database
"""
oldest_age = 20
age_histogram = np.zeros(shape=(oldest_age))
rows = inventory.query("SELECT * FROM machines")
for row in rows:
(name, serial_number, affectation, machine_spec_id, command_id, price_ex_vat, pos_x, pos_y, pos_z, inv_number)=row
is_cluster_node = is_cluster_node_name(name)
if is_cluster_node:
purchase_date = inventory.get_machine_purchase_date(name)
if purchase_date is not None:
purchase_time = matplotlib.dates.date2num(purchase_date.date())
age = datetime.datetime.now() - purchase_date
age_histogram[age.days / 365] += 1
# print(name, age)
fig, ax = plt.subplots()
ax.bar(range(oldest_age), age_histogram)
ax.set_xlabel('age (in years)')
ax.set_xticks(range(oldest_age))
ax.set_ylabel(u'number of compute nodes')
ax.set_title('compute_nodes_age_pyramid')
# format the ticks
ax.grid(True)
return fig
class IFigureHandler(object):
"""
specifies what to do with generated figures
@ -305,4 +339,7 @@ def draw_graphs(inventory, from_time, to_time, figure_handler):
fig = draw_dp_gflops_price_over_time_over_time_graph(inventory, from_time.date(), to_time.date())
figure_handler.on_figure_ended(fig)
fig = draw_age_pyramid_graph(inventory)
figure_handler.on_figure_ended(fig)
figure_handler.on_finalize()