Skip to content

Commit

Permalink
Merge pull request #73 from redBorder/fix_issue_shallow_outliers_fail…
Browse files Browse the repository at this point in the history
…s_to_initialize

PR-62: Fix issue shallow outliers fails to initialize
  • Loading branch information
malvads authored Jun 7, 2024
2 parents c6279d8 + 458f6ab commit 039738b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions resources/src/ai/shallow_outliers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def __init__(self, sensitivity=0.95, contamination=0.01):
contamination (float, optional): A value between 0 and 1 that indicates the proportion of data points
to be considered anomalous during training. Default is 0.01.
"""
self.sens = sensitivity
self.cont = contamination
self.sens = float(sensitivity)
self.cont = float(contamination)


def predict(self, arr):
Expand Down
1 change: 1 addition & 0 deletions resources/tests/shallow_outliers_test_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"timestamp":"2024-05-22T10:00:00.000Z","result":{"bytes":1135538070}},{"timestamp":"2024-05-22T11:00:00.000Z","result":{"bytes":1294354228}},{"timestamp":"2024-05-22T12:00:00.000Z","result":{"bytes":272646382}},{"timestamp":"2024-05-22T13:00:00.000Z","result":{"bytes":602438212}},{"timestamp":"2024-05-22T14:00:00.000Z","result":{"bytes":1770232950}},{"timestamp":"2024-05-22T15:00:00.000Z","result":{"bytes":1430389764}},{"timestamp":"2024-05-22T16:00:00.000Z","result":{"bytes":79205229}},{"timestamp":"2024-05-22T17:00:00.000Z","result":{"bytes":146031984}},{"timestamp":"2024-05-22T18:00:00.000Z","result":{"bytes":225462515}},{"timestamp":"2024-05-22T19:00:00.000Z","result":{"bytes":6614869}},{"timestamp":"2024-05-22T20:00:00.000Z","result":{"bytes":12615122}},{"timestamp":"2024-05-22T21:00:00.000Z","result":{"bytes":403}},{"timestamp":"2024-05-22T22:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-22T23:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-23T00:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-23T01:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-23T02:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-23T03:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-23T04:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-23T05:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-23T06:00:00.000Z","result":{"bytes":406161}},{"timestamp":"2024-05-23T07:00:00.000Z","result":{"bytes":753567132}},{"timestamp":"2024-05-23T08:00:00.000Z","result":{"bytes":1782636431}},{"timestamp":"2024-05-23T09:00:00.000Z","result":{"bytes":450057013}},{"timestamp":"2024-05-23T10:00:00.000Z","result":{"bytes":564580710}},{"timestamp":"2024-05-23T11:00:00.000Z","result":{"bytes":328633748}},{"timestamp":"2024-05-23T12:00:00.000Z","result":{"bytes":350053980}},{"timestamp":"2024-05-23T13:00:00.000Z","result":{"bytes":220354810}},{"timestamp":"2024-05-23T14:00:00.000Z","result":{"bytes":460105618}},{"timestamp":"2024-05-23T15:00:00.000Z","result":{"bytes":193893468}},{"timestamp":"2024-05-23T16:00:00.000Z","result":{"bytes":56125025}},{"timestamp":"2024-05-23T17:00:00.000Z","result":{"bytes":4673655}},{"timestamp":"2024-05-23T18:00:00.000Z","result":{"bytes":23768884}},{"timestamp":"2024-05-23T19:00:00.000Z","result":{"bytes":66722458}},{"timestamp":"2024-05-23T20:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-23T21:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-23T22:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-23T23:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-24T00:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-24T01:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-24T02:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-24T03:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-24T04:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-24T05:00:00.000Z","result":{"bytes":134985449}},{"timestamp":"2024-05-24T06:00:00.000Z","result":{"bytes":677764}},{"timestamp":"2024-05-24T07:00:00.000Z","result":{"bytes":908801655}},{"timestamp":"2024-05-24T08:00:00.000Z","result":{"bytes":131336254}},{"timestamp":"2024-05-24T09:00:00.000Z","result":{"bytes":147977277}},{"timestamp":"2024-05-24T10:00:00.000Z","result":{"bytes":245402019}},{"timestamp":"2024-05-24T11:00:00.000Z","result":{"bytes":217988557}},{"timestamp":"2024-05-24T12:00:00.000Z","result":{"bytes":290310956}},{"timestamp":"2024-05-24T13:00:00.000Z","result":{"bytes":129299756}},{"timestamp":"2024-05-24T14:00:00.000Z","result":{"bytes":435848065}},{"timestamp":"2024-05-24T15:00:00.000Z","result":{"bytes":259763331}},{"timestamp":"2024-05-24T16:00:00.000Z","result":{"bytes":156017817}},{"timestamp":"2024-05-24T17:00:00.000Z","result":{"bytes":431267}},{"timestamp":"2024-05-25T06:00:00.000Z","result":{"bytes":33192936}},{"timestamp":"2024-05-25T07:00:00.000Z","result":{"bytes":73926125}},{"timestamp":"2024-05-25T15:00:00.000Z","result":{"bytes":688210}},{"timestamp":"2024-05-25T16:00:00.000Z","result":{"bytes":18398887}},{"timestamp":"2024-05-25T17:00:00.000Z","result":{"bytes":53452243}},{"timestamp":"2024-05-25T18:00:00.000Z","result":{"bytes":116237}},{"timestamp":"2024-05-25T19:00:00.000Z","result":{"bytes":33364199}},{"timestamp":"2024-05-25T20:00:00.000Z","result":{"bytes":707624}},{"timestamp":"2024-05-25T21:00:00.000Z","result":{"bytes":767681}},{"timestamp":"2024-05-25T22:00:00.000Z","result":{"bytes":92149}},{"timestamp":"2024-05-26T05:00:00.000Z","result":{"bytes":6915554}},{"timestamp":"2024-05-26T06:00:00.000Z","result":{"bytes":171564}},{"timestamp":"2024-05-27T01:00:00.000Z","result":{"bytes":51726781}},{"timestamp":"2024-05-27T06:00:00.000Z","result":{"bytes":241872}},{"timestamp":"2024-05-27T07:00:00.000Z","result":{"bytes":825923094}},{"timestamp":"2024-05-27T08:00:00.000Z","result":{"bytes":1147693084}},{"timestamp":"2024-05-27T09:00:00.000Z","result":{"bytes":264316849}},{"timestamp":"2024-05-27T10:00:00.000Z","result":{"bytes":1029209926}},{"timestamp":"2024-05-27T11:00:00.000Z","result":{"bytes":514029046}},{"timestamp":"2024-05-27T12:00:00.000Z","result":{"bytes":994488955}},{"timestamp":"2024-05-27T13:00:00.000Z","result":{"bytes":1051564307}},{"timestamp":"2024-05-27T14:00:00.000Z","result":{"bytes":541599643}},{"timestamp":"2024-05-27T15:00:00.000Z","result":{"bytes":130694151}},{"timestamp":"2024-05-27T16:00:00.000Z","result":{"bytes":149863332}},{"timestamp":"2024-05-27T17:00:00.000Z","result":{"bytes":51198086}},{"timestamp":"2024-05-27T18:00:00.000Z","result":{"bytes":7450614}},{"timestamp":"2024-05-27T19:00:00.000Z","result":{"bytes":8097203}},{"timestamp":"2024-05-27T20:00:00.000Z","result":{"bytes":3308571}},{"timestamp":"2024-05-27T21:00:00.000Z","result":{"bytes":1078158}},{"timestamp":"2024-05-27T22:00:00.000Z","result":{"bytes":843244}},{"timestamp":"2024-05-27T23:00:00.000Z","result":{"bytes":526008}},{"timestamp":"2024-05-28T00:00:00.000Z","result":{"bytes":551364}},{"timestamp":"2024-05-28T01:00:00.000Z","result":{"bytes":3168300}},{"timestamp":"2024-05-28T02:00:00.000Z","result":{"bytes":2305888}},{"timestamp":"2024-05-28T03:00:00.000Z","result":{"bytes":12938072}},{"timestamp":"2024-05-28T04:00:00.000Z","result":{"bytes":1368297}},{"timestamp":"2024-05-28T05:00:00.000Z","result":{"bytes":2005367}},{"timestamp":"2024-05-28T06:00:00.000Z","result":{"bytes":45246580}},{"timestamp":"2024-05-28T07:00:00.000Z","result":{"bytes":523319228}},{"timestamp":"2024-05-28T08:00:00.000Z","result":{"bytes":1137011362}},{"timestamp":"2024-05-28T09:00:00.000Z","result":{"bytes":771465280}},{"timestamp":"2024-05-28T10:00:00.000Z","result":{"bytes":1525444116}},{"timestamp":"2024-05-28T11:00:00.000Z","result":{"bytes":306270502}},{"timestamp":"2024-05-28T12:00:00.000Z","result":{"bytes":1030969313}},{"timestamp":"2024-05-28T13:00:00.000Z","result":{"bytes":525873160}},{"timestamp":"2024-05-28T14:00:00.000Z","result":{"bytes":1656404473}},{"timestamp":"2024-05-28T15:00:00.000Z","result":{"bytes":1459984538}},{"timestamp":"2024-05-28T16:00:00.000Z","result":{"bytes":43749174}},{"timestamp":"2024-05-28T17:00:00.000Z","result":{"bytes":86316696}},{"timestamp":"2024-05-28T18:00:00.000Z","result":{"bytes":25233469}},{"timestamp":"2024-05-28T19:00:00.000Z","result":{"bytes":777227}},{"timestamp":"2024-05-28T20:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-28T21:00:00.000Z","result":{"bytes":702}},{"timestamp":"2024-05-28T22:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-28T23:00:00.000Z","result":{"bytes":702}},{"timestamp":"2024-05-29T00:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-29T01:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-29T02:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-29T03:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-29T04:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-29T05:00:00.000Z","result":{"bytes":351}},{"timestamp":"2024-05-29T06:00:00.000Z","result":{"bytes":1986553}},{"timestamp":"2024-05-29T07:00:00.000Z","result":{"bytes":773198725}},{"timestamp":"2024-05-29T08:00:00.000Z","result":{"bytes":1377122223}},{"timestamp":"2024-05-29T09:00:00.000Z","result":{"bytes":1028909571}},{"timestamp":"2024-05-29T10:00:00.000Z","result":{"bytes":2345255138}},{"timestamp":"2024-05-29T11:00:00.000Z","result":{"bytes":1312279060}},{"timestamp":"2024-05-29T12:00:00.000Z","result":{"bytes":680850289}},{"timestamp":"2024-05-29T13:00:00.000Z","result":{"bytes":1048884638}},{"timestamp":"2024-05-29T14:00:00.000Z","result":{"bytes":1594418711}},{"timestamp":"2024-05-29T15:00:00.000Z","result":{"bytes":1058369829}},{"timestamp":"2024-05-29T16:00:00.000Z","result":{"bytes":51020619}},{"timestamp":"2024-05-29T17:00:00.000Z","result":{"bytes":699298}},{"timestamp":"2024-05-29T18:00:00.000Z","result":{"bytes":977580}},{"timestamp":"2024-05-29T19:00:00.000Z","result":{"bytes":654075}},{"timestamp":"2024-05-29T20:00:00.000Z","result":{"bytes":8857687}},{"timestamp":"2024-05-29T21:00:00.000Z","result":{"bytes":12372}},{"timestamp":"2024-05-29T22:00:00.000Z","result":{"bytes":720893}},{"timestamp":"2024-05-29T23:00:00.000Z","result":{"bytes":593767}},{"timestamp":"2024-05-30T00:00:00.000Z","result":{"bytes":899084}},{"timestamp":"2024-05-30T01:00:00.000Z","result":{"bytes":28013559}},{"timestamp":"2024-05-30T02:00:00.000Z","result":{"bytes":246812}},{"timestamp":"2024-05-30T03:00:00.000Z","result":{"bytes":792333}},{"timestamp":"2024-05-30T04:00:00.000Z","result":{"bytes":845997}},{"timestamp":"2024-05-30T05:00:00.000Z","result":{"bytes":640669}},{"timestamp":"2024-05-30T06:00:00.000Z","result":{"bytes":914336}},{"timestamp":"2024-05-30T07:00:00.000Z","result":{"bytes":11843}},{"timestamp":"2024-05-30T08:00:00.000Z","result":{"bytes":23894355}},{"timestamp":"2024-05-30T09:00:00.000Z","result":{"bytes":642649}},{"timestamp":"2024-05-30T10:00:00.000Z","result":{"bytes":607337}},{"timestamp":"2024-05-30T11:00:00.000Z","result":{"bytes":603927}},{"timestamp":"2024-05-30T12:00:00.000Z","result":{"bytes":659280}},{"timestamp":"2024-05-30T13:00:00.000Z","result":{"bytes":773766}},{"timestamp":"2024-05-30T14:00:00.000Z","result":{"bytes":852}},{"timestamp":"2024-05-30T15:00:00.000Z","result":{"bytes":232632585}},{"timestamp":"2024-05-30T16:00:00.000Z","result":{"bytes":30553729}},{"timestamp":"2024-05-30T17:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-05-30T18:00:00.000Z","result":{"bytes":579976}},{"timestamp":"2024-05-30T19:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-05-30T20:00:00.000Z","result":{"bytes":18922418}},{"timestamp":"2024-05-30T21:00:00.000Z","result":{"bytes":1058}},{"timestamp":"2024-05-30T22:00:00.000Z","result":{"bytes":824170}},{"timestamp":"2024-05-30T23:00:00.000Z","result":{"bytes":6631642}},{"timestamp":"2024-05-31T00:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-05-31T01:00:00.000Z","result":{"bytes":2512190}},{"timestamp":"2024-05-31T02:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-05-31T03:00:00.000Z","result":{"bytes":660209}},{"timestamp":"2024-05-31T04:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-05-31T05:00:00.000Z","result":{"bytes":5102760}},{"timestamp":"2024-05-31T06:00:00.000Z","result":{"bytes":2921583}},{"timestamp":"2024-05-31T07:00:00.000Z","result":{"bytes":656518340}},{"timestamp":"2024-05-31T08:00:00.000Z","result":{"bytes":3805623279}},{"timestamp":"2024-05-31T09:00:00.000Z","result":{"bytes":1595412971}},{"timestamp":"2024-05-31T10:00:00.000Z","result":{"bytes":482518147}},{"timestamp":"2024-05-31T11:00:00.000Z","result":{"bytes":1046130276}},{"timestamp":"2024-05-31T12:00:00.000Z","result":{"bytes":452666981}},{"timestamp":"2024-05-31T13:00:00.000Z","result":{"bytes":606428956}},{"timestamp":"2024-05-31T14:00:00.000Z","result":{"bytes":1042832725}},{"timestamp":"2024-05-31T15:00:00.000Z","result":{"bytes":845088829}},{"timestamp":"2024-05-31T16:00:00.000Z","result":{"bytes":3584434}},{"timestamp":"2024-05-31T17:00:00.000Z","result":{"bytes":12891123}},{"timestamp":"2024-05-31T18:00:00.000Z","result":{"bytes":15395332}},{"timestamp":"2024-05-31T19:00:00.000Z","result":{"bytes":2288910}},{"timestamp":"2024-05-31T20:00:00.000Z","result":{"bytes":1264}},{"timestamp":"2024-05-31T21:00:00.000Z","result":{"bytes":998175}},{"timestamp":"2024-05-31T22:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-05-31T23:00:00.000Z","result":{"bytes":745769}},{"timestamp":"2024-06-01T00:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-01T01:00:00.000Z","result":{"bytes":1487267}},{"timestamp":"2024-06-01T02:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-01T03:00:00.000Z","result":{"bytes":1039577}},{"timestamp":"2024-06-01T04:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-01T05:00:00.000Z","result":{"bytes":684789}},{"timestamp":"2024-06-01T06:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-01T07:00:00.000Z","result":{"bytes":755216}},{"timestamp":"2024-06-01T08:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-01T09:00:00.000Z","result":{"bytes":676819}},{"timestamp":"2024-06-01T10:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-01T11:00:00.000Z","result":{"bytes":19506743}},{"timestamp":"2024-06-01T12:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-01T13:00:00.000Z","result":{"bytes":698830}},{"timestamp":"2024-06-01T14:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-01T15:00:00.000Z","result":{"bytes":499128}},{"timestamp":"2024-06-01T16:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-01T17:00:00.000Z","result":{"bytes":727197}},{"timestamp":"2024-06-01T18:00:00.000Z","result":{"bytes":562298}},{"timestamp":"2024-06-01T19:00:00.000Z","result":{"bytes":525408}},{"timestamp":"2024-06-01T20:00:00.000Z","result":{"bytes":790}},{"timestamp":"2024-06-01T21:00:00.000Z","result":{"bytes":820827}},{"timestamp":"2024-06-01T22:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-01T23:00:00.000Z","result":{"bytes":5061768}},{"timestamp":"2024-06-02T00:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-02T01:00:00.000Z","result":{"bytes":594550}},{"timestamp":"2024-06-02T02:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-02T03:00:00.000Z","result":{"bytes":576944}},{"timestamp":"2024-06-02T04:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-02T05:00:00.000Z","result":{"bytes":725992}},{"timestamp":"2024-06-02T06:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-02T07:00:00.000Z","result":{"bytes":728435}},{"timestamp":"2024-06-02T08:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-02T09:00:00.000Z","result":{"bytes":706727}},{"timestamp":"2024-06-02T10:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-02T11:00:00.000Z","result":{"bytes":1285084}},{"timestamp":"2024-06-02T12:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-02T13:00:00.000Z","result":{"bytes":11870786}},{"timestamp":"2024-06-02T14:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-02T15:00:00.000Z","result":{"bytes":656684}},{"timestamp":"2024-06-02T16:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-02T17:00:00.000Z","result":{"bytes":683010}},{"timestamp":"2024-06-02T18:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-02T19:00:00.000Z","result":{"bytes":686293}},{"timestamp":"2024-06-02T20:00:00.000Z","result":{"bytes":948}},{"timestamp":"2024-06-02T21:00:00.000Z","result":{"bytes":769293}},{"timestamp":"2024-06-02T22:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-02T23:00:00.000Z","result":{"bytes":1311629}},{"timestamp":"2024-06-03T00:00:00.000Z","result":{"bytes":618147}},{"timestamp":"2024-06-03T01:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-03T02:00:00.000Z","result":{"bytes":583116}},{"timestamp":"2024-06-03T03:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-03T04:00:00.000Z","result":{"bytes":526511}},{"timestamp":"2024-06-03T05:00:00.000Z","result":{"bytes":632}},{"timestamp":"2024-06-03T06:00:00.000Z","result":{"bytes":4801852}},{"timestamp":"2024-06-03T07:00:00.000Z","result":{"bytes":724877222}}]
12 changes: 12 additions & 0 deletions resources/tests/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ def test_post_base64_encoded_data(self):
encoded_json = base64.b64encode(json.dumps(json_data).encode('utf-8')).decode('utf-8')
data = {'model':'dHJhZmZpYw==', 'data': encoded_json}
with self.api_server.app.test_client().post('/api/v1/outliers', data=data) as response:
self.assertEqual(response.get_json()["status"], "success")
self.assertEqual(response.status_code, 200)

def test_shallow_outliers_executes(self):
current_dir = os.path.dirname(os.path.abspath(__file__))
data_file_path = os.path.join(current_dir, "shallow_outliers_test_data.json")
with open(data_file_path, 'r') as file:
json_data = json.load(file)
encoded_json = base64.b64encode(json.dumps(json_data).encode('utf-8')).decode('utf-8')
data = {'data': encoded_json}
with self.api_server.app.test_client().post('/api/v1/outliers', data=data) as response:
self.assertEqual(response.get_json()["status"], "success")
self.assertEqual(response.status_code, 200)

if __name__ == '__main__':
Expand Down

0 comments on commit 039738b

Please sign in to comment.