Skip to content

Commit

Permalink
Colombia level 4digit products COL-370
Browse files Browse the repository at this point in the history
  • Loading branch information
makmanalp committed Aug 11, 2015
1 parent e120010 commit 5426ef0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
24 changes: 20 additions & 4 deletions colombia/api_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,33 @@ def marshal(schema, data, json=True, many=True):
return serialization_result.data


XPY_FIELDS = ("import_value", "export_value", "export_rca", "distance", "cog",
"coi", "product_id", "year")


class CountryProductYearSchema(ma.Schema):

country_id = ma.fields.Constant(0)
import_value = ma.fields.Constant(None)
export_rca = ma.fields.Constant(None)
distance = ma.fields.Constant(None)
cog = ma.fields.Constant(None)
coi = ma.fields.Constant(None)

class Meta:
fields = XPY_FIELDS + ("country_id", )


class DepartmentProductYearSchema(ma.Schema):

class Meta:
fields = ("import_value", "export_value", "export_rca", "distance",
"cog", "coi", "department_id", "product_id", "year")
fields = XPY_FIELDS + ("department_id", )


class MunicipalityProductYearSchema(ma.Schema):

class Meta:
fields = ("import_value", "export_value", "export_rca", "distance",
"cog", "coi", "municipality_id", "product_id", "year")
fields = XPY_FIELDS + ("municipality_id", )


class CountryMunicipalityProductYearSchema(ma.Schema):
Expand Down Expand Up @@ -105,6 +120,7 @@ class ColombiaMetadataSchema(MetadataSchema):
description_es = ma.fields.Str(required=False)


country_product_year = CountryProductYearSchema(many=True)
department_product_year = DepartmentProductYearSchema(many=True)
municipality_product_year = MunicipalityProductYearSchema(many=True)
country_municipality_product_year = CountryMunicipalityProductYearSchema(many=True)
Expand Down
2 changes: 2 additions & 0 deletions colombia/data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class ProductYear(BaseModel, IDMixin):
pci = db.Column(db.Float)
pci_rank = db.Column(db.Integer)

export_value = db.Column(db.BIGINT)



class IndustryYear(BaseModel, IDMixin):
Expand Down
5 changes: 5 additions & 0 deletions colombia/data/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ def eey_location_products(entity_type, entity_id, buildingblock_level):

location_level = lookup_classification_level("location", entity_id)

if location_level == "country":
q = ProductYear.query\
.filter_by(level=buildingblock_level)\
.all()
return marshal(schemas.country_product_year, q)
if location_level == "department":
q = DepartmentProductYear.query\
.filter_by(department_id=entity_id)\
Expand Down
1 change: 1 addition & 0 deletions colombia/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def prefix_path(to_prefix):
},
("product_id", "year"): {
"pci": first,
"export_value": sumGroup,
},
("department_id", "product_id", "year"): {
"export_value": first,
Expand Down

0 comments on commit 5426ef0

Please sign in to comment.