Skip to content

Commit

Permalink
filters out germany from tree maps pre 1985 closes #183
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandersimoes committed Oct 9, 2017
1 parent 1b95b7b commit 6fdcb7d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
9 changes: 5 additions & 4 deletions oec/__init__.py
Expand Up @@ -4,15 +4,15 @@
# general flask library
from flask import Flask
# flask-sqlalchemy connector for database queries
from flask.ext.sqlalchemy import SQLAlchemy
from flask_sqlalchemy import SQLAlchemy
# flask-babel for handling L18n and L10n
from flask.ext.babel import Babel
from flask_babel import Babel
# for new filters
from utils import Momentjs, formatter, strip_html, jinja_split, format_currency, \
format_percent, langify, num_format, YearConverter
from werkzeug.contrib.fixers import ProxyFix
# for caching views
from flask.ext.cache import Cache
from flask_cache import Cache
from werkzeug.contrib.fixers import ProxyFix

from config import DEBUG
Expand All @@ -36,9 +36,10 @@
# override cache timeout
cache_timeout = 0

from flask.ext.assets import Environment, Bundle
from flask_assets import Environment, Bundle
assets = Environment(app)
assets.load_path.append(os.path.join(oec_dir, "assets/js/"))
assets.auto_build = True
js = Bundle("warning.js", "visualization.js", "configs/*.js", "helpers/*.js", output="js/visualization.js")
assets.register("js", js)

Expand Down
10 changes: 8 additions & 2 deletions oec/assets/js/helpers/data_formatter.js
@@ -1,20 +1,26 @@
function format_data(raw_data, attrs, build){

var data = raw_data.data;
var opposite_trade_flow = build.trade_flow == "export" ? "import" : "export";
var attr_id = attr_id = build.attr_type + "_id";
var pini_domain = [32, 53];
var pini_scale = d3.scale.quantile().range(d3.range(7)).domain(pini_domain);
var pini_buckets = [32].concat(pini_scale.quantiles()).concat([53])

// remove germany for tree maps before 1985
if(build.classification === "sitc" && build.viz.slug === "tree_map") {
data = data.filter(function(d) {
return !(d.year < 1985 && d.origin_id === "eudeu");
})
}

// go through raw data and set each items nest and id vars properly
// also calculate net values
data.forEach(function(d){

// only assign "pini_class" if the dataset is SITC
if(build.attr_type === "sitc") {
if(attrs[d[attr_id]]) {
console.log(d[attr_id], attrs[d[attr_id]])
var bucket = pini_scale(attrs[d[attr_id]].pini);
d.pini_class = "PGIs ("+pini_buckets[bucket]+" - "+pini_buckets[bucket+1]+")";
}
Expand Down
2 changes: 1 addition & 1 deletion oec/general/views.py
Expand Up @@ -34,7 +34,7 @@ def before_request():
g.supported_langs = current_app.config.get('LANGUAGES')
g.supported_langs = sorted(g.supported_langs.iteritems(), key=lambda x: x[1].lower())
g.available_years = available_years
g.cache_version = 15
g.cache_version = 16
g.translations = json.dumps(get_translations())

# Save variable in session so we can determine if this is the user's
Expand Down
10 changes: 8 additions & 2 deletions oec/static/js/visualization.js
Expand Up @@ -763,22 +763,28 @@ configs.tree_map = function(build, container) {
}

function format_data(raw_data, attrs, build){

var data = raw_data.data;
var opposite_trade_flow = build.trade_flow == "export" ? "import" : "export";
var attr_id = attr_id = build.attr_type + "_id";
var pini_domain = [32, 53];
var pini_scale = d3.scale.quantile().range(d3.range(7)).domain(pini_domain);
var pini_buckets = [32].concat(pini_scale.quantiles()).concat([53])

// remove germany for tree maps before 1985
if(build.classification === "sitc" && build.viz.slug === "tree_map") {
data = data.filter(function(d) {
return !(d.year < 1985 && d.origin_id === "eudeu");
})
}

// go through raw data and set each items nest and id vars properly
// also calculate net values
data.forEach(function(d){

// only assign "pini_class" if the dataset is SITC
if(build.attr_type === "sitc") {
if(attrs[d[attr_id]]) {
console.log(d[attr_id], attrs[d[attr_id]])
var bucket = pini_scale(attrs[d[attr_id]].pini);
d.pini_class = "PGIs ("+pini_buckets[bucket]+" - "+pini_buckets[bucket+1]+")";
}
Expand Down
2 changes: 1 addition & 1 deletion run.py
@@ -1,4 +1,4 @@
from flask.ext.script import Manager
from flask_script import Manager
from oec import app

manager = Manager(app)
Expand Down

0 comments on commit 6fdcb7d

Please sign in to comment.