Beispiel #1
0
    def greenbutton_parsed_meters_confirmation(self, request):
        body = dict(request.data)
        file_id = body['file_id']
        org_id = body['organization_id']
        view_id = body['view_id']

        import_file = ImportFile.objects.get(pk=file_id)
        parser = reader.GreenButtonParser(import_file.local_file)
        raw_meter_data = list(parser.data)

        property_id = PropertyView.objects.get(pk=view_id).property_id
        meters_parser = MetersParser(org_id,
                                     raw_meter_data,
                                     source_type=Meter.GREENBUTTON,
                                     property_id=property_id)

        result = {}

        result["validated_type_units"] = meters_parser.validated_type_units()
        result["proposed_imports"] = meters_parser.proposed_imports()

        import_file.matching_results_data['property_id'] = property_id
        import_file.save()

        return result
Beispiel #2
0
    def greenbutton_meters_preview(self, request, pk):
        """
        Returns validated type units and proposed imports
        """
        org_id = request.query_params.get('organization_id')
        view_id = request.query_params.get('view_id')

        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)

        parser = reader.GreenButtonParser(import_file.local_file)
        raw_meter_data = list(parser.data)

        try:
            property_id = PropertyView.objects.get(
                pk=view_id, cycle__organization_id=org_id).property_id
        except PropertyView.DoesNotExist:
            return JsonResponse(
                {
                    'status': 'error',
                    'message':
                    'Could not find property with pk=' + str(view_id)
                },
                status=status.HTTP_400_BAD_REQUEST)

        meters_parser = MetersParser(org_id,
                                     raw_meter_data,
                                     source_type=Meter.GREENBUTTON,
                                     property_id=property_id)

        result = {}

        result["validated_type_units"] = meters_parser.validated_type_units()
        result["proposed_imports"] = meters_parser.proposed_imports

        import_file.matching_results_data['property_id'] = property_id
        import_file.save()

        return result