Skip to content

Commit

Permalink
Merge pull request #1581 from DataViva/fix/remove-old-charts
Browse files Browse the repository at this point in the history
Fix/remove old charts
  • Loading branch information
diogolundberg authored Apr 25, 2018
2 parents bb4248d + e14d559 commit 5532478
Show file tree
Hide file tree
Showing 309 changed files with 12,477 additions and 2,489 deletions.
99 changes: 99 additions & 0 deletions dataviva/api/attrs/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import gzip
import json
import requests
from StringIO import StringIO

from sqlalchemy import func, asc, desc, and_
Expand Down Expand Up @@ -493,6 +494,104 @@ def trade_partner():
status=(200 if returned_entries.count() else 404)
)

@mod.route('/health_region/')
@view_cache.cached(key_prefix=api_cache_key("attrs_health_region"))
def health_region():
r = requests.get('http://api.staging.dataviva.info/metadata/health_region')
data = []
response = r.json()
lang = request.args.get('lang', 'pt')

for key in response:
region = {}
region['id'] = key
region['name'] = response[key]['name_' + lang]
region['color'] = '-'
data.append(region)

return Response(
json.dumps({'data': data}),
status=200
)

@mod.route('/demographic_information/<attr>/')
@view_cache.cached(key_prefix=api_cache_key("attrs_demographic_information"))
def demographic_information(attr):
r = requests.get('http://api.staging.dataviva.info/metadata/' + attr)
data = []
response = r.json()
lang = request.args.get('lang', 'pt')

for key in response:
region = {}
region['id'] = key
region['name'] = response[key]['name_' + lang]
data.append(region)

return Response(
json.dumps({'data': data}),
status=200
)

@mod.route('/establishment_information/<attr>/')
@view_cache.cached(key_prefix=api_cache_key("attrs_establishment_information"))
def establishment_information(attr):
r = requests.get('http://api.staging.dataviva.info/metadata/' + attr)
data = []
response = r.json()
lang = request.args.get('lang', 'pt')

for key in response:
region = {}
region['id'] = key
region['name'] = response[key]['name_' + lang]
data.append(region)

return Response(
json.dumps({'data': data}),
status=200
)


@mod.route('/datasus/<attr>/')
@view_cache.cached(key_prefix=api_cache_key("attrs_datasus"))
def datasus(attr):
r = requests.get('http://api.staging.dataviva.info/metadata/' + attr)
data = []
response = r.json()
lang = request.args.get('lang', 'pt')

for key in response:
region = {}
region['id'] = key
region['name'] = response[key]['name_' + lang]
data.append(region)

return Response(
json.dumps({'data': data}),
status=200
)


@mod.route('/port/')
# @view_cache.cached(key_prefix=api_cache_key("attrs_port"))
def port():
r = requests.get('http://api.staging.dataviva.info/metadata/port')
data = []
response = r.json()
lang = request.args.get('lang', 'pt')

for key in response:
region = {}
region['id'] = key
region['name'] = response[key]['name_' + lang]
data.append(region)

return Response(
json.dumps({'data': data}),
status=200
)


@mod.route('/datasets/')
def datasets():
Expand Down
Empty file added dataviva/apps/bar/__init__.py
Empty file.
36 changes: 36 additions & 0 deletions dataviva/apps/bar/templates/bar/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!doctype html>
<html lang="{{ g.locale }}">
<head>
<meta charset="utf-8">
{% include "graphs/css_assets.html" %}
{% include "graphs/js_assets.html" %}
</style>
</head>
<body>
{% include "graphs/tools.html" %}
<div class="embed-responsive responsive-wrapper graph-wrapper">
<div id="bar"
class="embed-responsive responsive-wrapper"
dataset="{{dataset}}"
x="{{x}}"
y="{{y}}"
options="{{options}}"
subtitle="{{subtitle}}"
graph-title="{{graph_title}}"
graph-subtitle="{{graph_subtitle}}"
filters="{{filters}}">
</div>
</div>
<div id="controls"></div>

<div id="mask" class="loading"></div>

<script type="text/javascript">
var dictionary = {{ dictionary|safe }};
</script>
<script type="text/javascript" src="/static/js/modules/dictionary.js"></script>
<script type="text/javascript" src="/static/js/graphs/helper.js"></script>
<script type="text/javascript" src="/static/js/modules/bar.js"></script>
<script type="text/javascript" src="/static/js/graphs/tools.js"></script>
</body>
</html>
135 changes: 135 additions & 0 deletions dataviva/apps/bar/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# -*- coding: utf-8 -*-
from flask import Blueprint, render_template, g, request, abort
from dataviva.apps.general.views import get_locale
from dataviva.translations.dictionary import dictionary
from dataviva.apps.title.views import get_title
import urllib
import json

