Skip to content

Commit

Permalink
Merge pull request #7 from psrenergy/feature/file
Browse files Browse the repository at this point in the history
Improve TimeSeriesFileData
  • Loading branch information
raphasampaio authored Sep 21, 2024
2 parents 5e7bda2 + c120720 commit 3211b4c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 15 deletions.
6 changes: 1 addition & 5 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,7 @@ macro collection(expression)
getters_field(name = name, name_snakecase = name_snakecase, function_name = function_name, field_name = field_name)...,
)

if field_type == :TimeSeriesFileData
push!(getters,
getters_callable(name = name, name_snakecase = name_snakecase, function_name = function_name, field_name = field_name)...,
)
else
if field_type != :TimeSeriesFileData
push!(getters,
getters_array1(name = name, name_snakecase = name_snakecase, function_name = function_name, field_name = field_name)...,
)
Expand Down
30 changes: 30 additions & 0 deletions test/build.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
function add_thermal_plant!(db::DatabaseSQLite; kwargs...)
PSRI.create_element!(db, "ThermalPlant"; kwargs...)
return nothing
end

function add_hydro_plant!(db::DatabaseSQLite; kwargs...)
PSRI.create_element!(db, "HydroPlant"; kwargs...)
return nothing
end

function build_thermal_plant_label(i::Integer)
return "Thermal Plant $i"
end
Expand Down Expand Up @@ -30,6 +40,14 @@ function build_int(date_time::DateTime)
return Dates.month(date_time)
end

function build_thermal_plant_file()
return "thermal_plant_file"
end

function build_hydro_plant_file()
return "hydro_plant_file"
end

function build_database(path::AbstractString)
println("Building database")

Expand Down Expand Up @@ -67,6 +85,12 @@ function build_database(path::AbstractString)
)
end

PSRI.link_series_to_file(
db,
"ThermalPlant";
time_series_file = build_thermal_plant_file(),
)

for i in 1:HYDRO_PLANT_SIZE
add_hydro_plant!(db;
label = build_hydro_plant_label(i),
Expand All @@ -82,6 +106,12 @@ function build_database(path::AbstractString)
)
end

PSRI.link_series_to_file(
db,
"HydroPlant";
time_series_file = build_thermal_plant_file(),
)

PSRDatabaseSQLite.close!(db)

return nothing
Expand Down
22 changes: 12 additions & 10 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ include("build.jl")
time_series_float::TimeSeriesVectorData{Float64} = "time_series_float"
time_series_int::TimeSeriesVectorData{Int} = "time_series_int"
time_series_bool::TimeSeriesVectorData{Bool} = "time_series_bool"

time_series_file::TimeSeriesFileData = "time_series_file"

adjusted_vector_float::AdjustedVectorData{Float64} = AdjustedVectorData{Float64}()
adjusted_vector_int::AdjustedVectorData{Int} = AdjustedVectorData{Int}()
Expand All @@ -43,11 +45,6 @@ include("build.jl")
# spill_to_index::MapData = ("HydroPlant", "spill_to")
end

function add_hydro_plant!(db::DatabaseSQLite; kwargs...)
PSRI.create_element!(db, "HydroPlant"; kwargs...)
return nothing
end

function PSRBridge.adjust!(collection::HydroPlant, collections::AbstractCollections, db::DatabaseSQLite; kwargs...)
return nothing
end
Expand All @@ -64,18 +61,15 @@ end
time_series_int::TimeSeriesVectorData{Int} = "time_series_int"
time_series_bool::TimeSeriesVectorData{Bool} = "time_series_bool"

time_series_file::TimeSeriesFileData = "time_series_file"

adjusted_vector_float::AdjustedVectorData{Float64} = AdjustedVectorData{Float64}()
adjusted_vector_int::AdjustedVectorData{Int} = AdjustedVectorData{Int}()
adjusted_vector_bool::AdjustedVectorData{Bool} = AdjustedVectorData{Bool}()

_internal_data::String = "internal_data"
end

function add_thermal_plant!(db::DatabaseSQLite; kwargs...)
PSRI.create_element!(db, "ThermalPlant"; kwargs...)
return nothing
end

function PSRBridge.adjust!(collection::ThermalPlant, collections::AbstractCollections, db::DatabaseSQLite; kwargs...)
size = length(collection)

Expand Down Expand Up @@ -137,6 +131,14 @@ function test_all()
@test thermal_plant_label(inputs.collections) == labels
@test thermal_plant_label(inputs) == labels

@test hydro_plant_time_series_file(inputs.collections.hydro_plant) == build_hydro_plant_file()
@test hydro_plant_time_series_file(inputs.collections) == build_hydro_plant_file()
@test hydro_plant_time_series_file(inputs) == build_hydro_plant_file()

@test thermal_plant_time_series_file(inputs.collections.thermal_plant) == build_thermal_plant_file()
@test thermal_plant_time_series_file(inputs.collections) == build_thermal_plant_file()
@test thermal_plant_time_series_file(inputs) == build_thermal_plant_file()

for i in 1:HYDRO_PLANT_SIZE
label = build_hydro_plant_label(i)
@test hydro_plant_label(inputs.collections.hydro_plant, i) == label
Expand Down
8 changes: 8 additions & 0 deletions test/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ CREATE TABLE HydroPlant_time_series_parameters (
PRIMARY KEY (id, date_time)
) STRICT;

CREATE TABLE HydroPlant_time_series_files (
time_series_file TEXT NOT NULL
) STRICT;

CREATE TABLE ThermalPlant (
id INTEGER PRIMARY KEY AUTOINCREMENT,
label TEXT UNIQUE NOT NULL,
Expand All @@ -40,4 +44,8 @@ CREATE TABLE ThermalPlant_time_series_parameters (
time_series_bool INTEGER,
FOREIGN KEY(id) REFERENCES ThermalPlant(id) ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY (id, date_time)
) STRICT;

CREATE TABLE ThermalPlant_time_series_files (
time_series_file TEXT NOT NULL
) STRICT;

0 comments on commit 3211b4c

Please sign in to comment.