Skip to content

Commit

Permalink
Merge branch 'develop' into wava
Browse files Browse the repository at this point in the history
  • Loading branch information
axelstudios committed Jun 9, 2020
2 parents 527dcb3 + 10a61c4 commit 68a670d
Show file tree
Hide file tree
Showing 6 changed files with 933 additions and 13 deletions.
2 changes: 2 additions & 0 deletions seed/api/v3/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from seed.views.v3.cycles import CycleViewSet
from seed.views.v3.datasets import DatasetViewSet
from seed.views.v3.data_quality import DataQualityViews
from seed.views.v3.import_files import ImportFileViewSet
from seed.views.v3.organizations import OrganizationViewSet
from seed.views.v3.users import UserViewSet

Expand All @@ -15,6 +16,7 @@
api_v3_router.register(r'cycles', CycleViewSet, base_name='cycles')
api_v3_router.register(r'datasets', DatasetViewSet, base_name='datasets')
api_v3_router.register(r'data_quality_checks', DataQualityViews, base_name='data_quality_checks')
api_v3_router.register(r'import_files', ImportFileViewSet, base_name='import_files')
api_v3_router.register(r'organizations', OrganizationViewSet, base_name='organizations')
api_v3_router.register(r'users', UserViewSet, base_name='user')

Expand Down
35 changes: 35 additions & 0 deletions seed/serializers/column_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,38 @@ def to_representation(self, obj):
result['column_mapped'] = ColumnSerializer(obj.column_mapped.first()).data

return result


class ImportMappingSerializer(serializers.Serializer):
from_field = serializers.CharField()
from_units = serializers.CharField()
to_field = serializers.CharField()
to_field_display_name = serializers.CharField()
to_table_name = serializers.CharField()


class SaveColumnMappingsRequestPayloadSerializer(serializers.Serializer):
"""
Note that this is _not_ a model serializer, but used only for saving mappings
Example:
{
"mappings": [
{
'from_field': 'eui', # raw field in import file
'from_units': 'kBtu/ft**2/year', # pint-parsable units, optional
'to_field': 'energy_use_intensity',
'to_field_display_name': 'Energy Use Intensity',
'to_table_name': 'PropertyState',
},
{
'from_field': 'gfa',
'from_units': 'ft**2', # pint-parsable units, optional
'to_field': 'gross_floor_area',
'to_field_display_name': 'Gross Floor Area',
'to_table_name': 'PropertyState',
}
]
}
"""
mappings = serializers.ListField(child=ImportMappingSerializer())
35 changes: 24 additions & 11 deletions seed/utils/api_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AutoSchemaHelper(SwaggerAutoSchema):

# Used to easily build out example values displayed on Swagger page.
body_parameter_formats = {
'interger_array': openapi.Schema(
'integer_array': openapi.Schema(
type=openapi.TYPE_ARRAY,
items=openapi.Schema(type=openapi.TYPE_INTEGER)
),
Expand All @@ -22,7 +22,8 @@ class AutoSchemaHelper(SwaggerAutoSchema):
)
}

def base_field(self, name, location_attr, description, required, type):
@staticmethod
def base_field(name, location_attr, description, required, type):
"""
Created to avoid needing to directly access openapi within ViewSets.
Ideally, the cases below will be used instead of this one.
Expand All @@ -35,7 +36,8 @@ def base_field(self, name, location_attr, description, required, type):
type=type
)

def org_id_field(self, required=True):
@staticmethod
def org_id_field(required=True):
return openapi.Parameter(
'organization_id',
openapi.IN_QUERY,
Expand All @@ -44,7 +46,8 @@ def org_id_field(self, required=True):
type=openapi.TYPE_INTEGER
)

def query_integer_field(self, name, required, description):
@staticmethod
def query_integer_field(name, required, description):
return openapi.Parameter(
name,
openapi.IN_QUERY,
Expand All @@ -53,7 +56,8 @@ def query_integer_field(self, name, required, description):
type=openapi.TYPE_INTEGER
)

def query_string_field(self, name, required, description):
@staticmethod
def query_string_field(name, required, description):
return openapi.Parameter(
name,
openapi.IN_QUERY,
Expand All @@ -62,7 +66,8 @@ def query_string_field(self, name, required, description):
type=openapi.TYPE_STRING
)

def query_boolean_field(self, name, required, description):
@staticmethod
def query_boolean_field(name, required, description):
return openapi.Parameter(
name,
openapi.IN_QUERY,
Expand All @@ -71,7 +76,8 @@ def query_boolean_field(self, name, required, description):
type=openapi.TYPE_BOOLEAN
)

def path_id_field(self, description):
@staticmethod
def path_id_field(description):
return openapi.Parameter(
'id',
openapi.IN_PATH,
Expand All @@ -80,20 +86,27 @@ def path_id_field(self, description):
type=openapi.TYPE_INTEGER
)

def body_field(self, required, description, name='body', params_to_formats={}):
@classmethod
def body_field(cls, required, description, name='body', params_to_formats={}):
return openapi.Parameter(
name,
openapi.IN_BODY,
description=description,
required=required,
schema=self._build_body_schema(params_to_formats)
schema=cls.schema_factory(params_to_formats)
)

def _build_body_schema(self, params_to_formats):
@classmethod
def schema_factory(cls, params_to_formats):
"""Translates simple dictionary into an openapi Schema instance
:param params_to_formats: dict[str, str]
:return: drf_yasg.openapi.Schema
"""
return openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
k: self.body_parameter_formats.get(format_name, "")
k: cls.body_parameter_formats[format_name]
for k, format_name
in params_to_formats.items()
}
Expand Down
4 changes: 2 additions & 2 deletions seed/views/v3/data_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def __init__(self, *args):
required=True,
description="An object containing IDs of the records to perform data quality checks on. Should contain two keys- property_state_ids and taxlot_state_ids, each of which is an array of appropriate IDs.",
params_to_formats={
'property_state_ids': 'interger_array',
'taxlot_state_ids': 'interger_array'
'property_state_ids': 'integer_array',
'taxlot_state_ids': 'integer_array'
}
),
],
Expand Down
Loading

0 comments on commit 68a670d

Please sign in to comment.