Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify route names, group routes in docs, timezones by default #5

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ authors = [
classifiers = ["Programming Language :: Python :: 3"]
dependencies = [
"fastapi >= 0.105.0",
"pytz >= 2023.3",
"structlog >= 23.2.0",
"uvicorn >= 0.24.0",
]
Expand Down
4 changes: 2 additions & 2 deletions src/india_api/internal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .models import (
DatabaseInterface,
PredictedYield,
PredictedPower,
)

from . import (
Expand All @@ -11,7 +11,7 @@
)

__all__ = [
"PredictedYield",
"PredictedPower",
"DatabaseInterface",
"inputs",
"service",
Expand Down
50 changes: 25 additions & 25 deletions src/india_api/internal/inputs/dummydb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ._models import DummyDBPredictedYield

# step defines the time interval between each data point
step: dt.timedelta = dt.timedelta(minutes=5)
step: dt.timedelta = dt.timedelta(minutes=15)


class Client(internal.DatabaseInterface):
Expand All @@ -17,7 +17,7 @@ class Client(internal.DatabaseInterface):
def get_predicted_solar_yields_for_location(
self,
location: str,
) -> list[internal.PredictedYield]:
) -> list[internal.PredictedPower]:
"""Gets the predicted solar yields for a location.

Args:
Expand All @@ -26,24 +26,24 @@ def get_predicted_solar_yields_for_location(
# Get the window
start, end = _getWindow()
numSteps = int((end - start) / step)
yields: list[internal.PredictedYield] = []
values: list[internal.PredictedPower] = []

for i in range(numSteps):
time = start + i * step
_yield = _basicSolarYieldFunc(int(time.timestamp()))
yields.append(
internal.PredictedYield(
values.append(
internal.PredictedPower(
Time=time,
YieldKW=int(_yield.YieldKW),
PowerKW=int(_yield.YieldKW),
),
)

return yields
return values

def get_predicted_wind_yields_for_location(
self,
location: str,
) -> list[internal.PredictedYield]:
) -> list[internal.PredictedPower]:
"""Gets the predicted wind yields for a location.

Args:
Expand All @@ -52,57 +52,57 @@ def get_predicted_wind_yields_for_location(
# Get the window
start, end = _getWindow()
numSteps = int((end - start) / step)
yields: list[internal.PredictedYield] = []
values: list[internal.PredictedPower] = []

for i in range(numSteps):
time = start + i * step
_yield = _basicWindYieldFunc(int(time.timestamp()))
yields.append(
internal.PredictedYield(
values.append(
internal.PredictedPower(
Time=time,
YieldKW=int(_yield.YieldKW),
PowerKW=int(_yield.YieldKW),
),
)

return yields
return values

def get_actual_solar_yields_for_location(self, location: str) -> list[internal.PredictedYield]:
def get_actual_solar_yields_for_location(self, location: str) -> list[internal.PredictedPower]:
"""Gets the actual solar yields for a location."""
# Get the window
start, end = _getWindow()
numSteps = int((end - start) / step)
yields: list[internal.PredictedYield] = []
values: list[internal.PredictedPower] = []

for i in range(numSteps):
time = start + i * step
_yield = _basicSolarYieldFunc(int(time.timestamp()))
yields.append(
internal.PredictedYield(
values.append(
internal.PredictedPower(
Time=time,
YieldKW=int(_yield.YieldKW),
PowerKW=int(_yield.YieldKW),
),
)

return yields
return values

def get_actual_wind_yields_for_location(self, location: str) -> list[internal.PredictedYield]:
def get_actual_wind_yields_for_location(self, location: str) -> list[internal.PredictedPower]:
"""Gets the actual wind yields for a location."""
# Get the window
start, end = _getWindow()
numSteps = int((end - start) / step)
yields: list[internal.PredictedYield] = []
values: list[internal.PredictedPower] = []

for i in range(numSteps):
time = start + i * step
_yield = _basicWindYieldFunc(int(time.timestamp()))
yields.append(
internal.PredictedYield(
values.append(
internal.PredictedPower(
Time=time,
YieldKW=int(_yield.YieldKW),
PowerKW=int(_yield.YieldKW),
),
)

return yields
return values

def get_wind_regions(self) -> list[str]:
"""Gets the valid wind regions."""
Expand Down
27 changes: 17 additions & 10 deletions src/india_api/internal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,47 @@
from pydantic import BaseModel


class PredictedYield(BaseModel):
"""Defines the model for a predicted yield returned by the API."""
class PredictedPower(BaseModel):
"""Defines the data structure for a predicted power value returned by the API."""

YieldKW: int
PowerKW: int
Time: dt.datetime

def to_timezone(self, tz: dt.timezone) -> "PredictedPower":
"""Converts the time of this predicted power value to the given timezone."""
return PredictedPower(
PowerKW=self.PowerKW,
Time=self.Time.astimezone(tz=tz),
)

class ActualYield(BaseModel):
"""Defines the model for an actual yield returned by the API."""

YieldKW: int
class ActualPower(BaseModel):
"""Defines the data structure for an actual power value returned by the API."""

PowerKW: int
Time: dt.datetime


class DatabaseInterface(abc.ABC):
"""Defines the interface for a generic database connection."""

@abc.abstractmethod
def get_predicted_solar_yields_for_location(self, location: str) -> list[PredictedYield]:
def get_predicted_solar_yields_for_location(self, location: str) -> list[PredictedPower]:
"""Returns a list of predicted solar yields for a given location."""
pass

@abc.abstractmethod
def get_actual_solar_yields_for_location(self, location: str) -> list[ActualYield]:
def get_actual_solar_yields_for_location(self, location: str) -> list[ActualPower]:
"""Returns a list of actual solar yields for a given location."""
pass

@abc.abstractmethod
def get_predicted_wind_yields_for_location(self, location: str) -> list[PredictedYield]:
def get_predicted_wind_yields_for_location(self, location: str) -> list[PredictedPower]:
"""Returns a list of predicted wind yields for a given location."""
pass

@abc.abstractmethod
def get_actual_wind_yields_for_location(self, location: str) -> list[ActualYield]:
def get_actual_wind_yields_for_location(self, location: str) -> list[ActualPower]:
"""Returns a list of actual wind yields for a given location."""
pass

Expand Down
Loading
Loading