123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- from utils import transport
- from utils.ml import ML, AnomalyDetection
- import unittest
- import json
- import os
- path = os.environ['MONITOR_CONFIG_PATH']
- f = open(path)
- CONFIG = json.loads( f.read())
- f.close()
- factory = transport.DataSourceFactory()
- class TestML(unittest.TestCase):
- def setUp(self):
-
- ref = CONFIG['store']['class']['read']
- p = CONFIG['store']['args']
- p['qid'] = ['apps']
- self.greader = factory.instance(type=ref,args=p)
- def test_has_date(self):
- r = self.greader.read()
-
- self.assertTrue(r)
- def test_Filter(self):
- r = self.greader.read()
- r = r['apps']
- x = ML.Filter('label','Google Chrome',r)
- for row in x:
- self.assertTrue(row['label'] == 'Google Chrome')
- def test_Extract(self):
- r = self.greader.read()
- r = r['apps']
- x = ML.Filter('label','Google Chrome',r)
- x_ = ML.Extract(['cpu_usage','memory_usage'], x)
- self.assertTrue (len (x) == len(x_))
- pass
- def test_Learn(self):
- ref = CONFIG['store']['class']['read']
- p = CONFIG['store']['args']
- greader = factory.instance(type=ref,args=p)
-
- data = greader.read()
-
- data = data['apps']
- lhandler = AnomalyDetection()
- features = CONFIG['learner']['anomalies']['features']
- label = CONFIG['learner']['anomalies']['label']
- lhandler.learn(data,'label','Google Chrome',features,label)
-
-
- if __name__ == '__main__' :
- unittest.main()
|