Skip to content

Commit

Permalink
Merge pull request #31 from cid-harvard/feature/msa-year
Browse files Browse the repository at this point in the history
[COL-664] Add MSAYear API for MSA-level ECI comparison graphs
  • Loading branch information
makmanalp committed Nov 5, 2015
2 parents 616af41 + 7cc95ca commit ff372bf
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
7 changes: 7 additions & 0 deletions colombia/api_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ class Meta:
"department_id")


class MSAYearSchema(ma.Schema):

class Meta:
fields = ("year", "eci", "location_id")


class OccupationYearSchema(ma.Schema):

class Meta:
Expand Down Expand Up @@ -150,5 +156,6 @@ class ColombiaMetadataSchema(MetadataSchema):
industry_year = IndustryYearSchema(many=True)
occupation_year = OccupationYearSchema(many=True)
department_year = DepartmentYearSchema(many=True)
msa_year = MSAYearSchema(many=True)

metadata = ColombiaMetadataSchema(many=True)
12 changes: 12 additions & 0 deletions colombia/data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ class DepartmentYear(BaseModel, IDMixin):
num_establishments = db.Column(db.Integer)


class MSAYear(BaseModel, IDMixin):

__tablename__ = "msa_year"

location_id = db.Column(db.Integer, db.ForeignKey(Location.id))
year = db.Column(db.Integer)

location = db.relationship(Location)

eci = db.Column(db.Float)


class XIndustryYear(BaseModel, IDMixin):

__abstract__ = True
Expand Down
7 changes: 5 additions & 2 deletions colombia/data/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MunicipalityIndustryYear, ProductYear, IndustryYear,
DepartmentYear, Location, CountryMunicipalityProductYear,
CountryDepartmentProductYear, OccupationYear,
OccupationIndustryYear, CountryDepartmentYear)
OccupationIndustryYear, CountryDepartmentYear, MSAYear)
from ..api_schemas import marshal
from .routing import lookup_classification_level
from .. import api_schemas as schemas
Expand Down Expand Up @@ -55,8 +55,11 @@ def get_or_fail(name, dictionary):
"department": {
"model": DepartmentYear,
"schema": schemas.department_year
},
"msa": {
"model": MSAYear,
"schema": schemas.msa_year
}
#"municipality" ...
}

product_year_region_mapping = {
Expand Down
5 changes: 5 additions & 0 deletions colombia/import.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@
chunksize=10000, if_exists="append")


# MSA year
df = ret[('location_id', 'year')].reset_index()
df.to_sql("msa_year", db.engine, index=False,
chunksize=10000, if_exists="append")

# Municipality - trade rcpy
ret = process_dataset(trade4digit_rcpy_municipality)

Expand Down
2 changes: 1 addition & 1 deletion colombia/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
DepartmentIndustryYear, IndustryYear,
MunicipalityIndustryYear, MSAProductYear,
MSAIndustryYear, OccupationYear,
OccupationIndustryYear, CountryDepartmentYear)
OccupationIndustryYear, CountryDepartmentYear, MSAYear)

0 comments on commit ff372bf

Please sign in to comment.