<commit_before># -*- coding: utf-8 -*-
from flask import Blueprint, render_template, g
from dataviva.apps.general.views import get_locale
from dataviva.api.attrs.models import School, Bra
from dataviva.api.sc.models import Yc_sc, Ysc, Ybc_sc, Ybsc
from dataviva import db
from sqlalchemy import func, desc

mod = Blueprint('basic_course', __name__,
                template_folder='templates',
                url_prefix='/<lang_code>/basic_course',
                static_folder='static')


@mod.url_value_preprocessor
def pull_lang_code(endpoint, values):
    g.locale = values.pop('lang_code')


@mod.url_defaults
def add_language_code(endpoint, values):
    values.setdefault('lang_code', get_locale())


@mod.route('/')
def index():

    course_sc_id = 'xx006'
    bra_id = '1ac'
    course = {}    
    school = {}
    city = {}

    if bra_id:

        max_year_subquery = db.session.query(
            func.max(Ybc_sc.year)).filter_by(course_sc_id=course_sc_id,bra_id=bra_id)

        ybsc_max_year_subquery = db.session.query(
            func.max(Ybsc.year)).filter_by(course_sc_id=course_sc_id,bra_id=bra_id)

        ybc_query = Ybc_sc.query.filter(Ybc_sc.course_sc_id == course_sc_id,
                                      Ybc_sc.year == max_year_subquery,
                                      Ybc_sc.bra_id == bra_id)

        ybsc_query = Ybsc.query.filter(Ybsc.course_sc_id == course_sc_id,
                                     Ybsc.year == ybsc_max_year_subquery,
                                     Ybsc.bra_id == bra_id)

        course['schools_count'] = ybsc_query.count()

        ybc_data = ybc_query.values(Ybc_sc.classes,
                                   Ybc_sc.age,
                                   Ybc_sc.enrolled,
                                   Ybc_sc.year)

        for classes, age, enrolled, year in ybc_data:
            course['classes'] = classes
            course['age'] = age
            course['enrolled'] = enrolled
            course['average_class_size'] = enrolled / classes
            course['year'] = year

        school_max_enrolled_query = db.session.query(Ybsc, School).filter(Ybsc.school_id == School.id) \
                                        .filter(Ybsc.course_sc_id == course_sc_id,
                                        Ybsc.year == max_year_subquery,
                                        Ybsc.bra_id == bra_id).order_by(Ybsc.enrolled)

        school_data = school_max_enrolled_query.values(School.name_pt,
                                                        Ybsc.enrolled)

        for name_pt, enrolled in school_data:
            school['name'] = name_pt
            school['enrolled'] = enrolled


        city_max_enrolled_query = db.session.query(Ybc_sc, Bra).filter(Ybc_sc.bra_id == Bra.id) \
                                        .filter(Ybc_sc.course_sc_id == course_sc_id,
                                        Ybc_sc.year == max_year_subquery,
                                        Ybc_sc.bra_id_len == 9,
                                        Ybc_sc.bra_id.like(str(bra_id)+'%')).order_by(Ybc_sc.enrolled)

        city_data = city_max_enrolled_query.values(Bra.name_pt,
                                                        Ybc_sc.enrolled)

        for name_pt, enrolled in city_data:
            city['name'] = name_pt
            city['enrolled'] = enrolled

    else:
<commit_msg>Now the view is retrieving the course name and description from database.<commit_after># -*- coding: utf-8 -*-
from flask import Blueprint, render_template, g
from dataviva.apps.general.views import get_locale
from dataviva.api.attrs.models import School, Bra, Course_sc
from dataviva.api.sc.models import Yc_sc, Ysc, Ybc_sc, Ybsc
from dataviva import db
from sqlalchemy import func, desc

mod = Blueprint('basic_course', __name__,
                template_folder='templates',
                url_prefix='/<lang_code>/basic_course',
                static_folder='static')


@mod.url_value_preprocessor
def pull_lang_code(endpoint, values):
    g.locale = values.pop('lang_code')


@mod.url_defaults
def add_language_code(endpoint, values):
    values.setdefault('lang_code', get_locale())


@mod.route('/')
def index():

    course_sc_id = 'xx006'
    bra_id = '1ac'
    course = {}    
    school = {}
    city = {}

    if bra_id:

        max_year_subquery = db.session.query(
            func.max(Ybc_sc.year)).filter_by(course_sc_id=course_sc_id,bra_id=bra_id)

        ybsc_max_year_subquery = db.session.query(
            func.max(Ybsc.year)).filter_by(course_sc_id=course_sc_id,bra_id=bra_id)

        ybc_query = Ybc_sc.query.join(Course_sc).filter(Ybc_sc.course_sc_id == course_sc_id,
                                                        Ybc_sc.year == max_year_subquery,
                                                        Ybc_sc.bra_id == bra_id)

        ybsc_query = Ybsc.query.filter(Ybsc.course_sc_id == course_sc_id,
                                       Ybsc.year == ybsc_max_year_subquery,
                                       Ybsc.bra_id == bra_id)

        course['schools_count'] = ybsc_query.count()

        ybc_data = ybc_query.values(Course_sc.name_pt,
                                    Course_sc.desc_pt,
                                    Ybc_sc.classes,
                                    Ybc_sc.age,
                                    Ybc_sc.enrolled,
                                    Ybc_sc.year)

        for name_pt, desc_pt, classes, age, enrolled, year in ybc_data:
            course['name'] = name_pt
            course['description'] = desc_pt or 'Não há descrição para este curso.'
            course['classes'] = classes
            course['age'] = age
            course['enrolled'] = enrolled
            course['average_class_size'] = enrolled / classes
            course['year'] = year
        
        course['enrollment_statistics_description'] = desc_pt or 'Enrollment Statistics Description'

        school_max_enrolled_query = db.session.query(Ybsc, School).filter(Ybsc.school_id == School.id) \
                                        .filter(Ybsc.course_sc_id == course_sc_id,
                                        Ybsc.year == max_year_subquery,
                                        Ybsc.bra_id == bra_id).order_by(Ybsc.enrolled)

        school_data = school_max_enrolled_query.values(School.name_pt,
                                                       Ybsc.enrolled)

        for name_pt, enrolled in school_data:
            school['name'] = name_pt
            school['enrolled'] = enrolled

        city_max_enrolled_query = db.session.query(Ybc_sc, Bra).filter(Ybc_sc.bra_id == Bra.id) \
                                        .filter(Ybc_sc.course_sc_id == course_sc_id,
                                        Ybc_sc.year == max_year_subquery,
                                        Ybc_sc.bra_id_len == 9,
                                        Ybc_sc.bra_id.like(str(bra_id)+'%')).order_by(Ybc_sc.enrolled)

        city_data = city_max_enrolled_query.values(Bra.name_pt,
                                                   Ybc_sc.enrolled)

        for name_pt, enrolled in city_data:
            city['name'] = name_pt
            city['enrolled'] = enrolled

    else:

{'fraction_non_alphanumeric': 0.0947455523376086, 'fraction_numerical': 0.0016549441456350847, 'mean_word_length': 1.6361323155216285, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '110053', 'n_tokens_mistral': 2200, 'n_tokens_neox': 2111, 'n_words': 343}