Exemple #1
0
    def data_table(self):
        data = self.get_ges_extent_data()

        out = []

        for descr_type, descriptors in DESCRIPTOR_TYPES:
            descriptor_type_data = []

            for descriptor in descriptors:
                descriptor_data = [
                    [
                        get_label(row.Feature,
                                  'features'), row.MarineReportingUnit,
                        self._norm_float(row.GESExtentAchieved),
                        row.GESExtentUnit,
                        self._ges_achieved(row.GESAchieved)
                    ] for row in data
                    if row.GESComponent.split('/')[0] == descriptor
                ]

                if not descriptor_data:
                    descriptor_data = [['Not reported', '', '', '', '']]

                descriptor_type_data.append(
                    [self.get_descriptor_title(descriptor), descriptor_data])

            out.append([descr_type, descriptor_type_data])

        return out
Exemple #2
0
    def data_table(self):
        data = self.get_features_pressures_data()

        out = []

        # general_pressures = set(['PresAll', 'Unknown'])

        for activ_theme, activ_features in self.uses_activities_features:
            descriptor_type_data = []

            for activ_feat in activ_features:
                # if activ_feat.endswith('All'):
                #     continue

                features_rep = data.get(activ_feat, set())
                descriptor_data = []

                # we iterate on all pressures 'Non-indigenous species',
                # 'Microbial pathogens' etc. and check if the pressures
                # was reported for the current descriptor and feature
                for theme, features_for_theme in self.features_needed:
                    for feature in features_for_theme:
                        if feature.endswith('All'):
                            continue

                        # if pressure is ending with 'All' it applies to all
                        # features in the current theme
                        pressures = filter(
                            lambda i: i.endswith('All') or i == feature,
                            list(
                                features_rep.intersection(
                                    set(features_for_theme))))

                        # These pressures apply to all themes and features
                        # general_pressures_reported = list(
                        #     general_pressures.intersection(features_rep)
                        # )

                        # pressures.extend(general_pressures_reported)

                        pressures = [
                            ItemLabel(x, self.get_feature_short_name(x))
                            for x in pressures
                        ]

                        descriptor_data.append(ItemListOverview(pressures))

                descriptor_type_data.append(
                    (get_label(activ_feat, 'features'), descriptor_data))

            out.append((activ_theme, descriptor_type_data))

        return out
Exemple #3
0
    def features(self):
        t = sql.t_MSFD9_Features
        count, res = db.get_all_records(
            t,
            t.c.MSFD9_Descriptor == self.descriptor_item.MSFD9_Descriptor_ID)
        vals = list(
            set([x.FeatureType
                 for x in res] + [x.FeaturesPressuresImpacts for x in res]))
        # return vals       # remove code below when properly integrated

        rows = [ItemLabel(v, get_label(v, 'features')) for v in vals]
        return ItemList(rows=rows)
Exemple #4
0
    def data_table(self):
        pressures_data = self.get_features_pressures_data()
        env_targets_data = self.get_env_targets_data()
        out = []

        general_pressures = set(['PresAll', 'Unknown'])

        for descr_type, descriptors in DESCRIPTOR_TYPES:
            descriptor_type_data = []

            for descriptor in descriptors:
                features_rep = pressures_data[descriptor]
                descriptor_data = []

                # we iterate on all pressures 'Non-indigenous species',
                # 'Microbial pathogens' etc. and check if the pressures
                # was reported for the current descriptor and feature
                for theme, features_for_theme in self.features_needed:
                    for feature in features_for_theme:
                        if feature.endswith('All'):
                            continue

                        # if pressure is ending with 'All' it applies to all
                        # features in the current theme
                        pressures = filter(
                            lambda i: i.endswith('All') or i == feature,
                            list(
                                features_rep.intersection(
                                    set(features_for_theme))))

                        # These pressures apply to all themes and features
                        general_pressures_reported = list(
                            general_pressures.intersection(features_rep))

                        pressures.extend(general_pressures_reported)

                        targets = set(
                            sorted([
                                ItemLabel(get_label(p, 'targets'), p)
                                for press in pressures
                                for p in env_targets_data['-'.join((descriptor,
                                                                    press))]
                            ]))

                        descriptor_data.append(ItemListOverview(targets))

                descriptor_type_data.append(
                    (self.get_descriptor_title(descriptor), descriptor_data))

            out.append((descr_type, descriptor_type_data))

        return out
