Skip to content

Commit

Permalink
ran both providers locally
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield committed Jan 3, 2024
1 parent 79ad90f commit f96add7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pvconsumer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def pull_data_and_save(
pv_system_chunks = chunks(original_list=pv_systems, n=n_pv_systems_per_batch)

all_pv_yields_df = []
i = 0
for pv_system_chunk in pv_system_chunks:
if provider == "pvoutput.org":
# set up pv output.org
Expand Down Expand Up @@ -155,7 +156,8 @@ def pull_data_and_save(
else:
raise Exception(f"Can not use provider {provider}")

for i, pv_system in enumerate(pv_system_chunk):
for _, pv_system in enumerate(pv_system_chunk):
i = i + 1
logger.debug(
f"Processing {i}th pv system ({pv_system.client_site_id=}), "
f"out of {len(pv_systems)}"
Expand Down
4 changes: 3 additions & 1 deletion pvconsumer/pv_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def get_pv_systems(
pv_system.latitude = metadata.latitude
pv_system.longitude = metadata.longitude
pv_system.status_interval_minutes = int(metadata.status_interval_minutes)
pv_system.capacity_kw = metadata.system_DC_capacity_W / 1000

elif provider == solar_sheffield_passiv:
pv_system = pv_systems[pv_systems["pv_system_id"] == pv_system.pv_system_id].iloc[0]
Expand Down Expand Up @@ -214,11 +215,12 @@ def filter_pv_systems_which_have_new_data(
session.query(SiteSQL.site_uuid, GenerationSQL.start_utc)
.distinct(
GenerationSQL.site_uuid,
GenerationSQL.start_utc,
# GenerationSQL.start_utc,
)
.join(SiteSQL)
.filter(
GenerationSQL.start_utc <= datetime_utc,
GenerationSQL.start_utc >= datetime_utc - timedelta(days=1),
GenerationSQL.site_uuid.in_(site_uuids),
)
.order_by(
Expand Down
9 changes: 8 additions & 1 deletion pvconsumer/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""" Utils functions """
import logging
from datetime import timezone
from datetime import datetime, timedelta, timezone

import pandas as pd
from pvsite_datamodel.sqlmodels import GenerationSQL, SiteSQL
Expand Down Expand Up @@ -51,10 +51,17 @@ def format_pv_data(pv_system: SiteSQL, pv_yield_df: pd.DataFrame, session: Sessi
pv_yield_df.drop(pv_yield_df.tail(1).index, inplace=True)

# 2. filter by last
if len(pv_yield_df) > 0:
start_utc_filter = pv_yield_df["datetime_utc"].min() - timedelta(days=1)
else:
start_utc_filter = datetime.now() - timedelta(days=1)

last_pv_generation = (
session.query(GenerationSQL)
.filter(GenerationSQL.site_uuid == pv_system.site_uuid)
.join(SiteSQL)
.filter(SiteSQL.site_uuid == pv_system.site_uuid)
.filter(GenerationSQL.start_utc > start_utc_filter)
.order_by(GenerationSQL.created_utc.desc())
.first()
)
Expand Down

0 comments on commit f96add7

Please sign in to comment.