fixes to ClusterStats while attempting to add a new graph show the age of machines

- made ClusterStats work on graffy-ws2 : made code compatible with python3 (still compatible with python2 though)
- added support for physix in addition to simpatix)
- fixed bug
This commit is contained in:
Guillaume Raffy 2020-06-08 17:01:02 +00:00
parent 23fa150cbe
commit bc29b1186e
2 changed files with 13 additions and 6 deletions

View File

@ -1,6 +1,10 @@
import MySQLdb # sudo port install py-mysql
import MySQLdb # sudo port install py-mysql; sudo apt install python-mysqldb
import time
import sys
if sys.version_info < (3, 0):
import StringIO
else:
from io import StringIO
import re
from wol import *
import os

View File

@ -26,6 +26,9 @@ import abc
from SimpaDbUtil import SqlDatabaseReader, SqlFile
from inventory import Inventory
def is_cluster_node_name(name):
return re.match('^simpatix[0-9]+$', name) is not None or re.match('^physix[0-9]+$', name) is not None
def get_investment_over_time(time_value, price, purchase_time):
percent_decay_per_day = 0.0 # 1.0/(7.0*365.0)
f1 = (purchase_time-time_value)*percent_decay_per_day+1.0
@ -54,7 +57,7 @@ def get_flops_price_over_time(inventory, time_value):
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 = re.match('^simpatix[0-9]+$', name)
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:
@ -113,7 +116,7 @@ def stackplot(ax, x_signal, y_signals):
:param dict(str,numpy.array) y_signals:
"""
if 'stackplot' in dir(ax):
ax.stackplot(x_signal, list(y_signals.itervalues()) )
ax.stackplot(x_signal, list(y_signals.values()) )
plt.legend(list(y_signals.keys()))
else:
# emulating missing Axes.stackplot method
@ -141,7 +144,7 @@ def draw_cluster_value_over_time_graph(inventory, from_date, to_date, graph_type
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 = re.match('^simpatix[0-9]+$', name)
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:
@ -161,7 +164,7 @@ def draw_cluster_value_over_time_graph(inventory, from_date, to_date, graph_type
if owner_dept in cluster_value.keys():
cluster_value[owner_dept] += item_value_over_time
else:
cluster_value[owner_dept] = np.zeros_like(time_value)
cluster_value[owner_dept] = item_value_over_time # np.zeros_like(time_value)
# print(purchase_date)
# print(type(from_date))