Exemple #1
0
    def post(self, request):

        serializer = ThresholdSerializer(data=request.data)

        if serializer.is_valid():
            try:
                data = {}
                settings = get_settings(request)

                dataset_series_json = serializer.validated_data[
                    'dataset_series_json']
                threshold = serializer.validated_data['threshold']
                upper_boundary = serializer.validated_data['upper_boundary']

                data_series, info = get_updated_dataset_series_for_threshold_json(
                    dataset_series_json, threshold, upper_boundary, settings)
                data['series'] = data_series['series']
                data['info'] = info
                return Response(data)

            except Exception as e:
                logging.debug(e)
                return exception_message_response(e)
        else:
            return Response({}, status=status.HTTP_400_BAD_REQUEST)
Exemple #2
0
    def post(self, request, dataset_id):

        try:
            serializer = IsolationForestSerializer(context={
                'dataset_selected': dataset_id,
                'request': request
            },
                                                   data=request.data)

            if serializer.is_valid():
                df_from_json, df_class_from_json = get_datasets_from_json(
                    serializer.validated_data['dataset_series_json'])
                try:
                    data = {}
                    settings = get_settings(request)
                    data_series, info = isolation_forest_detection(
                        df_from_json, df_class_from_json,
                        serializer.validated_data, settings)

                    data['series'] = data_series
                    data['info'] = info
                    return Response(data)

                except Exception as e:
                    logging.debug(e)
                    return exception_message_response(e)
            else:
                return Response({'form_errors': serializer.errors},
                                status=status.HTTP_400_BAD_REQUEST)

        except DataSet.DoesNotExist:
            messages.error(request, dataset_not_found_msg(dataset_id))
            return redirect('vadetisweb:index')