Skip to content

Commit

Permalink
Adding RCY partner country APIs for whole country and MSAs COL-668 CO…
Browse files Browse the repository at this point in the history
…L-392
  • Loading branch information
makmanalp committed Nov 11, 2015
1 parent 6bd826d commit 0cf2705
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
4 changes: 2 additions & 2 deletions colombia/api_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Meta:
fields = ("export_value", "country_id", "product_id", "year")


class CountryDepartmentYearSchema(ma.Schema):
class CountryXYearSchema(ma.Schema):

class Meta:
fields = ("export_value", "country_id", "location_id", "year")
Expand Down Expand Up @@ -150,7 +150,7 @@ class ColombiaMetadataSchema(MetadataSchema):
country_municipality_product_year = CountryMunicipalityProductYearSchema(many=True)
country_department_product_year = CountryDepartmentProductYearSchema(many=True)

country_department_year = CountryDepartmentYearSchema(many=True)
country_x_year = CountryXYearSchema(many=True)

product_year = ProductYearSchema(many=True)
industry_year = IndustryYearSchema(many=True)
Expand Down
32 changes: 25 additions & 7 deletions colombia/data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,39 @@ class CountryMunicipalityProductYear(CountryXProductYear):
__tablename__ = "country_municipality_product_year"


class CountryDepartmentYear(BaseModel, IDMixin):
class CountryXYear(BaseModel, IDMixin):

__tablename__ = "country_department_year"
__abstract__ = True

country_id = db.Column(db.Integer, db.ForeignKey(Location.id))
location_id = db.Column(db.Integer, db.ForeignKey(Location.id))
year = db.Column(db.Integer)
@declared_attr
def country_id(cls):
return db.Column(db.Integer, db.ForeignKey(Location.id))

@declared_attr
def location_id(cls):
return db.Column(db.Integer, db.ForeignKey(Location.id))

location = db.relationship(Location, foreign_keys=[location_id])
country = db.relationship(Location, foreign_keys=[country_id])
year = db.Column(db.Integer)

export_value = db.Column(db.BIGINT)
export_num_plants = db.Column(db.Integer)


class CountryCountryYear(CountryXYear):

__tablename__ = "country_country_year"


class CountryDepartmentYear(CountryXYear):

__tablename__ = "country_department_year"


class CountryMSAYear(CountryXYear):

__tablename__ = "country_msa_year"


class DepartmentYear(BaseModel, IDMixin):

__tablename__ = "department_year"
Expand Down
15 changes: 13 additions & 2 deletions colombia/data/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
MunicipalityIndustryYear, ProductYear, IndustryYear,
DepartmentYear, Location, CountryMunicipalityProductYear,
CountryDepartmentProductYear, OccupationYear,
OccupationIndustryYear, CountryDepartmentYear, MSAYear)
OccupationIndustryYear, CountryCountryYear,
CountryDepartmentYear, CountryMSAYear, MSAYear)
from ..api_schemas import marshal
from .routing import lookup_classification_level
from .. import api_schemas as schemas
Expand Down Expand Up @@ -219,7 +220,17 @@ def eey_location_partners(entity_type, entity_id, buildingblock_level):
q = CountryDepartmentYear.query\
.filter_by(location_id=entity_id)\
.all()
return marshal(schemas.country_department_year, q)
return marshal(schemas.country_x_year, q)
elif location_level == "msa":
q = CountryMSAYear.query\
.filter_by(location_id=entity_id)\
.all()
return marshal(schemas.country_x_year, q)
elif location_level == "country":
q = CountryCountryYear.query\
.filter_by(location_id=entity_id)\
.all()
return marshal(schemas.country_x_year, q)
else:
msg = "Data doesn't exist at location level {}"\
.format(location_level)
Expand Down
3 changes: 2 additions & 1 deletion colombia/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
DepartmentIndustryYear, IndustryYear,
MunicipalityIndustryYear, MSAProductYear,
MSAIndustryYear, OccupationYear,
OccupationIndustryYear, CountryDepartmentYear, MSAYear)
OccupationIndustryYear, CountryCountryYear,
CountryDepartmentYear, CountryMSAYear, MSAYear)

0 comments on commit 0cf2705

Please sign in to comment.