예제 #1
0
    def baseline_map(self, f, row):
        additional_periods = ['1995', '1996', '1997', '1998', '1999', '2000']
        baseline_periods = ['BaseA5', 'BaseNA5']
        bdn_groups = ['AI', 'AII', 'BI', 'EI']
        group = row['Anx'] + row['Grp']
        if row['PeriodID'] in additional_periods and group in bdn_groups:
            if not self.MODELS['baseline']['additional_data'].get(
                    row['CntryID']):
                self.MODELS['baseline']['additional_data'][row['CntryID']] = {}
                for bdn_group in bdn_groups:
                    self.MODELS['baseline']['additional_data'][
                        row['CntryID']][bdn_group] = {}
            self.store_baseline_additional_data(
                row['CntryID'],
                row['PeriodID'],
                group,
                row['ProdArt5'] if row['ProdArt5'] else 0,
            )
        elif row['PeriodID'] in baseline_periods:
            if row['PeriodID'] == 'BaseNA5' and row['ProdTransfer']:
                self.store_baseline_prod_transfers(row['CntryID'], group,
                                                   row['ProdTransfer'])
            entries = []
            party = self.lookup_id('party', 'abbr', row['CntryID'])
            group = self.lookup_id('group', 'group_id', group)
            party_type = row['PeriodID'][4:]

            f['party'] = party
            f['group'] = group
            f['baseline_type_id'] = self.lookup_id('baselinetype', 'name',
                                                   party_type + 'Prod')
            # Don't need to call get_decimals for 'BaseA5' and 'BaseNA5' periods
            # because is not a special case and we will round to 1 decimal.
            baseline_prod = row['CalcProd']
            if baseline_prod:
                baseline_prod = round_half_up(row['CalcProd'], 1)
            f['baseline'] = baseline_prod
            entries.append(f)

            f = {}
            f['party'] = party
            f['group'] = group
            f['baseline_type_id'] = self.lookup_id('baselinetype', 'name',
                                                   party_type + 'Cons')
            baseline_cons = row['CalcCons']
            if baseline_cons:
                baseline_cons = round_half_up(row['CalcCons'], 1)
            f['baseline'] = baseline_cons
            entries.append(f)

            print('Procces country {} for group {}'.format(
                row['CntryID'], row['Anx'] + row['Grp']))

            return entries
        else:
            return
예제 #2
0
def get_chng(actual_value, compared_value):
    if isinstance(actual_value, str) or isinstance(compared_value, str):
        return '-'
    elif actual_value > 0 and compared_value != 0:
        return round_half_up(
            -100 + actual_value / compared_value * 100,
            2
        )
    else:
        return -100
예제 #3
0
    def calc_avg(self, data, periods):
        s = 0
        for period in periods:
            if not data.get(period):
                return
            s += data[period]['ProdArt5']
        baseline = s / len(periods)
        if data['prod_transfers']:
            baseline += data['prod_transfers']

        # BDN new baselines are rounded to 5 decimals
        return round_half_up(baseline, 5)
예제 #4
0
 def get_entry(self, idx, party, period, group, limit_type, limit):
     return {
         'pk': idx,
         'model': 'core.limit',
         'fields': {
             'party':
             party.pk,
             'reporting_period':
             period.pk,
             'group':
             group.pk,
             'limit_type':
             limit_type,
             'limit':
             round_half_up(
                 limit, 1 if limit_type == LimitTypes.BDN.value else
                 ProdCons.get_decimals(period, group, party))
         }
     }
예제 #5
0
def get_per_capita_cons(cons, population):
    if not isinstance(cons, str):
        return round_half_up(cons / population, 4)
    else:
        return '-'