reformatted code to pep8 convention
This commit is contained in:
parent
e9f3c5a784
commit
796ec2d6a5
76
inventory.py
76
inventory.py
|
@ -1,15 +1,11 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from SimpaDbUtil import SqlDatabaseReader, SqlFile
|
|
||||||
|
|
||||||
class Inventory( object ):
|
class Inventory(object):
|
||||||
def __init__(self, sql_reader):
|
def __init__(self, sql_reader):
|
||||||
"""
|
"""
|
||||||
:param SqlDatabaseReader sql_reader: the inventory database
|
:param SimpaDbUtil.SqlDatabaseReader sql_reader: the inventory database
|
||||||
"""
|
"""
|
||||||
super(Inventory, self).__init__()
|
super(Inventory, self).__init__()
|
||||||
self._sql_reader = sql_reader
|
self._sql_reader = sql_reader
|
||||||
|
@ -21,30 +17,34 @@ class Inventory( object ):
|
||||||
'''
|
'''
|
||||||
returns the serial number of the given machine
|
returns the serial number of the given machine
|
||||||
'''
|
'''
|
||||||
machine_serial_number = self._sql_reader.get_table_attr( 'machines', 'name', machine_name, 'serial_number' )
|
machine_serial_number = self._sql_reader.get_table_attr('machines', 'name', machine_name, 'serial_number')
|
||||||
return machine_serial_number
|
return machine_serial_number
|
||||||
|
|
||||||
def get_machine_name(self, machine_serial_number):
|
def get_machine_name(self, machine_serial_number):
|
||||||
'''
|
'''
|
||||||
returns the user-friendly name of the given machine
|
returns the user-friendly name of the given machine
|
||||||
'''
|
'''
|
||||||
machine_name = self._sql_reader.get_table_attr( 'machines', 'serial_number', machine_serial_number, 'name' )
|
machine_name = self._sql_reader.get_table_attr('machines', 'serial_number', machine_serial_number, 'name')
|
||||||
return machine_name
|
return machine_name
|
||||||
|
|
||||||
def machine_name_to_machine_spec_id(self, machine_name ):
|
def machine_name_to_machine_spec_id(self, machine_name):
|
||||||
machine_spec_id = self._sql_reader.get_table_attr( 'machines', 'name', machine_name, 'machine_spec_id' )
|
# machine_spec_id = None
|
||||||
|
# try:
|
||||||
|
machine_spec_id = self._sql_reader.get_table_attr('machines', 'name', machine_name, 'machine_spec_id')
|
||||||
|
# except:
|
||||||
|
# machine_spec_id = None
|
||||||
return machine_spec_id
|
return machine_spec_id
|
||||||
|
|
||||||
# electricity related methods
|
# electricity related methods
|
||||||
|
|
||||||
def machine_spec_id_to_power_consumption(self, machine_spec_id ):
|
def machine_spec_id_to_power_consumption(self, machine_spec_id):
|
||||||
power_consumption = self._sql_reader.get_table_attr( 'machine_spec_to_power_consumption', 'machine_spec_id', machine_spec_id, 'power_consumption' )
|
power_consumption = self._sql_reader.get_table_attr('machine_spec_to_power_consumption', 'machine_spec_id', machine_spec_id, 'power_consumption')
|
||||||
return power_consumption
|
return power_consumption
|
||||||
|
|
||||||
def get_plug_type_attr(self, plug_type, attr_name):
|
def get_plug_type_attr(self, plug_type, attr_name):
|
||||||
# INSERT INTO `powerplug_type_desc` (`plug_type_id`, `genre`, `max_amps`) VALUES
|
# INSERT INTO `powerplug_type_desc` (`plug_type_id`, `genre`, `max_amps`) VALUES
|
||||||
# ('iec60309_blue_pne6h_32a_m', 'm', 32.0),
|
# ('iec60309_blue_pne6h_32a_m', 'm', 32.0),
|
||||||
attr_value = self._sql_reader.get_table_attr('powerplug_type_desc', 'plug_type_id', plug_type, attr_name )
|
attr_value = self._sql_reader.get_table_attr('powerplug_type_desc', 'plug_type_id', plug_type, attr_name)
|
||||||
return attr_value
|
return attr_value
|
||||||
|
|
||||||
def read_plug_capacity(self, plug):
|
def read_plug_capacity(self, plug):
|
||||||
|
@ -59,7 +59,7 @@ class Inventory( object ):
|
||||||
# print('plug_type : %s' % plug_type)
|
# print('plug_type : %s' % plug_type)
|
||||||
|
|
||||||
plug_capacity = self.get_plug_type_attr(plug_type, 'max_amps')
|
plug_capacity = self.get_plug_type_attr(plug_type, 'max_amps')
|
||||||
#if plug_capacity:
|
# if plug_capacity:
|
||||||
# print('plug_capacity : %f A' % plug_capacity)
|
# print('plug_capacity : %f A' % plug_capacity)
|
||||||
# print("read_plug_capacity : plug capacity for plug.machine.name="+plug.machine.name+" plug="+str(plug)+" : "+ str(plug_capacity)+ "A")
|
# print("read_plug_capacity : plug capacity for plug.machine.name="+plug.machine.name+" plug="+str(plug)+" : "+ str(plug_capacity)+ "A")
|
||||||
return plug_capacity
|
return plug_capacity
|
||||||
|
@ -67,13 +67,13 @@ class Inventory( object ):
|
||||||
# cluster related methods
|
# cluster related methods
|
||||||
|
|
||||||
def get_machine_purchase_date(self, machine_id):
|
def get_machine_purchase_date(self, machine_id):
|
||||||
ordering_id = self._sql_reader.get_table_attr( 'machines', 'name', machine_id, 'command_id' )
|
ordering_id = self._sql_reader.get_table_attr('machines', 'name', machine_id, 'command_id')
|
||||||
# print(ordering_id)
|
# print(ordering_id)
|
||||||
# handle case of multiple orders
|
# handle case of multiple orders
|
||||||
ordering_id = ordering_id.split('+')[0]
|
ordering_id = ordering_id.split('+')[0]
|
||||||
if len(ordering_id) == 0:
|
if len(ordering_id) == 0:
|
||||||
return None
|
return None
|
||||||
ordering_date_as_str = self._sql_reader.get_table_attr( 'orderings', 'ordering_id', ordering_id, 'ordering_date' )
|
ordering_date_as_str = self._sql_reader.get_table_attr('orderings', 'ordering_id', ordering_id, 'ordering_date')
|
||||||
if ordering_date_as_str is None:
|
if ordering_date_as_str is None:
|
||||||
return None
|
return None
|
||||||
if len(ordering_date_as_str) == 0:
|
if len(ordering_date_as_str) == 0:
|
||||||
|
@ -81,34 +81,33 @@ class Inventory( object ):
|
||||||
ordering_date = datetime.datetime.strptime(ordering_date_as_str, '%d/%m/%Y')
|
ordering_date = datetime.datetime.strptime(ordering_date_as_str, '%d/%m/%Y')
|
||||||
return ordering_date
|
return ordering_date
|
||||||
|
|
||||||
|
|
||||||
def get_cpu_dflops(self, cpu_model):
|
def get_cpu_dflops(self, cpu_model):
|
||||||
'''
|
'''
|
||||||
returns the number of double precision operation per second this cpu can achieve
|
returns the number of double precision operation per second this cpu can achieve
|
||||||
'''
|
'''
|
||||||
#INSERT INTO `cpu_specs` (`cpu_model`, `num_cores`, `clock_speed`, `dflops_per_core_per_cycle`, `comment`) VALUES
|
# INSERT INTO `cpu_specs` (`cpu_model`, `num_cores`, `clock_speed`, `dflops_per_core_per_cycle`, `comment`) VALUES
|
||||||
#('intel_xeon_x5550', 4, 2.67, 4, ''),
|
# ('intel_xeon_x5550', 4, 2.67, 4, ''),
|
||||||
num_cores = int(self._sql_reader.get_table_attr( 'cpu_specs', 'cpu_model', cpu_model, 'num_cores' ))
|
num_cores = int(self._sql_reader.get_table_attr('cpu_specs', 'cpu_model', cpu_model, 'num_cores'))
|
||||||
clock_speed = float(self._sql_reader.get_table_attr( 'cpu_specs', 'cpu_model', cpu_model, 'clock_speed' )) * 1.e9
|
clock_speed = float(self._sql_reader.get_table_attr('cpu_specs', 'cpu_model', cpu_model, 'clock_speed')) * 1.e9
|
||||||
dflops_per_core_per_cycle = int(self._sql_reader.get_table_attr('cpu_specs', 'cpu_model', cpu_model, 'dflops_per_core_per_cycle' ))
|
dflops_per_core_per_cycle = int(self._sql_reader.get_table_attr('cpu_specs', 'cpu_model', cpu_model, 'dflops_per_core_per_cycle'))
|
||||||
# print(num_cores, clock_speed, dflops_per_core_per_cycle)
|
# print(num_cores, clock_speed, dflops_per_core_per_cycle)
|
||||||
return clock_speed * dflops_per_core_per_cycle * num_cores
|
return clock_speed * dflops_per_core_per_cycle * num_cores
|
||||||
|
|
||||||
def get_num_cpus(self, computer_name):
|
def get_num_cpus(self, computer_name):
|
||||||
return int(self._sql_reader.get_table_attr( 'computer_to_cpu', 'computer_id', computer_name, 'num_cpu' ))
|
return int(self._sql_reader.get_table_attr('computer_to_cpu', 'computer_id', computer_name, 'num_cpu'))
|
||||||
|
|
||||||
def get_cpu_model(self, computer_name):
|
def get_cpu_model(self, computer_name):
|
||||||
return self._sql_reader.get_table_attr( 'computer_to_cpu', 'computer_id', computer_name, 'cpu_model' )
|
return self._sql_reader.get_table_attr('computer_to_cpu', 'computer_id', computer_name, 'cpu_model')
|
||||||
|
|
||||||
def get_cpu_frequency(self, computer_name):
|
def get_cpu_frequency(self, computer_name):
|
||||||
cpu_model = self._sql_reader.get_table_attr( 'computer_to_cpu', 'computer_id', computer_name, 'cpu_model' )
|
cpu_model = self._sql_reader.get_table_attr('computer_to_cpu', 'computer_id', computer_name, 'cpu_model')
|
||||||
return float(self._sql_reader.get_table_attr( 'cpu_specs', 'cpu_model', cpu_model, 'clock_speed' ))
|
return float(self._sql_reader.get_table_attr('cpu_specs', 'cpu_model', cpu_model, 'clock_speed'))
|
||||||
|
|
||||||
def get_computer_dflops(self, computer_name):
|
def get_computer_dflops(self, computer_name):
|
||||||
# print(computer_serial_number)
|
# print(computer_serial_number)
|
||||||
num_cpus = int(self._sql_reader.get_table_attr( 'computer_to_cpu', 'computer_id', computer_name, 'num_cpu' ))
|
num_cpus = int(self._sql_reader.get_table_attr( 'computer_to_cpu', 'computer_id', computer_name, 'num_cpu'))
|
||||||
cpu_model = self._sql_reader.get_table_attr( 'computer_to_cpu', 'computer_id', computer_name, 'cpu_model' )
|
cpu_model = self._sql_reader.get_table_attr('computer_to_cpu', 'computer_id', computer_name, 'cpu_model')
|
||||||
flops = num_cpus * self.get_cpu_dflops( cpu_model )
|
flops = num_cpus * self.get_cpu_dflops(cpu_model)
|
||||||
return flops
|
return flops
|
||||||
|
|
||||||
def get_computer_options_price(self, computer_name):
|
def get_computer_options_price(self, computer_name):
|
||||||
|
@ -133,8 +132,8 @@ class Inventory( object ):
|
||||||
:param str item_id: the identifier of an inventory item (a machine (eg simpa-switch002), a group of machines (ceph), etc.)
|
:param str item_id: the identifier of an inventory item (a machine (eg simpa-switch002), a group of machines (ceph), etc.)
|
||||||
:return float: the price of the item exluding taxes
|
:return float: the price of the item exluding taxes
|
||||||
"""
|
"""
|
||||||
item_price = self._sql_reader.get_table_attr( 'machines', 'name', item_id, 'price_ex_vat' )
|
item_price = self._sql_reader.get_table_attr('machines', 'name', item_id, 'price_ex_vat')
|
||||||
if item_price == None:
|
if item_price is None:
|
||||||
item_price = 0.0
|
item_price = 0.0
|
||||||
else:
|
else:
|
||||||
item_price = float(item_price)
|
item_price = float(item_price)
|
||||||
|
@ -151,25 +150,24 @@ class Inventory( object ):
|
||||||
for row in rows:
|
for row in rows:
|
||||||
part_id = row[0]
|
part_id = row[0]
|
||||||
item_price += self.get_item_price(part_id, include_contents, include_maintenance)
|
item_price += self.get_item_price(part_id, include_contents, include_maintenance)
|
||||||
#print(u'price of %s : %.2f € HT' % (item_id, item_price))
|
# print(u'price of %s : %.2f € HT' % (item_id, item_price))
|
||||||
return item_price
|
return item_price
|
||||||
|
|
||||||
def get_item_ownership(self, item_id):
|
def get_item_ownership(self, item_id):
|
||||||
ownership=[]
|
ownership = []
|
||||||
|
|
||||||
rows = self._sql_reader.query("SELECT * FROM ownership WHERE machine_id='%s'" % item_id)
|
rows = self._sql_reader.query("SELECT * FROM ownership WHERE machine_id='%s'" % item_id)
|
||||||
for row in rows:
|
for row in rows:
|
||||||
(machine_id, owner, owner_ratio, comment)=row
|
(machine_id, owner, owner_ratio, comment) = row # @UnusedVariable
|
||||||
ownership.append({'owner':owner, 'owner_ratio':owner_ratio})
|
ownership.append({'owner': owner, 'owner_ratio': owner_ratio})
|
||||||
return ownership
|
return ownership
|
||||||
|
|
||||||
def get_item_use(self, item_id):
|
def get_item_use(self, item_id):
|
||||||
ownership=[]
|
ownership = []
|
||||||
|
|
||||||
rows = self._sql_reader.query("SELECT * FROM machine_users")
|
rows = self._sql_reader.query("SELECT * FROM machine_users")
|
||||||
for row in rows:
|
for row in rows:
|
||||||
(machine_id, user, user_ratio, comment)=row
|
(machine_id, user, user_ratio, comment) = row # @UnusedVariable
|
||||||
if machine_id == item_id:
|
if machine_id == item_id:
|
||||||
ownership.append({'user':user, 'user_ratio':user_ratio})
|
ownership.append({'user': user, 'user_ratio': user_ratio})
|
||||||
return ownership
|
return ownership
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue