-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'openclimatefix:main' into main
- Loading branch information
Showing
15 changed files
with
1,695 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" | |
|
||
[project] | ||
name = "quartz_solar_forecast" | ||
version = "1.0.75" | ||
version = "1.0.81" | ||
description = "Open Source Solar Forecasting for a Site" | ||
authors = [ | ||
{ name = "Peter Dudfield", email = "[email protected]" } | ||
|
@@ -43,6 +43,9 @@ package-data = { "quartz_solar_forecast" = ["*"] } | |
|
||
[project.optional-dependencies] | ||
dev = [] | ||
# additional vendor-specific dependencies for connecting to inverter APIs | ||
inverters = ["ocf_vrmapi"] # victron | ||
all = ["ocf_vrmapi"] | ||
|
||
[tool.mypy] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from typing import Callable | ||
|
||
import pandas as pd | ||
from datetime import datetime, timedelta | ||
from quartz_solar_forecast.inverters.inverter import AbstractInverter | ||
from pydantic import Field | ||
from pydantic_settings import BaseSettings, SettingsConfigDict | ||
try: | ||
from ocf_vrmapi.vrm import VRM_API | ||
except: | ||
print("Tried to import ocf_vrmapi but couldnt, Victron Inverter functions won't work") | ||
|
||
class VictronSettings(BaseSettings): | ||
model_config = SettingsConfigDict(env_file='.env', extra='ignore') | ||
|
||
username: str = Field(alias="VICTRON_USER") | ||
password: str = Field(alias="VICTRON_PASS") | ||
|
||
|
||
class VictronInverter(AbstractInverter): | ||
|
||
def __init__(self, get_sites: Callable, get_kwh_stats: Callable): | ||
self.__get_sites = get_sites | ||
self.__get_kwh_stats = get_kwh_stats | ||
|
||
@classmethod | ||
def from_settings(cls, settings: VictronSettings): | ||
api = VRM_API(username=settings.username, password=settings.password) | ||
get_sites = lambda: api.get_user_sites(api.user_id) | ||
end = datetime.now() | ||
start = end - timedelta(weeks=1) | ||
get_kwh_stats = lambda site_id: api.get_kwh_stats(site_id, start=start, end=end) | ||
return cls(get_sites, get_kwh_stats) | ||
|
||
def get_data(self, ts: pd.Timestamp) -> pd.DataFrame: | ||
sites = self.__get_sites() | ||
# get first site (bit of a guess) | ||
first_site_id = sites["records"][0]["idSite"] | ||
|
||
stats = self.__get_kwh_stats(first_site_id) | ||
|
||
kwh = stats["records"]["kwh"] | ||
|
||
df = pd.DataFrame(kwh) | ||
|
||
df[0] = pd.to_datetime(df[0], unit='ms') | ||
df.columns = ["timestamp", "power_kw"] | ||
return df |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.