Beispiel #1
0
    def get_related(table, attr, title):
        if attr == "bra":
            data_attr = category
        else:
            data_attr = attr
        if data_attr == "hs" or data_attr == "wld":
            dataset = "secex"
        elif data_attr == "cnae" or data_attr == "cbo":
            dataset = "rais"
        elif data_attr == "university" or data_attr == "course_hedu":
            dataset = "hedu"
        elif data_attr == "course_sc":
            dataset = "sc"
        else:
            return
        q = table.query.filter(getattr(table, "{}_id".format(category)) == id) \
                 .filter(getattr(table, "year") == parse_year(__year_range__[dataset][1]))

        if category in ("bra"):
            q = q.filter(not_(getattr(table, "{}_id_target".format(category)).startswith("0xx")))
        elif category in ("cnae", "cbo", "wld"):
            q = q.filter(not_(getattr(table, "{}_id_target".format(category)).startswith("xx")))
        elif category in ("hs"):
            q = q.filter(not_(getattr(table, "{}_id_target".format(category)).startswith("22")))
        elif category in ("course_hedu", "course_sc"):
            q = q.filter(not_(getattr(table, "{}_id_target".format(category)).startswith("00")))

        q = q.order_by(getattr(table, "prox_{}".format(attr)).desc()).limit(40).all()
        if len(q) > 0:
            m = globals()[category.capitalize()]
            q = [(m.query.get(getattr(a, "{}_id_target".format(category))), getattr(a, "prox_{}".format(attr))) for a in q]
            related.append({"title": title, "pages": q})
Beispiel #2
0
def index():

    profile_types = []

    # Bra
    most_recent_year = parse_year(__year_range__["secex"][-1])
    top = Ymb.query.filter_by(year=most_recent_year, month=0, bra_id_len=9).order_by(Ymb.export_val.desc()).limit(5).all()
    top = [t.bra for t in top]
    profile_types.append({
        "summary": gettext("Showing exports, employment and education data, statistics and visualizations about the chosen Brazilian location."),
        "top": top,
        "title": gettext(u"Brazilian Locations"),
        "type": "bra"
    })

    # Occupations
    most_recent_year = parse_year(__year_range__["rais"][-1])
    top = Yo.query.filter_by(year=most_recent_year, cbo_id_len=4).order_by(Yo.num_jobs.desc()).limit(5).all()
    top = [t.cbo for t in top]
    profile_types.append({
        "summary": gettext("Showing industries and locations that employ the selected occupation."),
        "top": top,
        "title": gettext(u"Occupations"),
        "type": "cbo"
    })

    # Industries
    top = Yi.query.filter_by(year=most_recent_year, cnae_id_len=6).order_by(Yi.num_jobs.desc()).limit(5).all()
    top = [t.cnae for t in top]
    profile_types.append({
        "summary": gettext("Showing the occupations and locations with jobs in the selected industry."),
        "top": top,
        "title": gettext(u"Industries"),
        "type": "cnae"
    })

    # Prods
    most_recent_year = parse_year(__year_range__["secex"][-1])
    top = Ymp.query.filter_by(year=most_recent_year, month=0, hs_id_len=6).order_by(Ymp.export_val.desc()).limit(5).all()
    top = [t.hs for t in top]
    profile_types.append({
        "summary": gettext("Showing locations in Brazil that export and import the selected product and their destinations and origins."),
        "top": top,
        "title": gettext(u"Products"),
        "type": "hs"
    })

    # Countries
    top = Ymw.query.filter_by(year=most_recent_year, month=0, wld_id_len=5).order_by(Ymw.export_val.desc()).limit(5).all()
    top = [t.wld for t in top]
    profile_types.append({
        "summary": gettext("Showing locations in brazil that trade with the selected country and the products they export and import from them."),
        "top": top,
        "title": gettext(u"Trade Partners"),
        "type": "wld"
    })

    # Universities
    most_recent_year = parse_year(__year_range__["hedu"][-1])
    top = Yu.query.filter_by(year=most_recent_year).order_by(Yu.enrolled.desc()).limit(5).all()
    top = [t.university for t in top]
    profile_types.append({
        "summary": gettext("Showing the majors found in the selected univserity."),
        "top": top,
        "title": gettext(u"Universities"),
        "type": "university"
    })

    # Majors
    top = Yc_hedu.query.filter_by(year=most_recent_year).order_by(Yc_hedu.enrolled.desc()).limit(5).all()
    top = [t.course_hedu for t in top]
    profile_types.append({
        "summary": gettext("Showing the university and locations in Brazil where the selected major is found."),
        "top": top,
        "title": gettext(u"Majors"),
        "type": "course_hedu"
    })

    # Vocations
    most_recent_year = parse_year(__year_range__["sc"][-1])
    top = Yc_sc.query.filter_by(year=most_recent_year, course_sc_id_len=5).order_by(Yc_sc.enrolled.desc()).filter(~Yc_sc.course_sc_id.startswith('xx')).limit(5).all()
    top = [t.course_sc for t in top]
    profile_types.append({
        "summary": gettext("Showing the locations and schools in which these basic courses are taught."),
        "top": top,
        "title": gettext(u"Basic Courses"),
        "type": "course_sc"
    })

    return render_template("profiles/index.html", profile_types=profile_types)