Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Factory:
- def __init__(self, unit_type, exp_grade=None):
- self.exp_grade = exp_grade
- self.unit_type = unit_type
- def create_unit(self, unit_name='default_name'):
- func_nodes = []
- unit_data = pd.read_csv('data/{}.csv'.format(self.unit_type), delimiter=';')
- for node in unit_data.values:
- node_type = node[0]
- node_weight = node[1]
- func_nodes.append(self.create_func_node(node_type, node_weight))
- return EquipmentUnit(unit_name, self.unit_type, func_nodes)
- def create_func_node(self, node_type, node_weight):
- param_groups = []
- node_data = pd.read_csv('data/{0}/{1}.csv'.format(self.unit_type, node_type), delimiter=';')
- for group in node_data.values:
- group_type = group[0]
- group_weight = group[1]
- param_groups.append(self.create_param_group(group_type, group_weight, node_type))
- return FunctionalNode(node_type, param_groups, node_weight)
- def create_param_group(self, group_type, group_weight, node_type):
- params = pd.DataFrame()
- group_data = pd.read_csv('data/{0}/{1}/{2}.csv'.format(self.unit_type, node_type, group_type),\
- delimiter=';')
- for param in group_data.values:
- cols = ['name', 'grade']
- params = pd.DataFrame(columns=cols)
- if self.exp_grade != None:
- param[1] = self.rand_grade()
- params = params.append(pd.DataFrame([[param[0], param[1]]],columns=cols))
- return ParamGroup(group_type, group_weight, params)
- def rand_grade(self):
- grade = round(np.random.normal(self.exp_grade, 1, 1)[0])
- if grade > 4:
- grade = 4
- if grade < 0:
- grade = 0
- return grade
- class EquipmentUnit:
- def __init__(self, unit_name, unit_type, func_nodes):
- self.unit_name = unit_name
- self.unit_type = unit_type
- self.func_nodes = func_nodes
- def __repr__(self):
- return '{0}.{1}'.format(self.unit_name, self.unit_type)
- def __str__(self):
- string = 'Unit name: {0}\nUnit type: {1}\nUnit consist of nodes:{2}'\
- .format(self.unit_name, self.unit_type, [x.node_type for x in self.func_nodes])
- return string
- def get_unit_itc(self):
- unit_itc = sum([x.node_weight*x.get_node_itc() for x in self.func_nodes])
- return unit_itc
- class FunctionalNode:
- def __init__(self, node_type, param_groups, node_weight):
- self.node_type = node_type
- self.param_groups = param_groups
- self.node_weight = node_weight
- def __repr__(self):
- return self.node_type
- def __str__(self):
- string = 'Node type: {0}\nNode weight: {1}\nNode consist of groups:{2}'\
- .format(self.node_type, self.node_weight, [x.group_type for x in self.param_groups])
- return string
- def get_node_itc(self):
- node_itc = 100*sum([x.group_weight*x.grade() for x in self.param_groups])/4
- return node_itc
- class ParamGroup:
- def __init__(self, group_type, group_weight, params):
- self.group_type = group_type
- self.group_weight = group_weight
- self.params = params
- def __repr__(self):
- return self.group_type
- def __str__(self):
- string = 'Group type: {0}\nGroup weight: {1}\nGroup grade: {2}'\
- .format(self.group_type, self.group_weight, self.grade())
- return string
- def grade(self):
- return self.params['grade'].min()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement