예제 #1
0
 def get_data(self):
     scorecard_id = self.kwargs['scorecard_id']
     scorecard = get_object_or_404(Scorecard, pk=scorecard_id)
     rs = get_responsesets(scorecard, limit_to_entity=[self.entity], aggregate_by_entity=True, aggregate_on=DataSeriesGroup.objects.get(name='Country'),compare_series=DataSeriesGroup.objects.get(name='Data collection year'))
     operations = OrderedDict()
     for country, data in rs[self.entity].items():
         result = scorecard.get_values(data)
         for operation, data in result:
             operations[operation] = operations.get(operation,[])
             operations[operation].append((country,data))
     return operations
예제 #2
0
    def get_data(self):
        scorecard_id = self.kwargs['scorecard_id']
        scorecard = get_object_or_404(Scorecard, pk=scorecard_id)
        entity_type = [EntityType.objects.get(name='Agency')]
        rs = get_responsesets(scorecard, aggregate_by_entity=True, compare_series=DataSeriesGroup.objects.get(name='Data collection year'), limit_to_entitytype=entity_type)

        operations = OrderedDict()
        for entity, data in rs.items():
            result = scorecard.get_values(data)
            for operation, data in result:
                operations[operation] = operations.get(operation,[])
                if operation.identifier =="5DPa":
                    data[0] = (data[0][0],Scalar(Decimal(indicator_5DPa[entity.name])))
                operations[operation].append((entity,data))
        return operations
예제 #3
0
    def get_data(self):
        scorecard_id = self.kwargs['scorecard_id']
        scorecard = get_object_or_404(Scorecard, pk=scorecard_id)
        if scorecard.name.startswith('Agency'):
            entity_type = [EntityType.objects.get(name='agency')]
        else:
            entity_type = [EntityType.objects.get(name='government')]
        rs = get_responsesets(scorecard, aggregate_by_entity=True, compare_series=DataSeriesGroup.objects.get(name='Data collection year').dataseries_set.filter(visible=True), limit_to_entitytype=entity_type)

        operations = OrderedDict()
        for entity, data in rs.items():
            result = scorecard.get_values(data)
            for operation, data in result:
                operations[operation] = operations.get(operation,[])

                base, curr = data
                base, curr = base[1], curr[1]

                change = ''
                if base is not None and curr is not None:
                    if isinstance(curr, Scalar) and isinstance(curr.get_value(), Decimal):
                        change = Scalar(100)
                        if isinstance(base, Scalar) and isinstance(base.get_value(),Decimal):
                            if base.get_value() == 0:
                                change = ''
                            else:
                                change = Scalar(((curr.get_value() / base.get_value() * 100)-100).quantize(Decimal('1.0')))

                data.append(('% change', change))

                rating = 'none'
                if curr is not None and isinstance(curr,Scalar) and isinstance(curr.get_value(), Decimal):
                    if base != None:
                        rating = self.get_rating(operation, base.get_value(), curr.get_value())
                    else:
                        rating = Rating.NONE

                data.append(('rating', rating))
                #if first:
                #    if len(data)==2:
                #        data.append(('rating',''))
                operations[operation].append((entity,data))
        return operations