Exemple #5
0
    def setup_data(self):
        data = self.get_ges_extent_data()

        out = []

        for descr_type, descriptors in DESCRIPTOR_TYPES:
            descriptor_type_data = []

            for descriptor in descriptors:
                descriptor_data = []

                for feature in DESCRIPTORS_FEATURES[descriptor]:
                    feature_data = []

                    for country_id, country_name in self.available_countries:
                        _v = [
                            x.GESExtentUnit for x in data
                            if (x.CountryCode == country_id
                                and x.Feature == feature)
                        ]
                        _vals = Counter(_v)
                        len_v = len(_v)

                        if feature == 'PresEnvNISnew':
                            _vals = [
                                "{0}: {1}".format(k, v)
                                for k, v in _vals.items() if k
                            ]
                        else:
                            _vals = [
                                "{0}: {1} ({2} of {3})".format(
                                    k, int((float(v) / len_v) * 100), v, len_v)
                                for k, v in _vals.items() if k
                            ]

                        feature_data.append(ItemListOverview(_vals))

                    descriptor_data.append(
                        (get_label(feature, 'features'), feature_data))

                descriptor_type_data.append(
                    [self.get_descriptor_title(descriptor), descriptor_data])

            out.append([descr_type, descriptor_type_data])

        return out
Exemple #6
0
    def features(self):
        features = []
        for row in self.feat_pres:
            v = row.FeatureType
            if v:
                features.append(v)

            v = row.PhysicalChemicalHabitatsFunctionalPressures
            features.append(v)

            if 'Other' in v and row.Other:
                o = row.Other
                features.append(o)

        res = [ItemLabel(r, get_label(r, 'features')) for r in set(features)]

        return ItemList(res)
Exemple #7
0
    def setup_data(self):
        # setup data to be available at 'features_pressures_data' attr
        self.get_features_pressures_data()
        data = self.features_pressures_data
        out = []

        for activ_theme, activ_features in self.uses_activities_features:
            activ_features = sorted(
                activ_features,
                key=lambda i: fixedorder_sortkey(i, FEATURES_ORDER))
            theme_data = []

            for activ_feat in activ_features:
                # if activ_feat.endswith('All'):
                #     continue

                activity_data = []

                for country_id, country_name in self.available_countries:
                    pressures = [
                        x[3] for x in data
                        if x[0] == country_id and x[2] == activ_feat
                    ]

                    sorted_press = sorted(
                        set(pressures),
                        key=lambda i: fixedorder_sortkey(i, FEATURES_ORDER))

                    pressures = [
                        ItemLabel(x, self.get_feature_short_name(x))
                        for x in sorted_press
                    ]

                    activity_data.append(
                        ItemListOverview(pressures, sort=False))

                theme_data.append((get_label(activ_feat,
                                             'features'), activity_data))

            out.append((activ_theme, theme_data))

        return out
Exemple #8
0
    def setup_data(self):
        data = self.get_ges_extent_data()

        out = []

        for descr_type, descriptors in DESCRIPTOR_TYPES:
            descriptor_type_data = []

            for descriptor in descriptors:
                descriptor_data = []

                for feature in DESCRIPTORS_FEATURES[descriptor]:
                    feature_data = []

                    for country_id, country_name in self.available_countries:
                        v = [
                            x.GESAchieved for x in data
                            if (x.CountryCode == country_id
                                and x.Feature == feature)
                        ]
                        v = v and v[0] or ''

                        if v == "GES achieved":
                            v = "GES achieved by 2018"

                        feature_data.append(v)

                    descriptor_data.append(
                        (get_label(feature, 'features'), feature_data))

                descriptor_type_data.append(
                    [self.get_descriptor_title(descriptor), descriptor_data])

            out.append([descr_type, descriptor_type_data])

        return out
Exemple #9
0
    def get_label_for_value(self, value):
        label = get_label(value, self.field.label_collection)

        return label