Skip to content

Commit

Permalink
Merge pull request #1547 from Vizzuality/develop
Browse files Browse the repository at this point in the history
5.3.5
  • Loading branch information
tomasmoose authored Sep 15, 2020
2 parents ab738eb + f77e9e0 commit 3f95199
Show file tree
Hide file tree
Showing 45 changed files with 1,070 additions and 201 deletions.
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ checks:
plugins:
rubocop:
enabled: true
channel: rubocop-0-89
channel: rubocop-0-90
brakeman:
enabled: true
bundler-audit:
Expand Down
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ TRASE_REMOTE_USER=main_ro # this user defined in remote database with read-only
TRASE_REMOTE_PASSWORD=
TRASE_REMOTE_SERVER=trase_server
TRASE_LOCAL_FDW_SCHEMA=main # this schema in local database where remote tables are mapped
TRASE_LOCAL_MIRROR_SCHEMA=tool_tables # this schema in local database where remote tables are restored
TRASE_LOCAL_MIRROR_SCHEMA=trase_earth # this schema in local database where remote tables are restored
TRASE_LOCAL_SCHEMA=public # this schema in local database where target tables are

API_HOST=http://localhost:3000 # base url of API
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ matrix:
- ./cc-test-reporter before-build

script:
- TRASE_LOCAL_MIRROR_SCHEMA=tool_tables TRASE_LOCAL_SCHEMA=public bundle exec rspec spec --fail-fast
- TRASE_LOCAL_MIRROR_SCHEMA=trase_earth TRASE_LOCAL_SCHEMA=public bundle exec rspec spec --fail-fast

after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ gem 'pg_search'
gem 'rack', '~> 2.2.3' # issue with sidekiq web in version 2.1.1, still doesn't work on sandbox in version 2.1.2
gem 'rack-cors', '~> 1.1'
gem 'scenic'
gem 'sidekiq', '~> 6.1.1'
gem 'sidekiq', '~> 6.1.2'
gem 'sidekiq-unique-jobs'
gem 'sitemap_generator'
gem 'twitter', '~> 7.0'
Expand Down Expand Up @@ -90,7 +90,7 @@ group :development do
gem 'capistrano-rails', '~> 1.6', require: false
gem 'capistrano-rvm'
gem 'ed25519', '~> 1.2'
gem 'rubocop', '~> 0.89.1', require: false
gem 'rubocop', '~> 0.90.0', require: false
gem 'rubocop-performance', require: false
end

Expand Down
34 changes: 16 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,26 @@ GEM
arel (9.0.0)
ast (2.4.1)
aws-eventstream (1.1.0)
aws-partitions (1.354.0)
aws-sdk-core (3.104.3)
aws-partitions (1.360.0)
aws-sdk-core (3.105.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.239.0)
aws-sigv4 (~> 1.1)
jmespath (~> 1.0)
aws-sdk-kms (1.36.0)
aws-sdk-kms (1.37.0)
aws-sdk-core (~> 3, >= 3.99.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.78.0)
aws-sdk-s3 (1.79.1)
aws-sdk-core (~> 3, >= 3.104.3)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.1)
aws-sigv4 (1.2.1)
aws-sigv4 (1.2.2)
aws-eventstream (~> 1, >= 1.0.2)
bcrypt (3.1.13)
bcrypt_pbkdf (1.0.0)
best_in_place (3.1.1)
actionpack (>= 3.2)
railties (>= 3.2)
bigdecimal (2.0.0)
bootsnap (1.4.8)
msgpack (~> 1.0)
buftok (0.2.0)
Expand Down Expand Up @@ -265,8 +264,7 @@ GEM
nio4r (2.5.2)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
oj (3.10.12)
bigdecimal (>= 1.0, < 3)
oj (3.10.14)
orm_adapter (0.5.0)
paperclip (6.1.0)
activemodel (>= 4.2.0)
Expand All @@ -286,7 +284,7 @@ GEM
polyamorous (2.3.2)
activerecord (>= 5.2.1)
public_suffix (4.0.3)
puma (4.3.5)
puma (4.3.6)
nio4r (~> 2.0)
rack (2.2.3)
rack-cors (1.1.1)
Expand Down Expand Up @@ -331,7 +329,7 @@ GEM
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
ffi (~> 1.0)
redis (4.2.1)
redis (4.2.2)
regexp_parser (1.7.1)
require_all (1.5.0)
responders (3.0.1)
Expand All @@ -357,7 +355,7 @@ GEM
rspec-mocks (~> 3.9)
rspec-support (~> 3.9)
rspec-support (3.9.3)
rubocop (0.89.1)
rubocop (0.90.0)
parallel (~> 1.10)
parser (>= 2.7.1.1)
rainbow (>= 2.2.2, < 4.0)
Expand All @@ -368,8 +366,8 @@ GEM
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.3.0)
parser (>= 2.7.1.4)
rubocop-performance (1.7.1)
rubocop (>= 0.82.0)
rubocop-performance (1.8.0)
rubocop (>= 0.87.0)
rubocop-rspec (1.43.2)
rubocop (~> 0.87)
ruby-progressbar (1.10.1)
Expand All @@ -392,14 +390,14 @@ GEM
railties (>= 4.0.0)
select2-rails (4.0.3)
thor (~> 0.14)
sidekiq (6.1.1)
sidekiq (6.1.2)
connection_pool (>= 2.2.2)
rack (~> 2.0)
redis (>= 4.2.0)
sidekiq-unique-jobs (6.0.22)
sidekiq-unique-jobs (6.0.23)
concurrent-ruby (~> 1.0, >= 1.0.5)
sidekiq (>= 4.0, < 7.0)
thor (~> 0)
thor (>= 0.20, < 2.0)
simple_oauth (0.3.1)
simplecov (0.19.0)
docile (~> 1.1)
Expand Down Expand Up @@ -514,12 +512,12 @@ DEPENDENCIES
rails-controller-testing
rspec-collection_matchers
rspec-rails (~> 4.0)
rubocop (~> 0.89.1)
rubocop (~> 0.90.0)
rubocop-performance
rubocop-rspec
sassc-rails (~> 2.1.2)
scenic
sidekiq (~> 6.1.1)
sidekiq (~> 6.1.2)
sidekiq-unique-jobs
simplecov
sitemap_generator
Expand Down
31 changes: 21 additions & 10 deletions app/controllers/api/v3/country_profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class CountryProfilesController < ApiController
include Api::V3::Profiles::CrossContextHelpers

