Skip to content

Instantly share code, notes, and snippets.

@tudormunteanu
Created September 23, 2020 12:53
Show Gist options
  • Save tudormunteanu/d1879681843c375ca345f240235e0b0b to your computer and use it in GitHub Desktop.
Save tudormunteanu/d1879681843c375ca345f240235e0b0b to your computer and use it in GitHub Desktop.
class SpainComparisonQuery(StrictSchema):
tariff_code = fields.Str(
description=(
"Only in Spain. Three digit version of the "
"tariff type. Example: 001 or 004."
)
)
meter_type = fields.Str(
description=(
"Only in Spain. Represents the meter type "
"in format: <code>remoteControlCode-meterPhaseCode</code>. "
"Example: <code>01-M</code> or <code>03-T</code>."
)
)
days_on_bill = fields.Int(
required=False,
description=(
"Only in Spain. The number of days between the start and end of"
"a user's bill."
"Example: 31"
),
default=31,
missing=31
)
class TariffQuery(StrictSchema):
territory = schemas.EnumField(schemas.Territory, required=False)
region_code = fields.Str()
power_capacity = fields.Int(required=False)
@validates_schema
def validate_power_capacity_arg_usage(self, data, **_):
if "power_capacity" in data and "region_code" not in data:
raise ValidationError(
"region_code is mandatory when filtering by power_capacity"
)
if (
"territory" in data
and ("tariff_code" in data or "meter_type" in data)
and data["territory"] != Territory.ES
):
raise ValidationError(
"Only Spain can have a tariff_code or meter_type."
)
@current.route(
"/tariffs/comparisons/ES/"
"<string:meter_type>/<tariff_type:tariff_type>/<string:power_capacity>/"
"<string:consumption>"
)
@spec.marshal_with(view_schemas.WrappedComparisonTariffSchema(), code=200)
@spec.use_kwargs(view_schemas.SpainComparisonQuery, locations=("query",))
@spec.doc(
tags=["territory specific", "comparison"],
summary="Tariff for comparison by meter type and tariff type for Spain",
description="Return tariff for comparison for Spain.",
)
def get_tariffs_for_comparison_spain(
meter_type: str,
tariff_type: TariffType,
power_capacity: str,
consumption: str,
days_on_bill: int,
):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment