Exemplo n.º 1
0
    def auto_translate(self):
        data = self.get_report_data()
        translatables = self.TRANSLATABLES
        seen = set()

        for compoundrow in data:
            rows = compoundrow.rows

            for row in rows:
                sub_title, values = row

                if compoundrow.field.name in translatables:
                    for indx, value in enumerate(values):
                        if not value:
                            continue

                        if value not in seen:
                            country_code = self.available_countries[indx][0]
                            retrieve_translation(country_code, value)
                            seen.add(value)

        messages = IStatusMessage(self.request)
        messages.add(
            u"Auto-translation initiated, please refresh "
            u"in a couple of minutes",
            type=u"info")

        url = self.context.absolute_url() + '/@@view-report-data-2018'

        return self.request.response.redirect(url)
Exemplo n.º 2
0
    def __call__(self):
        if 'edit-data' in self.request.form:
            url = "{}/edit".format(self._country_folder.absolute_url())
            return self.request.response.redirect(url)

        if 'download_pdf' in self.request.form:
            self.render_header = False

        report_html = self.render_reportdata()
        self.report_html = report_html

        if 'download' in self.request.form:
            return self.download()

        if 'download_pdf' in self.request.form:
            return self.download_pdf()

        if 'translate' in self.request.form:
            for value in self._translatable_values:
                retrieve_translation(self.country_code, value)

            messages = IStatusMessage(self.request)
            messages.add(
                u"Auto-translation initiated, please refresh "
                u"in a couple of minutes",
                type=u"info")

        @timeit
        def render_html():
            return self.index()

        return render_html()
Exemplo n.º 3
0
Arquivo: a11.py Projeto: eea/wise.msfd
    def auto_translate(self):
        try:
            self.setup_data()
        except AssertionError:
            return

        translatables = self.context.TRANSLATABLES
        seen = set()

        for row in self.rows:
            if not row:
                continue

            if row.field.name not in translatables:
                continue

            for value in row.raw_values:
                if not isinstance(value, basestring):
                    continue

                if value not in seen:
                    retrieve_translation(self.country_code, value)
                    seen.add(value)

        return ''
Exemplo n.º 4
0
    def __call__(self):
        # setup national assessment data
        for country_id, country_name in self.available_countries:
            self.setup_descriptor_level_assessment_data(country_id)
            country_data = self.overall_scores
            NATIONAL_ASSESSMENT_DATA[country_id] = country_data

        # setup regional assessment data
        view = RegDescriptorLevelAssessments(self, self.request)
        view.setup_descriptor_level_assessment_data()
        REGIONAL_ASSESSMENT_DATA[self.region_code] = view.overall_scores

        if 'edit-data' in self.request.form:
            url = "{}/edit".format(self.context.absolute_url())
            return self.request.response.redirect(url)

        report_html = self.render_reportdata()
        self.report_html = report_html

        if 'translate' in self.request.form:
            for value in self._translatable_values:
                retrieve_translation(self.country_code, value)

            messages = IStatusMessage(self.request)
            messages.add(
                u"Auto-translation initiated, please refresh "
                u"in a couple of minutes",
                type=u"info")

        @timeit
        def render_html():
            return self.index()

        return render_html()
Exemplo n.º 5
0
    def auto_translate(self):
        self.render_reportdata()
        seen = set()

        all_translatables = (self.translatable_data +
                             self.translatable_extra_data)

        for value in all_translatables:
            if not value:
                continue

            if not isinstance(value, basestring):
                continue

            if value not in seen:
                retrieve_translation(self.country_code, value)
                seen.add(value)

        messages = IStatusMessage(self.request)
        messages.add(
            u"Auto-translation initiated, please refresh "
            u"in a couple of minutes",
            type=u"info")

        url = self.context.absolute_url() + '/@@view-report-data-2018'
        return self.request.response.redirect(url)
Exemplo n.º 6
0
    def auto_translate(self, data=None):
        if not data:
            data = self.get_report_data()

        # report_def = REPORT_DEFS[self.year][self.article]
        # translatables = report_def.get_translatable_fields()
        translatables = self.TRANSLATABLES
        seen = set()

        for table in data:
            muid, table_data = table

            for row in table_data:
                field, cells = row
                if field.name in translatables:
                    for value in cells:
                        if value not in seen:
                            retrieve_translation(self.country_code, value)
                            seen.add(value)

        messages = IStatusMessage(self.request)
        messages.add(
            u"Auto-translation initiated, please refresh "
            u"in a couple of minutes",
            type=u"info")

        url = self.context.absolute_url() + '/@@view-report-data-2018'
        return self.request.response.redirect(url)
Exemplo n.º 7
0
Arquivo: a11.py Projeto: eea/wise.msfd
    def auto_translate(self):
        try:
            self.setup_data()
        except AssertionError:
            return

        translatables = self.context.TRANSLATABLES
        seen = set()

        # initiate translation for 2014 data
        for row in self.rows:
            if not row:
                continue

            if row.title not in translatables:
                continue

            for value in row.raw_values:
                if not isinstance(value, basestring):
                    continue

                if value not in seen:
                    retrieve_translation(self.country_code, value)
                    seen.add(value)

        # initiate translation for 2020 data
        for row in self.data_2020[0][1]:
            field = row[0]

            if field.title not in translatables:
                continue

            values = row[1]

            for value in values:
                if not isinstance(value, basestring):
                    continue

                if value not in seen:
                    retrieve_translation(self.country_code, value)
                    seen.add(value)

        return ''
Exemplo n.º 8
0
Arquivo: a10.py Projeto: eea/wise.msfd
    def auto_translate(self):
        # report_def = REPORT_DEFS[self.year][self.article]
        # translatables = report_def.get_translatable_fields()

        self.setup_data()

        translatables = self.context.TRANSLATABLES
        seen = set()

        for item in self.cols:
            for k in translatables:
                value = item[k]
                if not isinstance(value, basestring):
                    continue

                if value not in seen:
                    retrieve_translation(self.country_code, value)
                    seen.add(value)

        return ''
Exemplo n.º 9
0
    def auto_translate(self):
        self.setup_data()
        translatables = self.context.TRANSLATABLES
        seen = set()

        for table in self.rows.items():
            muid, table_data = table

            for row in table_data:
                if not row:
                    continue
                if row.title not in translatables:
                    continue

                for value in row.raw_values:
                    if not isinstance(value, basestring):
                        continue
                    if value not in seen:
                        retrieve_translation(self.country_code, value)
                        seen.add(value)

        return ''
Exemplo n.º 10
0
    def get_data(self):
        mapper_class = sql2018.MRUsPublication
        res = []

        # for better query speed we get only these columns
        col_names = ('Country', 'rZoneId', 'thematicId', 'nameTxtInt',
                     'nameText', 'spZoneType', 'legisSName', 'Area')
        columns = [getattr(mapper_class, name) for name in col_names]

        count, data = db.get_all_specific_columns(
            columns, mapper_class.Country == self.country_code)

        for row in data:
            description = row.nameTxtInt or row.nameText or ""
            translation = get_translated(description, self.country_code) or ""
            if not translation:
                retrieve_translation(self.country_code, description)

            self._translatable_values.append(description)

            res.append((row.rZoneId, row.spZoneType, row.thematicId,
                        description, translation))

        return res
Exemplo n.º 11
0
    def get_data(self):
        mapper_class = sql2018.MRUsPublication
        mc_mru_descr = sql2018.MarineReportingUnit
        data = _4GEO_DATA
        data_filtered = [
            row for row in data if row.MemberState == self.country_code
        ]

        # for better query speed we get only these columns
        col_names = ('Country', 'rZoneId', 'thematicId', 'nameTxtInt',
                     'nameText', 'spZoneType', 'legisSName', 'Area')
        columns = [getattr(mapper_class, name) for name in col_names]

        _, data_db = db.get_all_specific_columns(
            columns, mapper_class.Country == self.country_code)

        res = []

        _, art8_data = db.get_all_specific_columns([
            sql2018.t_V_ART8_GES_2018.c.MarineReportingUnit,
            sql2018.t_V_ART8_GES_2018.c.GESComponent
        ], sql2018.t_V_ART8_GES_2018.c.CountryCode == self.country_code)
        _, art9_data = db.get_all_specific_columns([
            sql2018.t_V_ART9_GES_2018.c.MarineReportingUnit,
            sql2018.t_V_ART9_GES_2018.c.GESComponent
        ], sql2018.t_V_ART9_GES_2018.c.CountryCode == self.country_code)
        art8_art9_data = set(art8_data + art9_data)

        for row in data_filtered:
            # if row.Status == 'Not used':
            #     continue

            description = row.MRUName
            mru_id = self.norm_mru_id(row.MRUID)
            translation = get_translated(description, self.country_code) or ''
            area = row.MRUArea and int(round(row.MRUArea)) or 0

            if not area:
                area = [x.Area for x in data_db if x.thematicId == mru_id]
                area = area and int(round(area[0])) or 0

            if not translation:
                retrieve_translation(self.country_code, description)

            self._translatable_values.append(description)

            # prop_water = int(round((area / marine_waters_total) * 100))
            prop_water = (row.MRUCoverage
                          and "{0:.1f}".format(float(row.MRUCoverage)) or 0)

            if not prop_water:
                mw_total = [
                    x.MarineWatersArea for x in data_filtered
                    if x.MarineWatersArea
                ]
                mw_total = mw_total and mw_total[0] or 0
                prop_water = int(round((area / mw_total) * 100))

            descr_list = set([x[1] for x in art8_art9_data if x[0] == mru_id])
            descr_list = sorted(descr_list, key=natural_sort_key)
            descr_list_norm = []

            for d in descr_list:
                try:
                    desc = get_descriptor(d).template_vars['title']
                except:
                    desc = d

                descr_list_norm.append(desc)

            descriptors = ', '.join(descr_list_norm)

            res.append(
                (row.MarineRegion, row.AssessmentArea, mru_id, description,
                 translation, '{:,}'.format(area), prop_water, descriptors))

        return res
Exemplo n.º 12
0
    def get_data_old(self):
        mapper_class = sql2018.MRUsPublication
        mc_mru_descr = sql2018.MarineReportingUnit
        res = []

        marine_waters_data = self.context._get_marine_waters_data()
        marine_waters_total = sum(
            [x[2] for x in marine_waters_data if x[0] == self.country_code])

        # for better query speed we get only these columns
        col_names = ('Country', 'rZoneId', 'thematicId', 'nameTxtInt',
                     'nameText', 'spZoneType', 'legisSName', 'Area')
        columns = [getattr(mapper_class, name) for name in col_names]

        count, data = db.get_all_specific_columns(
            columns, mapper_class.Country == self.country_code)
        mrus_needed = [x.thematicId for x in data]

        _, mru_descriptions = db.get_all_specific_columns([
            mc_mru_descr.MarineReportingUnitId, mc_mru_descr.Description,
            mc_mru_descr.nameTxtInt, mc_mru_descr.nameText
        ], mc_mru_descr.MarineReportingUnitId.in_(mrus_needed))

        _, art8_data = db.get_all_specific_columns([
            sql2018.t_V_ART8_GES_2018.c.MarineReportingUnit,
            sql2018.t_V_ART8_GES_2018.c.GESComponent
        ], sql2018.t_V_ART8_GES_2018.c.CountryCode == self.country_code)
        _, art9_data = db.get_all_specific_columns([
            sql2018.t_V_ART9_GES_2018.c.MarineReportingUnit,
            sql2018.t_V_ART9_GES_2018.c.GESComponent
        ], sql2018.t_V_ART9_GES_2018.c.CountryCode == self.country_code)
        art8_art9_data = set(art8_data + art9_data)

        for row in data:
            mru = row.thematicId
            description = [
                x.Description
                # (x.nameTxtInt is not None and x.nameTxtInt.strip()
                #  or x.nameText or "")
                for x in mru_descriptions if x.MarineReportingUnitId == mru
            ]
            if not description:
                description = row.nameTxtInt or row.nameText or ""
            else:
                description = description[0]

            translation = get_translated(description, self.country_code) or ""
            area = int(round(row.Area))

            if not translation:
                retrieve_translation(self.country_code, description)

            self._translatable_values.append(description)

            prop_water = int(round((area / marine_waters_total) * 100))

            descr_list = set(
                [x[1] for x in art8_art9_data if x[0] == row.thematicId])
            descr_list = sorted(descr_list, key=natural_sort_key)
            descr_list_norm = []

            for d in descr_list:
                try:
                    desc = get_descriptor(d).template_vars['title']
                except:
                    desc = d

                descr_list_norm.append(desc)

            descriptors = ', '.join(descr_list_norm)

            res.append(
                (row.rZoneId, row.spZoneType, mru, description, translation,
                 '{:,}'.format(area), prop_water, descriptors))

        return res