fixed pep8 styling problems
This commit is contained in:
parent
78d7e02285
commit
14e3e12571
|
@ -1,5 +1,5 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
import sys
|
# import sys
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import datetime
|
import datetime
|
||||||
|
@ -19,29 +19,33 @@ if r != 0:
|
||||||
matplotlib.use('Agg') # use Anti Grain Geometry backend for non-interactive rendering into pngs, svg, etc...
|
matplotlib.use('Agg') # use Anti Grain Geometry backend for non-interactive rendering into pngs, svg, etc...
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
#import matplotlib.pyplot as plt
|
# import matplotlib.pyplot as plt
|
||||||
import matplotlib.dates
|
import matplotlib.dates
|
||||||
import abc
|
import abc
|
||||||
|
|
||||||
from SimpaDbUtil import SqlDatabaseReader, SqlFile
|
# from SimpaDbUtil import SqlDatabaseReader, SqlFile
|
||||||
from inventory import Inventory
|
# from inventory import Inventory
|
||||||
|
|
||||||
|
|
||||||
def is_cluster_node_name(name):
|
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
|
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):
|
def get_investment_over_time(time_value, price, purchase_time):
|
||||||
percent_decay_per_day = 0.0 # 1.0/(7.0*365.0)
|
percent_decay_per_day = 0.0 # 1.0/(7.0*365.0)
|
||||||
f1 = (purchase_time-time_value)*percent_decay_per_day+1.0
|
f1 = (purchase_time - time_value) * percent_decay_per_day + 1.0
|
||||||
f2 = np.where( f1 < 0.0, 0.0, f1 )
|
f2 = np.where(f1 < 0.0, 0.0, f1)
|
||||||
f3 = np.where( time_value < purchase_time, 0.0, f2 )
|
f3 = np.where(time_value < purchase_time, 0.0, f2)
|
||||||
|
|
||||||
return f3 * price
|
return f3 * price
|
||||||
|
|
||||||
|
|
||||||
def get_flops_over_time(inventory, time_value, computer_id, purchase_time):
|
def get_flops_over_time(inventory, time_value, computer_id, purchase_time):
|
||||||
"""
|
"""
|
||||||
:param Inventory inventory:
|
:param Inventory inventory:
|
||||||
"""
|
"""
|
||||||
return np.where( time_value < purchase_time, 0.0, inventory.get_computer_dflops(computer_id) )
|
return np.where(time_value < purchase_time, 0.0, inventory.get_computer_dflops(computer_id))
|
||||||
|
|
||||||
|
|
||||||
def get_flops_price_over_time(inventory, time_value):
|
def get_flops_price_over_time(inventory, time_value):
|
||||||
"""
|
"""
|
||||||
|
@ -56,7 +60,7 @@ def get_flops_price_over_time(inventory, time_value):
|
||||||
flops_prices = []
|
flops_prices = []
|
||||||
|
|
||||||
for row in rows:
|
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
|
(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)
|
is_cluster_node = is_cluster_node_name(name)
|
||||||
if is_cluster_node:
|
if is_cluster_node:
|
||||||
purchase_date = inventory.get_machine_purchase_date(name)
|
purchase_date = inventory.get_machine_purchase_date(name)
|
||||||
|
@ -64,20 +68,20 @@ def get_flops_price_over_time(inventory, time_value):
|
||||||
# print(name, price_ex_vat)
|
# print(name, price_ex_vat)
|
||||||
purchase_time = matplotlib.dates.date2num(purchase_date.date())
|
purchase_time = matplotlib.dates.date2num(purchase_date.date())
|
||||||
computer_flops = inventory.get_computer_dflops(name)
|
computer_flops = inventory.get_computer_dflops(name)
|
||||||
flops_price = ( price_ex_vat-inventory.get_computer_options_price(name) ) / computer_flops
|
flops_price = (price_ex_vat - inventory.get_computer_options_price(name)) / computer_flops
|
||||||
# print ( purchase_date, name, price_ex_vat, computer_flops, flops_price )
|
# print ( purchase_date, name, price_ex_vat, computer_flops, flops_price )
|
||||||
flops_prices.append({'time':purchase_time, 'flops_price':flops_price, 'purchase_date':purchase_date})
|
flops_prices.append({'time': purchase_time, 'flops_price': flops_price, 'purchase_date': purchase_date})
|
||||||
|
|
||||||
flops_prices = sorted(flops_prices, key=get_key)
|
flops_prices = sorted(flops_prices, key=get_key)
|
||||||
|
|
||||||
flops_price_over_time = np.where( True, 0.0, 0.0 )
|
flops_price_over_time = np.where(True, 0.0, 0.0)
|
||||||
for item in flops_prices:
|
for item in flops_prices:
|
||||||
# print(item)
|
# print(item)
|
||||||
flops_price_over_time = np.where( time_value < item['time'], flops_price_over_time, item['flops_price'])
|
flops_price_over_time = np.where(time_value < item['time'], flops_price_over_time, item['flops_price'])
|
||||||
|
|
||||||
|
|
||||||
return flops_price_over_time
|
return flops_price_over_time
|
||||||
|
|
||||||
|
|
||||||
def get_computer_value_over_time(inventory, computer_id, time_value, flops_price_over_time, purchase_time):
|
def get_computer_value_over_time(inventory, computer_id, time_value, flops_price_over_time, purchase_time):
|
||||||
# print('flops_price_over_time = ', flops_price_over_time)
|
# print('flops_price_over_time = ', flops_price_over_time)
|
||||||
computer_flops = inventory.get_computer_dflops(computer_id)
|
computer_flops = inventory.get_computer_dflops(computer_id)
|
||||||
|
@ -110,6 +114,8 @@ def get_computer_value_over_time(inventory, computer_id, time_value, flops_price
|
||||||
# from_signal = y_stack[series_index-1,:]
|
# from_signal = y_stack[series_index-1,:]
|
||||||
# ax.fill_between(x_signal, from_signal, y_stack[series_index,:], color=colors[series_index], lw=0.0, label=y_signals.keys()[series_index])
|
# ax.fill_between(x_signal, from_signal, y_stack[series_index,:], color=colors[series_index], lw=0.0, label=y_signals.keys()[series_index])
|
||||||
# plt.legend()
|
# plt.legend()
|
||||||
|
|
||||||
|
|
||||||
def stackplot(ax, x_signal, y_signals):
|
def stackplot(ax, x_signal, y_signals):
|
||||||
"""
|
"""
|
||||||
:param matplotlib.Axes ax:
|
:param matplotlib.Axes ax:
|
||||||
|
@ -117,7 +123,7 @@ def stackplot(ax, x_signal, y_signals):
|
||||||
:param dict(str,numpy.array) y_signals:
|
:param dict(str,numpy.array) y_signals:
|
||||||
"""
|
"""
|
||||||
if 'stackplot' in dir(ax):
|
if 'stackplot' in dir(ax):
|
||||||
ax.stackplot(x_signal, list(y_signals.values()) )
|
ax.stackplot(x_signal, list(y_signals.values()))
|
||||||
plt.legend(list(y_signals.keys()))
|
plt.legend(list(y_signals.keys()))
|
||||||
else:
|
else:
|
||||||
# emulating missing Axes.stackplot method
|
# emulating missing Axes.stackplot method
|
||||||
|
@ -130,12 +136,13 @@ def stackplot(ax, x_signal, y_signals):
|
||||||
if series_index == 0:
|
if series_index == 0:
|
||||||
from_signal = 0
|
from_signal = 0
|
||||||
else:
|
else:
|
||||||
from_signal = y_stack[series_index-1,:]
|
from_signal = y_stack[series_index - 1, :]
|
||||||
ax.fill_between(x_signal, from_signal, y_stack[series_index,:], color=colors[series_index], lw=0.0)
|
ax.fill_between(x_signal, from_signal, y_stack[series_index, :], color=colors[series_index], lw=0.0)
|
||||||
p = plt.Rectangle((0, 0), 0, 0, color=colors[series_index])
|
p = plt.Rectangle((0, 0), 0, 0, color=colors[series_index])
|
||||||
ax.add_patch(p)
|
ax.add_patch(p)
|
||||||
plt.legend(list(y_signals.keys()))
|
plt.legend(list(y_signals.keys()))
|
||||||
|
|
||||||
|
|
||||||
def draw_cluster_value_over_time_graph(inventory, from_date, to_date, graph_type):
|
def draw_cluster_value_over_time_graph(inventory, from_date, to_date, graph_type):
|
||||||
time_value = matplotlib.dates.drange(dstart=from_date, dend=to_date, delta=datetime.timedelta(days=1))
|
time_value = matplotlib.dates.drange(dstart=from_date, dend=to_date, delta=datetime.timedelta(days=1))
|
||||||
flops_price_over_time = get_flops_price_over_time(inventory, time_value)
|
flops_price_over_time = get_flops_price_over_time(inventory, time_value)
|
||||||
|
@ -144,7 +151,7 @@ def draw_cluster_value_over_time_graph(inventory, from_date, to_date, graph_type
|
||||||
rows = inventory.query("SELECT * FROM machines")
|
rows = inventory.query("SELECT * FROM machines")
|
||||||
|
|
||||||
for row in rows:
|
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
|
(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)
|
is_cluster_node = is_cluster_node_name(name)
|
||||||
if is_cluster_node:
|
if is_cluster_node:
|
||||||
purchase_date = inventory.get_machine_purchase_date(name)
|
purchase_date = inventory.get_machine_purchase_date(name)
|
||||||
|
@ -152,9 +159,9 @@ def draw_cluster_value_over_time_graph(inventory, from_date, to_date, graph_type
|
||||||
# print(name, price_ex_vat)
|
# print(name, price_ex_vat)
|
||||||
purchase_time = matplotlib.dates.date2num(purchase_date.date())
|
purchase_time = matplotlib.dates.date2num(purchase_date.date())
|
||||||
item_value_over_time = {
|
item_value_over_time = {
|
||||||
'cluster_cost_over_time':get_investment_over_time(time_value, price_ex_vat, purchase_time),
|
'cluster_cost_over_time': get_investment_over_time(time_value, price_ex_vat, purchase_time),
|
||||||
'cluster_value_over_time':get_computer_value_over_time(inventory, name, time_value, flops_price_over_time, purchase_time),
|
'cluster_value_over_time': get_computer_value_over_time(inventory, name, time_value, flops_price_over_time, purchase_time),
|
||||||
'cluster_dp_gflops_over_time':get_flops_over_time(inventory, time_value, name, purchase_time)}[graph_type]
|
'cluster_dp_gflops_over_time': get_flops_over_time(inventory, time_value, name, purchase_time)}[graph_type]
|
||||||
for ownership in inventory.get_item_ownership(name):
|
for ownership in inventory.get_item_ownership(name):
|
||||||
# print(ownership)
|
# print(ownership)
|
||||||
# print(ownership['owner'], ownership['owner_ratio'])
|
# print(ownership['owner'], ownership['owner_ratio'])
|
||||||
|
@ -175,16 +182,16 @@ def draw_cluster_value_over_time_graph(inventory, from_date, to_date, graph_type
|
||||||
|
|
||||||
fig, ax = plt.subplots()
|
fig, ax = plt.subplots()
|
||||||
ax.set_title(graph_type)
|
ax.set_title(graph_type)
|
||||||
#for dept, cluster_value_for_dept in cluster_value.iteritems():
|
# for dept, cluster_value_for_dept in cluster_value.iteritems():
|
||||||
# ax.plot(time_value, cluster_value_for_dept)
|
# ax.plot(time_value, cluster_value_for_dept)
|
||||||
|
|
||||||
stackplot( ax, time_value, cluster_value)
|
stackplot(ax, time_value, cluster_value)
|
||||||
|
|
||||||
plt.xlabel('time')
|
plt.xlabel('time')
|
||||||
plt.ylabel(
|
plt.ylabel({
|
||||||
{'cluster_cost_over_time':u'cluster investment (€)',
|
'cluster_cost_over_time': u'cluster investment (€)',
|
||||||
'cluster_value_over_time':u'cluster value (€)',
|
'cluster_value_over_time': u'cluster value (€)',
|
||||||
'cluster_dp_gflops_over_time':u'double prec gflops'}[graph_type])
|
'cluster_dp_gflops_over_time': u'double prec gflops'}[graph_type])
|
||||||
|
|
||||||
years = matplotlib.dates.YearLocator() # every year
|
years = matplotlib.dates.YearLocator() # every year
|
||||||
months = matplotlib.dates.MonthLocator() # every month
|
months = matplotlib.dates.MonthLocator() # every month
|
||||||
|
@ -204,10 +211,11 @@ def draw_cluster_value_over_time_graph(inventory, from_date, to_date, graph_type
|
||||||
# fig.autofmt_xdate()
|
# fig.autofmt_xdate()
|
||||||
ax.grid(True)
|
ax.grid(True)
|
||||||
|
|
||||||
#plt.plot()
|
# plt.plot()
|
||||||
# plt.plot(X,S)
|
# plt.plot(X,S)
|
||||||
return fig
|
return fig
|
||||||
|
|
||||||
|
|
||||||
def draw_dp_gflops_price_over_time_over_time_graph(inventory, from_date, to_date):
|
def draw_dp_gflops_price_over_time_over_time_graph(inventory, from_date, to_date):
|
||||||
"""
|
"""
|
||||||
:param Inventory inventory: the inventory database
|
:param Inventory inventory: the inventory database
|
||||||
|
@ -235,6 +243,7 @@ def draw_dp_gflops_price_over_time_over_time_graph(inventory, from_date, to_date
|
||||||
ax.grid(True)
|
ax.grid(True)
|
||||||
return fig
|
return fig
|
||||||
|
|
||||||
|
|
||||||
def draw_age_pyramid_graph(inventory):
|
def draw_age_pyramid_graph(inventory):
|
||||||
"""
|
"""
|
||||||
:param Inventory inventory: the inventory database
|
:param Inventory inventory: the inventory database
|
||||||
|
@ -246,12 +255,12 @@ def draw_age_pyramid_graph(inventory):
|
||||||
rows = inventory.query("SELECT * FROM machines")
|
rows = inventory.query("SELECT * FROM machines")
|
||||||
|
|
||||||
for row in rows:
|
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
|
(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)
|
is_cluster_node = is_cluster_node_name(name)
|
||||||
if is_cluster_node:
|
if is_cluster_node:
|
||||||
purchase_date = inventory.get_machine_purchase_date(name)
|
purchase_date = inventory.get_machine_purchase_date(name)
|
||||||
if purchase_date is not None:
|
if purchase_date is not None:
|
||||||
purchase_time = matplotlib.dates.date2num(purchase_date.date())
|
purchase_time = matplotlib.dates.date2num(purchase_date.date()) # noqa: F841
|
||||||
age = datetime.datetime.now() - purchase_date
|
age = datetime.datetime.now() - purchase_date
|
||||||
age_histogram[age.days / 365] += 1
|
age_histogram[age.days / 365] += 1
|
||||||
# print(name, age)
|
# print(name, age)
|
||||||
|
@ -288,6 +297,7 @@ class IFigureHandler(object):
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ScreenFigureHandler(IFigureHandler):
|
class ScreenFigureHandler(IFigureHandler):
|
||||||
"""
|
"""
|
||||||
displays figures on screen
|
displays figures on screen
|
||||||
|
@ -301,12 +311,11 @@ class ScreenFigureHandler(IFigureHandler):
|
||||||
def on_finalize(self):
|
def on_finalize(self):
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
class SvgFigureHandler(IFigureHandler):
|
class SvgFigureHandler(IFigureHandler):
|
||||||
"""
|
"""
|
||||||
saves figures as svg files
|
saves figures as svg files
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def __init__(self, out_svg_dir_path):
|
def __init__(self, out_svg_dir_path):
|
||||||
"""
|
"""
|
||||||
|
@ -320,6 +329,7 @@ class SvgFigureHandler(IFigureHandler):
|
||||||
def on_finalize(self):
|
def on_finalize(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def draw_graphs(inventory, from_time, to_time, figure_handler):
|
def draw_graphs(inventory, from_time, to_time, figure_handler):
|
||||||
"""
|
"""
|
||||||
:param Inventory inventory: the inventory database
|
:param Inventory inventory: the inventory database
|
||||||
|
|
Loading…
Reference in New Issue