1 # -------------------------------------------------------------------------
2 # Copyright (C) 2020 Wipro Limited.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # -------------------------------------------------------------------------
21 from osdf.adapters.dcae import des
22 from osdf.adapters.dcae.des import DESException
23 from osdf.config.base import osdf_config
24 from osdf.logging.osdf_logging import error_log
27 class MlModel(object):
29 self.config = osdf_config.core['PCI']
31 def get_additional_inputs(self, dzn_data, network_cell_info):
32 """Add/update additional info to the existing models.
34 The method returns nothing. Instead, it modifies the dzn_data
35 :params: dzn_data: map with data for the optimization
37 self.compute_ml_model(dzn_data, network_cell_info)
39 def compute_ml_model(self, dzn_data, network_cell_info):
40 average_ho_threshold = self.config['ML']['average_ho_threshold']
41 latest_ho_threshold = self.config['ML']['latest_ho_threshold']
44 for cell in network_cell_info['cell_list']:
45 cell_id = cell['cell_id']
46 average_ho, latest_ho = self.get_ho_details(cell['cell_id'])
47 if average_ho > average_ho_threshold or latest_ho > latest_ho_threshold:
48 fixed_cells.add(cell_id)
50 fixed_cells.update(dzn_data.get('PCI_UNCHANGEABLE_CELLS', []))
51 dzn_data['PCI_UNCHANGEABLE_CELLS'] = fixed_cells
53 def get_ho_details(self, cell_id):
54 service_id = self.config['DES']['service_id']
55 request_data = self.config['DES']['filter']
56 request_data['cell_id'] = cell_id
58 result = des.extract_data(service_id, json.dumps(request_data))
59 except DESException as e:
60 error_log.error("Error while calling DES {}".format(e))
67 for pm_data in result:
68 ho = pm_data['overallHoAtt']
71 return sum(ho_list) / len(ho_list), ho_list[0]