Esempio n. 1
0
    def start(self, request, organization_id):
        """
        This API endpoint will create a new data_quality check process in the background,
        on potentially a subset of properties/taxlots, and return back a query key
        """
        body = request.data
        property_view_ids = body['property_view_ids']
        taxlot_view_ids = body['taxlot_view_ids']

        property_state_ids = PropertyView.objects.filter(
            id__in=property_view_ids).values_list('state_id', flat=True)
        taxlot_state_ids = TaxLotView.objects.filter(
            id__in=taxlot_view_ids).values_list('state_id', flat=True)

        # For now, organization_id is the only key currently used to identify DataQualityChecks
        return_value = do_checks(organization_id, property_state_ids,
                                 taxlot_state_ids)

        return JsonResponse({
            'num_properties': len(property_state_ids),
            'num_taxlots': len(taxlot_state_ids),
            # TODO #239: Deprecate progress_key from here and just use the 'progess.progress_key'
            'progress_key': return_value['progress_key'],
            'progress': return_value,
        })
Esempio n. 2
0
    def create(self, request):
        """
        This API endpoint will create a new cleansing operation process in the background,
        on potentially a subset of properties/taxlots, and return back a query key
        ---
        parameters:
            - name: organization_id
              description: Organization ID
              type: integer
              required: true
              paramType: query
            - name: data_quality_ids
              description: An object containing IDs of the records to perform data quality checks on.
                           Should contain two keys- property_state_ids and taxlot_state_ids, each of which is an array
                           of appropriate IDs.
              required: true
              paramType: body
        type:
            status:
                type: string
                description: success or error
                required: true
        """
        # step 0: retrieving the data
        body = request.data
        property_state_ids = body['property_state_ids']
        taxlot_state_ids = body['taxlot_state_ids']
        organization = Organization.objects.get(
            pk=request.query_params['organization_id'])

        # step 1: validate the check IDs all exist
        # step 2: validate the check IDs all belong to this organization ID
        # step 3: validate the actual user belongs to the passed in org ID
        # step 4: kick off a background task
        return_value = do_checks(organization.id, property_state_ids,
                                 taxlot_state_ids)
        # step 5: create a new model instance
        return JsonResponse({
            'num_properties': len(property_state_ids),
            'num_taxlots': len(taxlot_state_ids),
            # TODO #239: Deprecate progress_key from here and just use the 'progess.progress_key'
            'progress_key': return_value['progress_key'],
            'progress': return_value,
        })
Esempio n. 3
0
    def start_data_quality_checks(self, request, pk=None):
        """
        Starts a background task to attempt automatic matching between buildings
        in an ImportFile with other existing buildings within the same org.
        """
        org_id = request.query_params.get('organization_id', None)

        try:
            import_file = ImportFile.objects.get(
                pk=pk,
                import_record__super_organization_id=org_id
            )
        except ImportFile.DoesNotExist:
            return JsonResponse(
                {'status': 'error', 'message': 'Could not find import file with pk=' + str(
                    pk)}, status=status.HTTP_400_BAD_REQUEST)

        return_value = do_checks(org_id, None, None, import_file.pk)
        # step 5: create a new model instance
        return JsonResponse({
            'progress_key': return_value['progress_key'],
            'progress': return_value,
        })