コード例 #1
0
ファイル: test_api.py プロジェクト: xgen-dev/haro-python-sdk
 def test_predict(self, m):
     m.get(
         'http://test-prediction-api/v42.526/predict/predict-avg-context-for-action-watch-context-duration_seconds/user/u1/',
         text=json.dumps({'value': 31.41}),
         headers={
             'X-ADDITIONAL-INFO': 'some-value',
             'other-headers': 'present'
         })
     haro_api = api.HaroAPIClient(api_id="test-api-id",
                                  api_key="test-api-key")
     r = haro_api.predict(
         pid="predict-avg-context-for-action-watch-context-duration_seconds",
         user="******")
     self.assertEqual(r.value, 31.41)
     self.assertEqual(r.meta, {"ADDITIONAL-INFO": "some-value"})
コード例 #2
0
ファイル: test_api.py プロジェクト: xgen-dev/haro-python-sdk
 def test_anticipate(self, m):
     m.get(
         'http://test-prediction-api/v42.526/anticipate/anticipate-condition-eebc14df57-within-3-hours/user/u1/',
         text=json.dumps({'value': 0.79}),
         headers={
             'X-ADDITIONAL-INFO': 'some-value',
             'other-headers': 'present'
         })
     haro_api = api.HaroAPIClient(api_id="test-api-id",
                                  api_key="test-api-key")
     r = haro_api.anticipate(
         pid="anticipate-condition-eebc14df57-within-3-hours",
         user="******",
         name="v2")
     self.assertEqual(r.value, 0.79)
     self.assertEqual(r.meta, {"ADDITIONAL-INFO": "some-value"})
コード例 #3
0
ファイル: test_api.py プロジェクト: xgen-dev/haro-python-sdk
 def test_all_predictions(self, m):
     api_result = [
         {
             "pid": "rank-items-for-action-watch",
             "name": "rank-watch",
             "predictions": {
                 'entities': ['item-3', 'item-1', 'item-2'],
                 'scores': [0.79, 0.43, 0.05]
             },
         },
         {
             "pid":
             "predict-avg-context-for-action-watch-context-duration_seconds",
             "name": "avg-duration",
             "predictions": {
                 'value': 31.41
             },
         },
         {
             "pid": "anticipate-condition-eebc14df57-within-3-hours",
             "name": "anticipate-watch",
             "predictions": {
                 'value': 0.79
             },
         },
     ]
     m.get('http://test-prediction-api/v42.526/all-predictions/user/u1/',
           text=json.dumps(api_result))
     haro_api = api.HaroAPIClient(api_id="test-api-id",
                                  api_key="test-api-key")
     results = haro_api.all_predictions(user="******")
     self.assertEquals(len(results), 3)
     r1, r2, r3 = results
     self.assertEquals(r1.pid, "rank-items-for-action-watch")
     self.assertEquals(r1.name, "rank-watch")
     self.assertEquals(r1.entities, ['item-3', 'item-1', 'item-2'])
     self.assertEqual(r1.scores, [0.79, 0.43, 0.05])
     self.assertEquals(
         r2.pid,
         "predict-avg-context-for-action-watch-context-duration_seconds")
     self.assertEquals(r2.name, "avg-duration")
     self.assertEquals(r2.value, 31.41)
     self.assertEquals(r3.pid,
                       "anticipate-condition-eebc14df57-within-3-hours")
     self.assertEquals(r3.name, "anticipate-watch")
     self.assertEquals(r3.value, 0.79)
コード例 #4
0
ファイル: test_api.py プロジェクト: xgen-dev/haro-python-sdk
 def test_custom(self, m):
     m.get(
         'http://test-prediction-api/v42.526/custom/custom-predictor-for-home-page/user/u1/',
         text=json.dumps({'value': {
             "custom-values": [3, 1, 4]
         }}),
         headers={
             'X-ADDITIONAL-INFO': 'some-value',
             'other-headers': 'present'
         })
     haro_api = api.HaroAPIClient(api_id="test-api-id",
                                  api_key="test-api-key")
     r = haro_api.custom(pid="custom-predictor-for-home-page",
                         user="******",
                         name="v2")
     self.assertEqual(r.value, {"custom-values": [3, 1, 4]})
     self.assertEqual(r.meta, {"ADDITIONAL-INFO": "some-value"})
コード例 #5
0
ファイル: test_api.py プロジェクト: xgen-dev/haro-python-sdk
 def test_send_events(self, m):
     m.post('http://test-events-api/v31.415/events',
            text=json.dumps({
                'status': 'ok',
                'count': 2
            }))
     now = int(time.time() * 1000)
     e1 = api.Event(id="event-id-1",
                    action="action_1",
                    item="item-1",
                    timestamp=now,
                    user="******",
                    context={
                        "k1": "v1",
                        "k2": 3.1415
                    })
     e2 = api.Event(id="event-id-2",
                    action="action-2",
                    item="item-2",
                    timestamp=now,
                    user="******",
                    context={})
     haro_api = api.HaroAPIClient(api_id="test-api-id",
                                  api_key="test-api-key")
     num_sent, errors = haro_api.send_events([e1, e2])
     self.assertEqual(num_sent, 2)
     self.assertEqual(errors, [])
     self.assertEqual(m.last_request.json(), [{
         'action': 'action_1',
         'user': '******',
         'context': {
             'k1': 'v1',
             'k2': 3.1415
         },
         'item': 'item-1',
         'id': 'event-id-1',
         'ts': now
     }, {
         'action': 'action-2',
         'user': '******',
         'context': {},
         'item': 'item-2',
         'id': 'event-id-2',
         'ts': now
     }])
コード例 #6
0
ファイル: test_api.py プロジェクト: xgen-dev/haro-python-sdk
 def test_rank(self, m):
     m.get(
         'http://test-prediction-api/v42.526/rank/rank-items-for-action-watch/user/u1/',
         text=json.dumps({
             'entities': ['item-3', 'item-1', 'item-2'],
             'scores': [0.79, 0.43, 0.05]
         }),
         headers={
             'X-ADDITIONAL-INFO': 'some-value',
             'other-headers': 'present'
         })
     haro_api = api.HaroAPIClient(api_id="test-api-id",
                                  api_key="test-api-key")
     r = haro_api.rank(pid="rank-items-for-action-watch",
                       user="******",
                       subset=['item-1', 'item-2', 'item-3'],
                       include_scores=True)
     self.assertEqual(r.entities, ['item-3', 'item-1', 'item-2'])
     self.assertEqual(r.scores, [0.79, 0.43, 0.05])
     self.assertEqual(r.meta, {"ADDITIONAL-INFO": "some-value"})