-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from psrenergy/rs/tests
Tests improvements
- Loading branch information
Showing
6 changed files
with
230 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,5 @@ docs/site/ | |
|
||
format/Manifest.toml | ||
revise/Manifest.toml | ||
|
||
*.sqlite |
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
function build_thermal_plant_label(i::Integer) | ||
return "Thermal Plant $i" | ||
end | ||
|
||
function build_thermal_plant_shutdown_cost(i::Integer) | ||
return Float64(i) | ||
end | ||
|
||
function build_thermal_plant_max_startups(i::Integer) | ||
return i | ||
end | ||
|
||
function build_hydro_plant_label(i::Integer) | ||
return "Hydro Plant $i" | ||
end | ||
|
||
function build_hydro_plant_initial_volume(i::Integer) | ||
return Float64(i) | ||
end | ||
|
||
function build_hydro_plant_has_commitment(i::Integer) | ||
return i % 2 == 0 | ||
end | ||
|
||
function build_hydro_plant_existing(date_time::DateTime) | ||
return Dates.month(date_time) % 2 == 0 | ||
end | ||
|
||
function build_hydro_plant_max_generation(date_time::DateTime) | ||
return Float64(Dates.month(date_time)) | ||
end | ||
|
||
function build_database(path::AbstractString) | ||
if isfile(path) | ||
rm(path; force = true) | ||
end | ||
|
||
path_schema = joinpath(@__DIR__, "schema.sql") | ||
|
||
db = PSRDatabaseSQLite.create_empty_db_from_schema( | ||
path, | ||
path_schema; | ||
force = true, | ||
) | ||
|
||
PSRDatabaseSQLite.create_element!( | ||
db, | ||
"Configuration"; | ||
label = "Bridge", | ||
) | ||
|
||
for i in 1:THERMAL_PLANT_SIZE | ||
add_thermal_plant!( | ||
db; | ||
label = build_thermal_plant_label(i), | ||
shutdown_cost = build_thermal_plant_shutdown_cost(i), | ||
max_startups = build_thermal_plant_max_startups(i), | ||
) | ||
end | ||
|
||
for i in 1:HYDRO_PLANT_SIZE | ||
add_hydro_plant!(db; | ||
label = build_hydro_plant_label(i), | ||
initial_volume = build_hydro_plant_initial_volume(i), | ||
has_commitment = build_hydro_plant_has_commitment(i) ? 1 : 0, | ||
parameters = DataFrame(; | ||
date_time = DATE_TIMES, | ||
existing = [build_hydro_plant_existing(date_time) ? 1 : 0 for date_time in DATE_TIMES], | ||
max_generation = [build_hydro_plant_max_generation(date_time) for date_time in DATE_TIMES], | ||
), | ||
) | ||
end | ||
|
||
PSRDatabaseSQLite.close!(db) | ||
|
||
return nothing | ||
end |
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,30 @@ | ||
PRAGMA user_version = 1; | ||
PRAGMA foreign_keys = ON; | ||
|
||
CREATE TABLE Configuration ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
label TEXT UNIQUE NOT NULL | ||
) STRICT; | ||
|
||
CREATE TABLE HydroPlant ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
label TEXT UNIQUE NOT NULL, | ||
initial_volume REAL, | ||
has_commitment INTEGER DEFAULT 0 | ||
) STRICT; | ||
|
||
CREATE TABLE HydroPlant_time_series_parameters ( | ||
id INTEGER, | ||
date_time TEXT NOT NULL, | ||
existing INTEGER, | ||
max_generation REAL, | ||
FOREIGN KEY(id) REFERENCES HydroPlant(id) ON DELETE CASCADE ON UPDATE CASCADE, | ||
PRIMARY KEY (id, date_time) | ||
) STRICT; | ||
|
||
CREATE TABLE ThermalPlant ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
label TEXT UNIQUE NOT NULL, | ||
shutdown_cost REAL, | ||
max_startups INTEGER | ||
) STRICT; |