Add report generation package - #92
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #92 +/- ##
==========================================
+ Coverage 84.14% 84.97% +0.82%
==========================================
Files 45 49 +4
Lines 2491 2768 +277
==========================================
+ Hits 2096 2352 +256
- Misses 395 416 +21 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new PRASReport.jl package to the PRAS ecosystem that generates interactive HTML reports for power system resource adequacy analysis results. The package extracts "events" (periods of energy shortfall above a threshold) from PRAS simulation results and creates visualizations using embedded databases and web technologies.
Key changes:
- Implements event extraction and analysis from PRAS
ShortfallResultobjects - Creates interactive HTML reports with charts and tabular views using DuckDB WASM
- Provides multiple input methods (results, system models, or file paths)
Reviewed Changes
Copilot reviewed 16 out of 18 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| PRASReport.jl/src/ | Core package implementation with event extraction, database operations, and HTML report generation |
| PRASReport.jl/test/ | Test suite covering event extraction and report generation workflows |
| PRASReport.jl/examples/ | Example usage script |
| PRASCore.jl/src/Results/ | Extension to support new NEUE calculations needed by reporting |
| .github/workflows/ | CI configuration for the new package |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| regions::Vector{String} | ||
| ) where {N,L,T,E} | ||
|
|
||
| length(lole) != length(eue) != length(neue) != length(regions) && |
There was a problem hiding this comment.
This chained inequality comparison doesn't work as intended in Julia. It should be length(lole) != length(eue) || length(eue) != length(neue) || length(neue) != length(regions) to check that all vectors have equal length.
| length(lole) != length(eue) != length(neue) != length(regions) && | |
| (length(lole) != length(eue) || length(eue) != length(neue) || length(neue) != length(regions)) && |
| _write_db!(::ShortfallResult{N,L,T,E}, ::FlowResult{N,L,T,P}, | ||
| threshold::Int, conn::DuckDB.Connection) | ||
|
|
||
| Write system and simulation parameters to the parameters table. | ||
| """ | ||
| function _write_db!(sf::ShortfallResult{N,L,T,E}, | ||
| ::FlowResult{N,L,T,P}, | ||
| threshold::Int64, |
There was a problem hiding this comment.
The second parameter is unused (anonymous with ::FlowResult). If the FlowResult is not needed for this function, consider removing it from the signature or document why it's required for the interface.
| _write_db!(::ShortfallResult{N,L,T,E}, ::FlowResult{N,L,T,P}, | |
| threshold::Int, conn::DuckDB.Connection) | |
| Write system and simulation parameters to the parameters table. | |
| """ | |
| function _write_db!(sf::ShortfallResult{N,L,T,E}, | |
| ::FlowResult{N,L,T,P}, | |
| threshold::Int64, | |
| _write_db!(sf::ShortfallResult{N,L,T,E}, | |
| threshold::Int, conn::DuckDB.Connection) | |
| Write system and simulation parameters to the parameters table. | |
| """ | |
| function _write_db!(sf::ShortfallResult{N,L,T,E}, | |
| threshold::Int64, |
There was a problem hiding this comment.
Not sure why this was marked resolved.
…bse; Remove views in the db schema, can bring back in later if needed; Make many functions internal and don't export
26d3d92 to
23c1488
Compare
| function NEUE(x::ShortfallResult{N,L,T,E}, r::AbstractString, t::ZonedDateTime) where {N,L,T,E} | ||
| i_r = findfirstunique(x.regions.names, r) | ||
| i_t = findfirstunique(x.timestamps, t) | ||
| return NEUE(div(MeanEstimate(x[r, t]..., x.nsamples),x.regions.load[i_r,i_t]/1e6)) |
There was a problem hiding this comment.
Check if the load = 0 update ever made it through as tests might fail.
There was a problem hiding this comment.
Not sure if this should be here. We don't have this in any other repos.
| CREATE TABLE events ( | ||
| id INTEGER PRIMARY KEY DEFAULT nextval('eventid_sequence'), | ||
| name TEXT NOT NULL, | ||
| start_timestamp TIMESTAMP WITHOUT TIME ZONE NOT NULL, |
There was a problem hiding this comment.
Is this different from the start_timestamp in the systemsinfo table?
| @@ -0,0 +1,95 @@ | |||
| -- System and Simulation parameters | |||
There was a problem hiding this comment.
General comment here: DuckDB is incredbly fast at doing some of the calculatins we do for EUE, nEUE, etc. I know this might mean a full overhaul of the schema but something to think about.
| regions::Vector{String} | ||
| ) where {N,L,T,E} | ||
|
|
||
| length(lole) != length(eue) != length(neue) != length(regions) && |
| @@ -0,0 +1,141 @@ | |||
| """ | |||
There was a problem hiding this comment.
General comment: Is the API we want to go with? I don't have any comments on the code here, I'm not sure `create_pras_report(args, kwargs,) is what we like?
| _write_db!(::ShortfallResult{N,L,T,E}, ::FlowResult{N,L,T,P}, | ||
| threshold::Int, conn::DuckDB.Connection) | ||
|
|
||
| Write system and simulation parameters to the parameters table. | ||
| """ | ||
| function _write_db!(sf::ShortfallResult{N,L,T,E}, | ||
| ::FlowResult{N,L,T,P}, | ||
| threshold::Int64, |
There was a problem hiding this comment.
Not sure why this was marked resolved.
| threshold::Int=0, | ||
| title::String="Resource Adequacy Report") | ||
|
|
||
| base64_db = _get_base64_db((system_path,);threshold=threshold, |
There was a problem hiding this comment.
Why can't we load the system and call the function above?
| threshold=0, | ||
| samples=nothing, seed=nothing) where {N,L,T,P,E} | ||
|
|
||
| if isnothing(conn) |
There was a problem hiding this comment.
This gets called from _get_base64_db. I guess I don't understand why conn would ever be Nothing?
| events = get_events(sf,threshold) | ||
|
|
||
| # Write events to database (events, system metrics, regional metrics) | ||
| foreach(event -> _write_db!(event,conn), events) |
There was a problem hiding this comment.
Could you use the appender API here?
|
Couple of other comments:
|
No description provided.