skip_before_action :load_context
before_action :ensure_commodity_or_context_given, only: [:top_consumer_actors, :top_consumer_countries]
before_action :load_node
before_action :set_year

Expand Down Expand Up @@ -47,16 +48,26 @@ def top_consumer_actors
end

def top_consumer_countries
@result = Api::V3::Profiles::CrossContextTopNodesChart.new(
@contexts,
@node,
@year,
{
profile_type: profile_type,
chart_identifier: :country_top_consumer_countries,
include_other: false
}
).call
@result =
if @node.node_type == NodeTypeName::COUNTRY_OF_PRODUCTION
Api::V3::Profiles::CrossContextTopNodesChart.new(
@contexts,
@node,
@year,
{
profile_type: profile_type,
chart_identifier: :country_top_consumer_countries,
include_other: false
}
).call
else
Api::V3::CountryProfiles::TopSourceCountriesChart.new(
@contexts,
@node,
@year,
{}
).call
end

render json: {data: @result}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ def set_year
node_years.last
end
end

def ensure_commodity_or_context_given
return if params[:commodity_id].present? || params[:context_id].present?
raise ActionController::ParameterMissing,
"Required param commodity_id or context_id missing"
end
end
end
end
Expand Down
37 changes: 37 additions & 0 deletions app/models/api/v3/countries_com_trade_partner_indicator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# == Schema Information
#
# Table name: countries_com_trade_partner_indicators
#
# raw_quantity :float
# quantity :float
# value :float
# commodity_id :integer not null
# year :integer not null
# iso3 :text not null
# iso2 :text not null
# partner_iso3 :text not null
# partner_iso2 :text not null
# commodity_code :text not null
# activity :text not null
#
module Api
module V3
class CountriesComTradePartnerIndicator < YellowTable
belongs_to :commodity, optional: false

validates :iso3, presence: true
validates :iso2, presence: true
validates :partner_iso3, presence: true
validates :partner_iso2, presence: true
validates :year, presence: true
validates :commodity_code, presence: true
validates :activity, presence: true

def self.blue_foreign_keys
[
{name: :commodity_id, table_class: Api::V3::Commodity}
]
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# == Schema Information
#
# Table name: countries_com_trade_indicators
# Table name: countries_com_trade_world_indicators
#
# raw_quantity :float
# quantity :float
Expand All @@ -14,7 +14,7 @@
#
module Api
module V3
class CountriesComTradeIndicator < YellowTable
class CountriesComTradeWorldIndicator < YellowTable
belongs_to :commodity, optional: false

validates :iso3, presence: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# == Schema Information
#
# Table name: countries_com_trade_partner_aggregated_indicators
#
# quantity :float
# value :float
# commodity_id :integer
# year :integer
# iso2 :text
# iso3 :text
# activity :text
#
module Api
module V3
module Readonly
class CountriesComTradePartnerAggregatedIndicator < Api::Readonly::BaseModel
include Api::V3::Readonly::MaterialisedTable

self.table_name = 'countries_com_trade_partner_aggregated_indicators'

INDEXES = [].freeze
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# == Schema Information
#
# Table name: countries_com_trade_aggregated_indicators
# Table name: countries_com_trade_world_aggregated_indicators
#
# quantity :float
# value :float
Expand All @@ -14,10 +14,10 @@
module Api
module V3
module Readonly
class CountriesComTradeAggregatedIndicator < Api::Readonly::BaseModel
class CountriesComTradeWorldAggregatedIndicator < Api::Readonly::BaseModel
include Api::V3::Readonly::MaterialisedTable

self.table_name = 'countries_com_trade_aggregated_indicators'
self.table_name = 'countries_com_trade_world_aggregated_indicators'

INDEXES = [].freeze
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/api/public/nodes/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def apply_filters
:node_type,
:geo_id,
'JSON_AGG(' \
'JSON_BUILD_OBJECT(' \
'DISTINCT JSONB_BUILD_OBJECT(' \
'\'country\', contexts_mv.iso2, ' \
'\'commodity\', contexts_mv.commodity_name, ' \
'\'years\', nodes_with_flows.years' \
Expand Down
Loading

0 comments on commit 3f95199

Please sign in to comment.