Ejemplo n.º 1
0
    def list(self, request, *args, **kwargs):
        lic_id = int(request.GET["lic_id"])
        (duration_type, start, end) = duration_utils.parse_duration_from_request(request)

        # todo, fixme: replace with egg consumer call
        if False:   # LicenseLockListExtLicense.objects.is_ext_license_locked(LicenseEnum.license_optimisation_management, lic_id):
            return Response([])
        else:
            # LicenseUsage.log_usage(
            #     LicenseEnum.license_optimisation_management,
            #     LicenseParameterTypeEnum.ext_lic,
            #     lic_id
            # )

            logger.debug(
                "retrieving data for license {} from {} to {}, type {}".format(
                    lic_id,
                    start,
                    end,
                    duration_type
                )
            )
            self.object_list = ext_license_state_coarse.objects.filter(
                ext_license_id=lic_id,
                ext_license_check_coarse__duration_type=duration_type.ID,
                ext_license_check_coarse__start_date__range=(start, end)
            )

            serializer = self.get_serializer(self.object_list, many=True)
            return Response(serializer.data)
Ejemplo n.º 2
0
    def list(self, request, *args, **kwargs):
        lic_id = request.GET["lic_id"]
        (duration_type, start, end) = duration_utils.parse_duration_from_request(request)

        self.object_list = ext_license_version_state_coarse.objects.filter(
            ext_license_version__ext_license=lic_id,
            ext_license_check_coarse__duration_type=duration_type.ID,
            ext_license_check_coarse__start_date__range=(start, end)
        )

        serializer = self.get_serializer(self.object_list, many=True)
        return Response(serializer.data)
Ejemplo n.º 3
0
    def list(self, request, *args, **kwargs):
        lic_id = request.GET["lic_id"]
        (duration_type, start,
         end) = duration_utils.parse_duration_from_request(request)

        data = ext_license_usage_coarse.objects.filter(
            ext_license_version_state_coarse__ext_license_version__ext_license=
            lic_id,
            ext_license_version_state_coarse__ext_license_check_coarse__duration_type
            =duration_type.ID,
            ext_license_version_state_coarse__ext_license_check_coarse__start_date__range
            =(start, end)
        ).extra(select={
            "val": "num * backbone_ext_license_usage_coarse.frequency"
        }).values_list(
            self.get_name_column_name(),
            "ext_license_version_state_coarse__ext_license_check_coarse__start_date",
            "val")
        # for device, we possibly will also want the long name, in which case we could have two columns here and combine them in the loop below or so

        summing = collections.defaultdict(lambda: 0)

        # sum up (would be nicer in db query, but it doesn't seem to be combinable with val calculation)
        for d in data:
            name = d[0]
            full_start_date = d[1]
            val = d[2]
            summing[(name, full_start_date)] += val

        result = []
        for entry in summing.iteritems():
            name = entry[0][0]
            full_start_date = entry[0][1]
            val_sum = entry[1]
            result.append({
                'type':
                name,
                'val':
                val_sum,
                'full_start_date':
                full_start_date,
                'display_date':
                duration_type.get_display_date(full_start_date)
            })

        return Response(result)