Skip to content

Commit

Permalink
Swap linter to ruff (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
devsjc authored Jan 27, 2023
1 parent 0b0a90b commit 9a25276
Show file tree
Hide file tree
Showing 19 changed files with 137 additions and 193 deletions.
38 changes: 5 additions & 33 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,13 @@ repos:
- id: debug-statements
- id: detect-private-key
# python code formatting/linting
- repo: https://github.com/PyCQA/pydocstyle
rev: 6.1.1
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: "v0.0.236"
hooks:
- id: pydocstyle
args: [--convention=google, "--add-ignore=D200,D202,D210,D212,D415"]
- id: ruff
files: sdk/python/pvsite_datamodel
exclude: __version__.py
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
args:
[
"--max-line-length",
"100",
"--extend-ignore=E203",
"--per-file-ignores",
"__init__.py:F401",
"sdk/python/pvsite_datamodel",

]
- repo: https://github.com/PyCQA/isort
rev: 5.11.4
hooks:
- id: isort
args: ["--profile", "black", "--line-length", "100"]
files: sdk/python/pvsite_datamodel
exclude: __version__.py
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
args: ["--line-length", "100"]
files: sdk/python/pvsite_datamodel
exclude: __version__.py
args: [--fix, -v]
# yaml formatting
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.4
Expand Down
2 changes: 1 addition & 1 deletion gen/pvsite.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Sites(Base):
ml_id = sa.Column(sa.Integer(), autoincrement=True)

__table_args__ = (

UniqueConstraint("client_site_id",client_uuid, name='idx_client')
)

Expand Down
24 changes: 12 additions & 12 deletions gen/pvsite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ COMMENT ON TABLE "sites" IS 'Each site row specifies a single panel or cluster o
found on a residential house or commercial building. Their
data is provided by a client.
*Approximate size: *
*Approximate size: *
4 clients * ~1000 sites each = ~4000 rows';

COMMENT ON COLUMN "sites"."client_uuid" IS 'The internal ID of the client providing the site data';
Expand All @@ -109,7 +109,7 @@ COMMENT ON COLUMN "sites"."ml_id" IS 'Auto-incrementing integer ID of the site f
COMMENT ON TABLE "generation" IS 'Each yield row specifies a generated power output over a
given time range for a site.
*Approximate size: *
*Approximate size: *
Generation populated every 5 minutes per site * 4000 sites = ~1,125,000 rows per day';

COMMENT ON COLUMN "generation"."site_uuid" IS 'The site for which this geenration yield belongs to';
Expand All @@ -119,9 +119,9 @@ COMMENT ON COLUMN "generation"."power_kw" IS 'The actual generated power in kW a
COMMENT ON COLUMN "generation"."datetime_interval_uuid" IS 'The time interval over which this generated power value applies';

COMMENT ON TABLE "forecasts" IS 'Each forecast row refers to a sequence of predicted solar generation values
over a set of target times for a site.
over a set of target times for a site.
*Approximate size: *
*Approximate size: *
One forecast per site every 5 minutes = ~1,125,000 rows per day';

COMMENT ON COLUMN "forecasts"."site_uuid" IS 'The site for which the forecast sequence was generated';
Expand All @@ -130,11 +130,11 @@ COMMENT ON COLUMN "forecasts"."created_utc" IS 'The creation time of the forecas

COMMENT ON COLUMN "forecasts"."forecast_version" IS 'The semantic version of the model used to generate the forecast';

COMMENT ON TABLE "forecast_values" IS 'Each forecast_value row is a prediction for the power output
COMMENT ON TABLE "forecast_values" IS 'Each forecast_value row is a prediction for the power output
of a site over a target datetime interval. Many predictions
are made for each site at each target interval.
*Approximate size: *
*Approximate size: *
One forecast value every 5 minutes per site per forecast.
Each forecast"s prediction sequence covers 24 hours of target
intervals = ~324,000,000 rows per day';
Expand All @@ -145,12 +145,12 @@ COMMENT ON COLUMN "forecast_values"."forecast_generation_kw" IS 'The predicted p

COMMENT ON COLUMN "forecast_values"."forecast_uuid" IS 'The forecast sequence this forcast value belongs to';

COMMENT ON TABLE "latest_forecast_values" IS 'Each forecast_value row is a prediction for the power output
of a site over a target datetime interval. Only the most recent
COMMENT ON TABLE "latest_forecast_values" IS 'Each forecast_value row is a prediction for the power output
of a site over a target datetime interval. Only the most recent
prediction for each target time interval is stored in this table
per site.
*Approximate size: *
*Approximate size: *
One forecast value every 5 minutes per site per forecast
sequence = ~1,125,000 rows per day';

Expand All @@ -166,18 +166,18 @@ COMMENT ON COLUMN "latest_forecast_values"."forecast_version" IS 'The semantic v

COMMENT ON TABLE "clients" IS 'Each client row defines a provider of site data
*Approximate size: *
*Approximate size: *
One row per client = ~4 rows';

COMMENT ON TABLE "datetime_intervals" IS 'Each datetime_interval row defines a timespan between a start and end time
*Approximate size: *
*Approximate size: *
One interval every 5 minutes per day = ~288 rows per day';

COMMENT ON TABLE "status" IS 'Each status row defines a message reporting on the status of the
services within the nowcasting domain
*Approximate size: *
*Approximate size: *
~1 row per day';

ALTER TABLE "sites" ADD FOREIGN KEY ("client_uuid") REFERENCES "clients" ("client_uuid");
Expand Down
60 changes: 30 additions & 30 deletions pvsite.dbml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Project pvsite {
database_type: 'PostgreSQL'

Note: '''
Datamodel for PV site-level data. To be surfaced via
the to-be built nowcasting site-level API and frontend.
Expand All @@ -23,17 +23,17 @@ Table sites {
created_utc timestamp [not null]
updated_utc timestamp [not null]
ml_id serial [note: 'Auto-incrementing integer ID of the site for use in ML training']

Indexes {
(client_uuid, client_site_id) [unique, name: 'idx_client']
}

Note: '''
Each site row specifies a single panel or cluster of panels
found on a residential house or commercial building. Their
data is provided by a client.
*Approximate size: *

*Approximate size: *
4 clients * ~1000 sites each = ~4000 rows
'''
}
Expand All @@ -44,12 +44,12 @@ Table generation {
power_kw real [not null, note: 'The actual generated power in kW at this site for this datetime interval']
datetime_interval_uuid uuid [not null, note: 'The time interval over which this generated power value applies']
created_utc timestamp [not null]

Note: '''
Each yield row specifies a generated power output over a
given time range for a site.
*Approximate size: *

*Approximate size: *
Generation populated every 5 minutes per site * 4000 sites = ~1,125,000 rows per day
'''
}
Expand All @@ -59,12 +59,12 @@ Table forecasts {
site_uuid uuid [not null, note: 'The site for which the forecast sequence was generated']
created_utc timestamp [not null, note: 'The creation time of the forecast sequence']
forecast_version varchar(32) [not null, note: 'The semantic version of the model used to generate the forecast']

Note: '''
Each forecast row refers to a sequence of predicted solar generation values
over a set of target times for a site.
*Approximate size: *
over a set of target times for a site.

*Approximate size: *
One forecast per site every 5 minutes = ~1,125,000 rows per day
'''
}
Expand All @@ -75,13 +75,13 @@ Table forecast_values {
forecast_generation_kw real [not null, note: 'The predicted power generation of this site for the given time interval']
created_utc timestamp [not null]
forecast_uuid uuid [not null, note: 'The forecast sequence this forcast value belongs to']

Note: '''
Each forecast_value row is a prediction for the power output
Each forecast_value row is a prediction for the power output
of a site over a target datetime interval. Many predictions
are made for each site at each target interval.
*Approximate size: *

*Approximate size: *
One forecast value every 5 minutes per site per forecast.
Each forecast's prediction sequence covers 24 hours of target
intervals = ~324,000,000 rows per day
Expand All @@ -96,14 +96,14 @@ Table latest_forecast_values {
forecast_uuid uuid [not null, note: 'The forecast sequence this forcast value belongs to']
site_uuid uuid [not null, note: 'The site for which the forecast sequence was generated']
forecast_version varchar(32) [not null, note: 'The semantic version of the model used to generate the forecast']

Note: '''
Each forecast_value row is a prediction for the power output
of a site over a target datetime interval. Only the most recent
Each forecast_value row is a prediction for the power output
of a site over a target datetime interval. Only the most recent
prediction for each target time interval is stored in this table
per site.
*Approximate size: *

*Approximate size: *
One forecast value every 5 minutes per site per forecast
sequence = ~1,125,000 rows per day
'''
Expand All @@ -113,11 +113,11 @@ Table clients {
client_uuid uuid [primary key, not null]
client_name varchar(255) [not null]
created_utc timestamp [not null]

Note: '''
Each client row defines a provider of site data
*Approximate size: *

*Approximate size: *
One row per client = ~4 rows
'''
}
Expand All @@ -127,16 +127,16 @@ Table datetime_intervals {
start_utc timestamp [not null]
end_utc timestamp [not null]
created_utc timestamp [not null]

Indexes {
start_utc
end_utc
}

Note: '''
Each datetime_interval row defines a timespan between a start and end time
*Approximate size: *

*Approximate size: *
One interval every 5 minutes per day = ~288 rows per day
'''
}
Expand All @@ -150,8 +150,8 @@ Table status {
Note: '''
Each status row defines a message reporting on the status of the
services within the nowcasting domain
*Approximate size: *

*Approximate size: *
~1 row per day
'''
}
Expand Down
4 changes: 1 addition & 3 deletions sdk/python/pvsite_datamodel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Python SDK for reading/writing to/from pvsite database
"""
"""Python SDK for reading/writing to/from pvsite database."""

from .connection import DatabaseConnection
from .sqlmodels import (
Expand Down
15 changes: 8 additions & 7 deletions sdk/python/pvsite_datamodel/connection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Database Connection class"""
"""Database Connection class."""
import logging

from sqlalchemy import create_engine
Expand All @@ -10,19 +10,20 @@


class DatabaseConnection:
"""Database connection class"""
"""Database connection class."""

def __init__(self, url: URL | str, echo: bool = True):
"""
Set up database connection
"""Set up database connection.
url: the database url, used for connecting
:param url: the database url, used for connecting
:param echo: whether to echo
"""
self.url = url
self.engine = create_engine(self.url, echo=echo)
self.Session = sessionmaker(bind=self.engine)
assert self.url is not None, Exception("Need to set url for database connection")
if self.url is None:
raise Exception("Need to set url for database connection")

def get_session(self) -> Session:
"""Get sqlalamcy session"""
"""Get sqlalchemy session."""
return self.Session()
15 changes: 6 additions & 9 deletions sdk/python/pvsite_datamodel/read/generation.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
""" Read pv generation functions """
"""Read pv generation functions."""
import logging
import uuid
from datetime import datetime
from typing import List, Optional

from pvsite_datamodel.sqlmodels import ClientSQL, DatetimeIntervalSQL, GenerationSQL, SiteSQL
from sqlalchemy.orm import Session

from pvsite_datamodel.sqlmodels import ClientSQL, DatetimeIntervalSQL, GenerationSQL, SiteSQL

from .utils import filter_query_by_datetime_interval

logger = logging.getLogger(__name__)
Expand All @@ -18,16 +19,14 @@ def get_pv_generation_by_client(
end_utc: Optional[datetime] = None,
client_names: Optional[List[str]] = None,
) -> List[GenerationSQL]:
"""
Get the generation data by client
"""Get the generation data by client.
:param session: database session
:param end_utc: search filters < on 'datetime_utc'. Can be None
:param start_utc: search filters >= on 'datetime_utc'. Can be None
:param client_names: optional list of provider names
:return:list of pv yields
:return:list of pv yields.
"""

# start main query
query = session.query(GenerationSQL)
query = query.join(SiteSQL)
Expand Down Expand Up @@ -58,16 +57,14 @@ def get_pv_generation_by_sites(
end_utc: Optional[datetime] = None,
site_uuids: Optional[List[uuid.UUID]] = None,
) -> List[GenerationSQL]:
"""
Get the generation data by site
"""Get the generation data by site.
:param session: database session
:param start_utc: search filters >= on 'datetime_utc'
:param end_utc: search fileters < on 'datetime_utc'
:param site_uuids: optional list of site uuids
:return: list of pv yields
"""

# start main query
query = session.query(GenerationSQL)
query = query.join(SiteSQL)
Expand Down
Loading

0 comments on commit 9a25276

Please sign in to comment.