예제 #1
0
    def test_get_dataset_download_action(self, async_get_object_mock):
        # bogus model
        url = self._get_url(id=101010,
                            action='dataset_download')
        resp = self.client.get(url, headers=HTTP_HEADERS)
        self.assertEquals(resp.status_code, httplib.NOT_FOUND)

        # existing model
        dataset = DataSet.query.filter_by(
            name=DataSetData.dataset_01.name).first()
        from api.async_tasks.models import AsyncTask
        task = AsyncTask()
        task.args = [self.obj.id, dataset.id]
        task.object_id = self.obj.id
        async_get_object_mock.return_value = [task]
        self.obj.status = Model.STATUS_TRAINING
        url = self._get_url(id=self.obj.id,
                            action='dataset_download')
        resp = self.client.get(url, headers=HTTP_HEADERS)
        self.assertEquals(resp.status_code, httplib.OK)
        resp_obj = json.loads(resp.data)
        self.assertEqual(async_get_object_mock.call_args_list[0][0][1],
                         TRANSFORM_DATASET_TASK)
        self.assertTrue('downloads' in resp_obj)
        self.assertEqual(resp_obj['downloads'][0]['dataset']['id'], dataset.id)
예제 #2
0
def task_prerun_handler(sender=None, task_id=None, task=None, args=None,
                        kwargs=None, **kwds):  # pragma: no cover
    obj = get_object_from_task(task.name, args, kwargs)
    if obj:
        task_obj = AsyncTask.create_by_task_and_object(
            task.name,
            task_id,
            args,
            kwargs,
            obj)
        task_obj.save()
예제 #3
0
    def test_get_transformers_download_action(self, async_get_object_mock):
        # bogus model
        url = self._get_url(id=101010,
                            action='transformers_download')
        resp = self.client.get(url, headers=HTTP_HEADERS)
        self.assertEquals(resp.status_code, httplib.NOT_FOUND)

        # existing model
        segment = Segment.query.filter_by(
            name=SegmentData.segment_01.name).first()
        from api.async_tasks.models import AsyncTask
        task = AsyncTask()
        task.args = [self.obj.id, segment.id]
        task.object_id = segment.id
        async_get_object_mock.return_value = [task]
        url = self._get_url(id=self.obj.id,
                            action='transformers_download')
        resp = self.client.get(url, headers=HTTP_HEADERS)
        self.assertEquals(resp.status_code, httplib.OK)
        resp_obj = json.loads(resp.data)
        self.assertEqual(async_get_object_mock.call_args_list[0][0][1],
                         TRANSFORMERS_UPLOAD_TASK)
        self.assertTrue('downloads' in resp_obj)
        self.assertEqual(resp_obj['downloads'][0]['segment']['id'], segment.id)
예제 #4
0
    def _get_dataset_download_action(self, **kwargs):
        model = self._get_details_query(None, **kwargs)
        if model is None:
            raise NotFound('Model not found')

        from api.tasks import TRANSFORM_DATASET_TASK
        tasks = AsyncTask.get_current_by_object(model, TRANSFORM_DATASET_TASK)

        downloads = []
        for task in tasks:
            downloads.append({
                'dataset': DataSet.query.get(task.args[1]),
                'task': task
            })

        return self._render({
            self.OBJECT_NAME: model.id,
            'downloads': downloads
        })
예제 #5
0
    def _get_transformers_download_action(self, **kwargs):
        model = self._get_details_query(None, **kwargs)
        if model is None:
            raise NotFound('Model not found')

        from api.tasks import TRANSFORMERS_UPLOAD_TASK
        tasks = []
        for segment in model.segments:
            tasks.extend(
                AsyncTask.get_current_by_object(segment,
                                                TRANSFORMERS_UPLOAD_TASK))

        downloads = []
        for task in sorted(tasks, key=lambda x: x.created_on, reverse=True):
            downloads.append({
                'segment': Segment.query.get(task.args[1]),
                'task': task
            })

        return self._render({
            self.OBJECT_NAME: model.id,
            'downloads': downloads
        })
예제 #6
0
 def tunnels(self):
     from api.async_tasks.models import AsyncTask
     return AsyncTask.get_current_by_object(
         self,
         'api.instances.tasks.run_ssh_tunnel',
     )
예제 #7
0
 def pig_fields(self):
     from api.async_tasks.models import AsyncTask
     return AsyncTask.get_current_by_object(
         self,
         'api.import_handlers.tasks.load_pig_fields',
     )
예제 #8
0
 def exports(self):
     from api.async_tasks.models import AsyncTask
     return AsyncTask.get_current_by_object(
         self,
         'api.model_tests.tasks.get_csv_results',
     )
예제 #9
0
 def confusion_matrix_calculations(self):
     from api.async_tasks.models import AsyncTask
     return AsyncTask.get_current_by_object(
         self,
         'api.model_tests.tasks.calculate_confusion_matrix',
         statuses=AsyncTask.STATUSES)
예제 #10
0
 def db_exports(self):
     from api.async_tasks.models import AsyncTask
     return AsyncTask.get_current_by_object(
         self,
         'api.model_tests.tasks.export_results_to_db',
     )