Skip to content

Commit

Permalink
Merge pull request #3 from openearthplatforminitiative/fix-api-examples
Browse files Browse the repository at this point in the history
Correct examples in data model
  • Loading branch information
A-Stangeland authored Nov 10, 2023
2 parents 5a6fcbf + f26b4ed commit 119075e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
24 changes: 13 additions & 11 deletions deforestation_api/models/basin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@


class LossYear(BaseModel):
year: int = Field(example=2022, description="Year when the loss was detected.")
year: int = Field(examples=[2022], description="Year when the loss was detected.")
area: float = Field(
example=8.5095,
examples=[8.5095],
description="Total tree cover loss within the basin polygon, in square kilometers.",
)
relative_area: float = Field(
example=0.0036,
examples=[0.0036],
description=(
"Tree cover loss within the basin polygon "
"relative to the total area of the polygon."
Expand All @@ -23,34 +23,34 @@ class LossYear(BaseModel):

class BasinProperties(BaseModel):
downstream_id: int = Field(
example=1071114980,
examples=[1071114980],
description=(
"Id of the next downstream polygon for the current basin polygon. "
"The value 0 means that there is no downstream connection."
),
)
basin_area: float = Field(
example=2350.0, description="Area of the basin polygon in square kilometers."
examples=[2350.0], description="Area of the basin polygon in square kilometers."
)
upstream_area: float = Field(
example=29444.1,
examples=[29444.1],
description=(
"Total upstream area in square kilometers, "
"including the current polygon."
),
)
start_year: int = Field(example=2020)
end_year: int = Field(example=2022)
start_year: int = Field(examples=[2020])
end_year: int = Field(examples=[2022])
daterange_tot_treeloss: float = Field(
example=35.7217,
examples=[35.7217],
description=(
"Total tree cover loss, in square kilometers, "
"within the basin polygon over the time period "
"from start_year to end_year (inclusive)"
),
)
daterange_rel_treeloss: float = Field(
example=0.0152,
examples=[0.0152],
description=(
"Tree cover loss within the basin polygon "
"relative to the total area of the polygon, "
Expand All @@ -62,7 +62,9 @@ class BasinProperties(BaseModel):


class DeforestationBasinFeature(BaseModel):
id: int = Field(example=1071119930, description="Unique basin polygon identifier.")
id: int = Field(
examples=[1071119930], description="Unique basin polygon identifier."
)
type: Literal["Feature"]
properties: BasinProperties
geometry: Polygon
Expand Down
11 changes: 9 additions & 2 deletions deforestation_api/models/geometry.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
from __future__ import annotations

from enum import Enum
from typing import Annotated, Literal
from pydantic import BaseModel, Field

Longitude = Annotated[float, Field(ge=-180, le=180)]
Latitude = Annotated[float, Field(ge=-90, le=90)]
Position = tuple[Longitude, Latitude]
LinearRing = Annotated[list[Position], Field(min_length=4)]
LinearRing = Annotated[
list[Position],
Field(
examples=[
[[-20.0, -10.0], [50.0, -10.0], [50.0, 10.0], [-20.0, 10.0], [-20.0, -10.0]]
],
min_length=4,
),
]
PolygonCoords = list[LinearRing]


Expand Down

0 comments on commit 119075e

Please sign in to comment.