<commit_before># -*- coding: utf-8 -*-

"""Akvo RSR is covered by the GNU Affero General Public License.

See more details in the license.txt file located at the root folder of the
Akvo RSR module. For additional details on the GNU license please
see < http://www.gnu.org/licenses/agpl.html >.
"""

from akvo.rsr.models import IndicatorPeriod, ProjectHierarchy
from akvo.rsr.models.result.utils import PERCENTAGE_MEASURE
from akvo.rsr.decorators import with_download_indicator
from datetime import datetime
from django.contrib.auth.decorators import login_required
from django.db.models import Count
from django.shortcuts import get_object_or_404
from pyexcelerate import Workbook, Style, Font, Color, Fill, Alignment
from pyexcelerate.Borders import Borders
from pyexcelerate.Border import Border

from . import utils


def build_view_object(organisation):
    project_ids = organisation.all_projects()\
        .annotate(results_count=Count('results'))\
        .filter(results_count__gt=0)\
        .values_list('pk', flat=True)

    periods = IndicatorPeriod.objects\
        .select_related('indicator', 'indicator__result', 'indicator__result__project')\
        .filter(indicator__result__project__in=project_ids)\
        .exclude(indicator__result__type__iexact='')\
        .order_by('indicator__result__project__iati_activity_id')

    return utils.make_project_proxies(periods)


@login_required
@with_download_indicator
def render_report(request, program_id):
    queryset = ProjectHierarchy.objects.prefetch_related('organisation')
    project_hierarchy = get_object_or_404(queryset, root_project=program_id)
    organisation = project_hierarchy.organisation
    projects = build_view_object(organisation)

    wb = Workbook()
    ws = wb.new_sheet('ProjectList')
    ws.set_col_style(1, Style(size=81.5))
    ws.set_col_style(2, Style(size=33.5))
    ws.set_col_style(3, Style(size=7.67))
    ws.set_col_style(4, Style(size=21.17))
    ws.set_col_style(5, Style(size=20.67))
    ws.set_col_style(6, Style(size=19))
    ws.set_col_style(7, Style(size=18.17))
    ws.set_col_style(8, Style(size=33.5))
    ws.set_col_style(9, Style(size=21))
    ws.set_col_style(10, Style(size=14.83))
    ws.set_col_style(11, Style(size=33.5))
    ws.set_col_style(12, Style(size=23.17))
    ws.set_col_style(13, Style(size=10.5))
    ws.set_col_style(14, Style(size=14))
    ws.set_col_style(15, Style(size=16.67))
    ws.set_col_style(16, Style(size=19.5))
    ws.set_col_style(17, Style(size=34.33))
    ws.set_col_style(18, Style(size=15.67))
    ws.set_col_style(19, Style(size=15.67))
    ws.set_col_style(20, Style(size=22.33))
    ws.set_col_style(21, Style(size=25))
    ws.set_col_style(22, Style(size=17.5))
    ws.set_col_style(23, Style(size=20.83))
    ws.set_col_style(24, Style(size=9.67))<commit_msg>Fix EUTF org export report<commit_after># -*- coding: utf-8 -*-

"""Akvo RSR is covered by the GNU Affero General Public License.

See more details in the license.txt file located at the root folder of the
Akvo RSR module. For additional details on the GNU license please
see < http://www.gnu.org/licenses/agpl.html >.
"""

from akvo.rsr.models import IndicatorPeriod, ProjectHierarchy
from akvo.rsr.models.result.utils import PERCENTAGE_MEASURE
from akvo.rsr.decorators import with_download_indicator
from datetime import datetime
from django.contrib.auth.decorators import login_required
from django.db.models import Count
from django.shortcuts import get_object_or_404
from pyexcelerate import Workbook, Style, Font, Color, Fill, Alignment
from pyexcelerate.Borders import Borders
from pyexcelerate.Border import Border

from . import utils


def build_view_object(organisation):
    project_ids = organisation.all_projects()\
        .annotate(results_count=Count('results'))\
        .filter(results_count__gt=0)\
        .values_list('pk', flat=True)

    periods = IndicatorPeriod.objects\
        .select_related('indicator', 'indicator__result', 'indicator__result__project')\
        .filter(indicator__result__project__in=project_ids)\
        .exclude(indicator__result__type__iexact='')\
        .order_by('indicator__result__project__iati_activity_id')

    return utils.make_project_proxies(periods)


@login_required
@with_download_indicator
def render_report(request, program_id):
    project_hierarchy = get_object_or_404(ProjectHierarchy, root_project=program_id)
    organisation = project_hierarchy.organisation
    projects = build_view_object(organisation)

    wb = Workbook()
    ws = wb.new_sheet('ProjectList')
    ws.set_col_style(1, Style(size=81.5))
    ws.set_col_style(2, Style(size=33.5))
    ws.set_col_style(3, Style(size=7.67))
    ws.set_col_style(4, Style(size=21.17))
    ws.set_col_style(5, Style(size=20.67))
    ws.set_col_style(6, Style(size=19))
    ws.set_col_style(7, Style(size=18.17))
    ws.set_col_style(8, Style(size=33.5))
    ws.set_col_style(9, Style(size=21))
    ws.set_col_style(10, Style(size=14.83))
    ws.set_col_style(11, Style(size=33.5))
    ws.set_col_style(12, Style(size=23.17))
    ws.set_col_style(13, Style(size=10.5))
    ws.set_col_style(14, Style(size=14))
    ws.set_col_style(15, Style(size=16.67))
    ws.set_col_style(16, Style(size=19.5))
    ws.set_col_style(17, Style(size=34.33))
    ws.set_col_style(18, Style(size=15.67))
    ws.set_col_style(19, Style(size=15.67))
    ws.set_col_style(20, Style(size=22.33))
    ws.set_col_style(21, Style(size=25))
    ws.set_col_style(22, Style(size=17.5))
    ws.set_col_style(23, Style(size=20.83))
    ws.set_col_style(24, Style(size=9.67))
{'fraction_non_alphanumeric': 0.12029401219074937, 'fraction_numerical': 0.045177482968806026, 'mean_word_length': 4.787344398340249, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6614006', 'n_tokens_mistral': 2176, 'n_tokens_neox': 1993, 'n_words': 349}