mod = Blueprint('bar', __name__,
template_folder='templates',
url_prefix='/<lang_code>/bar',
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.before_request
def before_request():
g.page_type = mod.name


def location_service(id_ibge):
locations = {
1: "region", #todo
2: "state",
4: "mesoregion",
5: "microregion",
7: "municipality"
}

return (locations[len(id_ibge)], id_ibge)


def product_service(product):
if len(product) == 2:
return ('product_section', product[:2])
elif len(product) == 4:
return ('product_chapter', product[2:4])
else:
return ('product', product[2:])

def wld_service(wld):
if wld.isdigit():
wld = '%03d' % int(wld)

wlds = {
2: "continent",
3: "country"
}

return (wlds[len(wld)], wld)

def occupation_service(occupation):
occupations = {
1: "occupation_group",
4: "occupation_family"
}

return (occupations[len(occupation)], occupation)

def industry_service(industry):
if len(industry) == 1:
return ('industry_section', industry)
elif len(industry) == 3:
return ('industry_division', industry[1:])
else:
return ('industry_class', industry[1:])


@mod.route('/<dataset>/<x>/<y>')
def index(dataset, x, y):
product = request.args.get('product')
id_ibge = request.args.get('id_ibge')
type = request.args.get('type')
wld = request.args.get('wld')
establishment = request.args.get('establishment')
occupation = request.args.get('occupation')
industry = request.args.get('industry')
counts = request.args.getlist('count')

title_attrs = {}

options = request.args.get('options')
subtitle = request.args.get('subtitle', '')

filters = []

for count in counts:
filters.append(('count', count))

if type:
filters.append(('type', type))
title_attrs['type'] = type

if request.args.get('filters'):
filters.append(('filters', request.args.get('filters')))

if wld:
filters.append(wld_service(wld))
title_attrs[wld_service(wld)[0]] = wld_service(wld)[1]

if occupation:
filters.append(occupation_service(occupation))
title_attrs[occupation_service(occupation)[0]] = occupation_service(occupation)[1]

if industry:
filters.append(industry_service(industry))
title_attrs[industry_service(industry)[0]] = industry_service(industry)[1]

if product:
filters.append(product_service(product))
title_attrs[product_service(product)[0]] = product_service(product)[1]

if id_ibge:
filters.append(location_service(id_ibge))
title_attrs[location_service(id_ibge)[0]] = location_service(id_ibge)[1]

if establishment:
filters.append(('establishment', establishment))

filters = urllib.urlencode(filters)
graph_title, graph_subtitle = get_title(dataset, y.split(',')[0], 'bar', title_attrs)

return render_template('bar/index.html', dataset=dataset, x=x, y=y, filters=filters, options=options,
subtitle=subtitle, graph_title=graph_title or '', graph_subtitle=graph_subtitle or '',
dictionary=json.dumps(dictionary()))

Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,60 @@ <h4>{%trans%}Enrollments By{%endtrans%}</h4>
{% if location.id | length != 9 %}
<a href="#enrollments-basic-course" class="list-group-item" data-toggle="collapse" data-parent="#enrollments-basic-course">{%trans%}Municipality{%endtrans%}</a>
<div class="collapse" id="enrollments-municipality">
<a href="/{{ g.locale }}/embed/geo_map/sc/{{ location.id if location else 'all' }}/all/{{basic_course.id}}/bra/?color=enrolled"
<!-- <a href="/{{ g.locale }}/embed/geo_map/sc/{{ location.id if location else 'all' }}/all/{{basic_course.id}}/bra/?color=enrolled"
target="graphs-frame-enrollments" class="list-group-item {{'selected' if graph.menu == 'enrollments-municipality-geo_map' or not graph }}" data-parent="#enrollments-municipality">
{% trans %}Map{% endtrans %}
</a> -->
<a href="/{{ g.locale }}/map/sc/students/{{ id_ibge if id_ibge }}?values=students&basic_course={{basic_course.id}}&colors=students+classes+average_class_size"
target="graphs-frame-enrollments" class="list-group-item {{'selected' if graph.menu == 'enrollments-municipality-map_new_api' or not graph}}" data-parent="#enrollments-municipality">
{% trans %}Map{% endtrans %}
</a>
<a href="/{{ g.locale }}/embed/stacked/sc/{{ location.id if location else 'all' }}/all/{{basic_course.id}}/bra/?y=enrolled&layout=value&order=color"
<!-- <a href="/{{ g.locale }}/embed/stacked/sc/{{ location.id if location else 'all' }}/all/{{basic_course.id}}/bra/?y=enrolled&layout=value&order=color"
target="graphs-frame-enrollments" class="list-group-item {{'selected' if graph.menu == 'enrollments-municipality-stacked'}}" data-parent="#enrollments-municipality">
{% trans %}Stacked{% endtrans %}</a>
</a> -->
<a href="/{{ g.locale }}/stacked/sc/region/students?values=students+classes+average_class_size&depths=region+state+mesoregion+microregion+municipality&depth=state&order=region&basic_course={{basic_course.id}}"
target="graphs-frame-enrollments" class="list-group-item {{'selected' if graph.menu == 'enrollments-municipality-stacked_new_api'}}" data-parent="#enrollments-municipality">
{% trans %}Stacked{% endtrans %}</a>
</a>
<a href="/{{ g.locale }}/embed/tree_map/sc/{{ location.id if location else 'all' }}/all/{{basic_course.id}}/bra/?color=color&depth=bra_9&size=enrolled"
<!-- <a href="/{{ g.locale }}/embed/tree_map/sc/{{ location.id if location else 'all' }}/all/{{basic_course.id}}/bra/?color=color&depth=bra_9&size=enrolled"
target="graphs-frame-enrollments" class="list-group-item {{'selected' if graph.menu == 'enrollments-municipality-tree_map'}}" data-parent="#enrollments-municipality">
TreeMap
</a> -->
<a href="/{{ g.locale }}/tree_map/sc/municipality/students?sizes=students+classes&colors=students+average_age&basic_course={{ basic_course.id }}{{ '&id_ibge=%s' % id_ibge if id_ibge }}"
target="graphs-frame-enrollments" class="list-group-item {{'selected' if graph.menu == 'enrollments-municipality-tree_map_new_api' }}" data-parent="#enrollments-municipality">
TreeMap
</a>
</div>
{% endif %}
{% if location.id %}
<a href="#enrollments-school" class="list-group-item" data-toggle="collapse" data-parent="#enrollments-school">{%trans%}School{%endtrans%}</a>
<div class="collapse" id="enrollments-school">
<a href="/{{ g.locale }}/embed/tree_map/sc/{{ location.id if location else 'all' }}/all/{{basic_course.id}}/school/?color=color&depth=school_8&size=enrolled"
<!-- <a href="/{{ g.locale }}/embed/tree_map/sc/{{ location.id if location else 'all' }}/all/{{basic_course.id}}/school/?color=color&depth=school_8&size=enrolled"
target="graphs-frame-enrollments" class="list-group-item {{'selected' if graph.menu == 'enrollments-school-tree_map'}}" data-parent="#enrollments-school">
TreeMap
</a> -->
<a href="/{{ g.locale }}/tree_map/sc/sc_school/students?sizes=students+classes&depths=administrative_dependency+sc_school&colors=students+average_age&basic_course={{ basic_course.id }}{{ '&id_ibge=%s' % id_ibge if id_ibge }}"
target="graphs-frame-enrollments" class="list-group-item {{'selected' if graph.menu == 'enrollments-school-tree_map_new_api'}}" data-parent="#enrollments-school">
TreeMap
</a>
</div>
{% endif %}
</div>
</nav>
<div class="responsive-frame col-xs-12 col-sm-9 col-md-9">
<div class="embed-responsive responsive-wrapper">
{% if graph %}
<iframe src="/{{ g.locale }}/embed/{{graph.url}}"
name="graphs-frame-enrollments"
id="graphs-frame-enrollments"
class="embed-responsive-item">
</iframe>
{% elif location.id | length != 9 %}
<iframe src="/{{ g.locale }}/embed/geo_map/sc/{{ location.id if location else 'all' }}/all/{{basic_course.id}}/bra/?color=enrolled"
<iframe src="{% if graph %}
/{{ g.locale }}/{{graph.url}}
{% elif location.id | length != 9 %}
/{{ g.locale }}/map/sc/students/{{ id_ibge if id_ibge }}?values=students&basic_course={{basic_course.id}}&colors=students+classes+average_class_size
{% else %}
/{{ g.locale }}/tree_map/sc/sc_school/students?sizes=students+classes&depths=administrative_dependency+sc_school&colors=students+average_age&basic_course={{ basic_course.id }}{{ '&id_ibge=%s' % id_ibge if id_ibge }}
{% endif %}"
name="graphs-frame-enrollments"
id="graphs-frame-enrollments"
class="embed-responsive-item">
</iframe>
{% else %}
<iframe src="/{{ g.locale }}/embed/tree_map/sc/{{ location.id if location else 'all' }}/all/{{basic_course.id}}/school/?color=color&depth=school_8&size=enrolled"
name="graphs-frame-enrollments"
id="graphs-frame-enrollments"
class="embed-responsive-item">
</iframe>
{% endif %}
</div>
</div>
</div>
Loading

0 comments on commit 5532478

Please sign in to comment.