-
Notifications
You must be signed in to change notification settings - Fork 0
Add MySQL procedure and event to forward fill table pvlive.pvgenerati… #1
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
Open
JulianBriggs
wants to merge
1
commit into
main
Choose a base branch
from
capacity
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,2 +1,8 @@ | ||
| # pvgenerationforwardfill | ||
| MySql procedure and event to forward fill table pvlive.pvgeneration | ||
|
|
||
| #Forward fill the pvgeneration table during hours of darkness today and ndays hence: | ||
| # generation_MW=0, capacity_MWp and installedcalacity_MWp same as yesterday. | ||
| #Julian Briggs | ||
| #4-feb-2025 | ||
|
|
This file contains hidden or 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,6 @@ | ||
| CREATE EVENT forwardfill | ||
| ON SCHEDULE EVERY 1 DAY | ||
| STARTS '2025-02-04 00:00:00.000' | ||
| ON COMPLETION PRESERVE | ||
| ENABLE | ||
| DO CALL pvlive.forwardfill() |
This file contains hidden or 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,50 @@ | ||
| CREATE DEFINER=`admin`@`localhost` PROCEDURE `pvlive`.`forwardfill`() | ||
| BEGIN | ||
| #Forward fill the pvgeneration table during hours of darkness today and ndays hence: | ||
| # generation_MW=0, capacity_MWp and installedcalacity_MWp same as yesterday. | ||
| #Julian Briggs | ||
| #4-feb-2025 | ||
|
|
||
| declare ndays int default 7; | ||
| # | ||
| #Create and populate a temporary table of 48 timestamps at 30 minute intervals (on the hour and half hour) | ||
| #from now (rounded up) and ndays days hence | ||
| DROP TEMPORARY TABLE IF EXISTS times; | ||
|
|
||
| DROP TEMPORARY TABLE IF EXISTS timestamps; | ||
|
|
||
| #Table times: column _time is generated from column i (just before a select) | ||
| create temporary table times (i int unsigned, _time time generated always as (time('00:00:00') + INTERVAL i * 30 MINUTE)); | ||
|
|
||
| create temporary table timestamps (_date date, datetime_GMT timestamp ); | ||
| # | ||
| #Populate table times: column _time is generated from column i (just before a select) | ||
| INSERT INTO times (i) | ||
| values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17),(18),(19),(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),(30),(31),(32),(33),(34),(35),(36),(37),(38),(39),(40),(41),(42),(43),(44),(45),(46),(47); | ||
| # | ||
| #Populate table timestamps with timestamps every 30 mins on the hour and half hour before sunrise and after sunset, today and ndays hence | ||
| insert into timestamps (datetime_GMT) select timestamp(ss.date, times._time) | ||
| from times | ||
| join pvstream.sunrise_sunset ss | ||
| where ss.date between CURRENT_DATE() and CURRENT_DATE() + interval ndays day | ||
| and times._time not between earliest_sunrise and latest_sunset; | ||
| # | ||
| #Forward fill table pvgeneration every 30 mins (on the hour and half hour) before sunrise and after sunset, today and ndays hence | ||
| #Join table pvgeneration (single row yesterday at noon) to table gsp_20220314 (to get all gsp_ids, pvgenration=0, capacity_MWp, installedcapacity_MWp) | ||
| #Then join to table timestamps (to get rows for all gsps and all (48 half hourly) datetime_gmt) | ||
| insert into | ||
| pvgeneration (gsp_id, datetime_GMT, generation_MW, capacity_MWp, installedcapacity_MWp | ||
| ) | ||
| select g.gsp_id, timestamps.datetime_GMT, 0, capacity_MWp, installedcapacity_MWp | ||
| from gsp_20220314 g | ||
| join | ||
| pvgeneration p on | ||
| (p.gsp_id = g.gsp_id | ||
| and p.datetime_gmt = timestamp(CURRENT_DATE()- interval 12 hour)) | ||
| join timestamps | ||
| order by | ||
| g.gsp_id, timestamps.datetime_GMT | ||
| ON | ||
| DUPLICATE KEY UPDATE generation_MW = 0, capacity_MWp = p.capacity_MWp, installedcapacity_MWp = p.installedcapacity_MWp; | ||
|
|
||
| END | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will soon change GSP boundaries to gsp_20250109 (on cloud) with Capacity Update; later for on-prem pending OCF finishing their work