X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fad_model.py;h=14c4dcfbab72587417a1cba27f61c8eef9a0b4d1;hb=refs%2Fchanges%2F79%2F12279%2F2;hp=617fc9f2355a783e9054beae73c2c5f38e11421a;hpb=77f7c38a2133e3ca11582a217762802d1a14c8fa;p=ric-app%2Fad.git diff --git a/src/ad_model.py b/src/ad_model.py index 617fc9f..14c4dcf 100644 --- a/src/ad_model.py +++ b/src/ad_model.py @@ -91,7 +91,7 @@ class CAUSE(object): def __init__(self): self.normal = None - def cause(self, df, db): + def cause(self, df, db, threshold): """ Filter normal data for a particular ue-id to compare with a given sample Compare with normal data to find and return degradaton type """ @@ -99,23 +99,25 @@ class CAUSE(object): sample.index = range(len(sample)) for i in range(len(sample)): if sample.iloc[i]['Anomaly'] == 1: - query = 'select * from {} where {} = \'{}\' and timenow()-20s'.format(db.meas, db.ue, sample.iloc[i][db.ue]) + query = """select * from {} where "{}" = \'{}\' and timenow()-20s""".format(db.meas, db.ue, sample.iloc[i][db.ue]) normal = db.query(query) if normal: normal = normal[db.meas][[db.thpt, db.rsrp, db.rsrq]] - deg = self.find(sample.loc[i, :], normal.max(), db) + deg = self.find(sample.loc[i, :], normal.max(), db, threshold) if deg: sample.loc[i, 'Degradation'] = deg if 'Throughput' in deg and ('RSRP' in deg or 'RSRQ' in deg): sample.loc[i, 'Anomaly'] = 2 + else: + sample.loc[i, 'Anomaly'] = 1 else: sample.loc[i, 'Anomaly'] = 0 return sample[['Anomaly', 'Degradation']].values.tolist() - def find(self, row, l, db): + def find(self, row, l, db, threshold): """ store if a particular parameter is below threshold and return """ deg = [] - if row[db.thpt] < l[db.thpt]*0.5: + if row[db.thpt] < l[db.thpt]*(100 - threshold)*0.01: deg.append('Throughput') if row[db.rsrp] < l[db.rsrp]-15: deg.append('RSRP')