From 79741a248d43fbceda3017b32202b0e2e30cbc91 Mon Sep 17 00:00:00 2001 From: Guillaume Raffy Date: Thu, 18 Jun 2020 15:30:30 +0000 Subject: [PATCH] =?UTF-8?q?Bug=202911=20-=20r=C3=A9pondre=20au=20questionn?= =?UTF-8?q?aire=20ur1=20sur=20les=20besoins=20en=20informatique?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - added a graph that show the age pyramid of the machines --- cluster_stats.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/cluster_stats.py b/cluster_stats.py index e33e0fe..03f4ec4 100644 --- a/cluster_stats.py +++ b/cluster_stats.py @@ -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()