Esempio n. 1
0
def create_multiple(request):
    """No request validation"""
    payload = json.loads(request.body.decode('utf-8'))
    try:
        split = Split.objects.get(pk=payload['split_id'])
    except Split.DoesNotExist:
        return Response({'error': 'not in database'},
                        status=status.HTTP_404_NOT_FOUND)

    # detect either or not a predictive_model to update has been specified otherwise train a new one.
    if 'incremental_train' in payload['config'] and payload['config'][
            'incremental_train']['base_model'] is not None:
        jobs = update(split, payload)
    elif payload['type'] in [e.value for e in PredictiveModels]:
        jobs = generate(split, payload)
    elif payload['type'] == JobTypes.LABELLING.value:
        jobs = generate_labelling(split, payload)
    else:
        return Response(
            {'error': 'type not supported'.format(payload['type'])},
            status=status.HTTP_422_UNPROCESSABLE_ENTITY)
    for job in jobs:
        django_rq.enqueue(tasks.prediction_task, job.id)
    serializer = JobSerializer(jobs, many=True)
    return Response(serializer.data, status=201)
Esempio n. 2
0
    def test_generate_labelling_up_to(self):
        job = create_test_job()
        job.type = JobTypes.LABELLING.value
        job.save()

        generated_job = generate_labelling(
            split=job.split,
            payload={
                'type': 'labelling',
                'split_id': 1,
                'config': {
                    'encodings': ['simpleIndex'],
                    'encoding': {
                        'padding': False,
                        'prefix_length': 2,
                        'generation_type': 'up_to',
                        'add_remaining_time': False,
                        'add_elapsed_time': False,
                        'add_executed_events': False,
                        'add_resources_used': False,
                        'add_new_traces': False,
                        'features': [],
                    },
                    'create_models': False,
                    'labelling': {
                        'type': 'next_activity',
                        'attribute_name': '',
                        'threshold_type': 'threshold_mean',
                        'threshold': 0,
                    }
                }
            })[0]

        self.assertEqual(job.type, generated_job.type)
        self.assertEqual(job.split, generated_job.split)

        job.encoding.features = None
        job.encoding.task_generation_type = None
        generated_job.encoding.features = None
        generated_job.encoding.task_generation_type = None
        self.assertDictEqual(job.encoding.to_dict(),
                             generated_job.encoding.to_dict())

        job.labelling.attribute_name = None
        generated_job.labelling.attribute_name = None
        self.assertDictEqual(job.labelling.to_dict(),
                             generated_job.labelling.to_dict())