diff --git a/src/macros.jl b/src/macros.jl index 72eeb2a..92a9d2c 100644 --- a/src/macros.jl +++ b/src/macros.jl @@ -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)..., ) diff --git a/test/build.jl b/test/build.jl index 3b5dc22..03cdee6 100644 --- a/test/build.jl +++ b/test/build.jl @@ -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 @@ -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") @@ -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), @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 5469325..3e0f369 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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}() @@ -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 @@ -64,6 +61,8 @@ 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}() @@ -71,11 +70,6 @@ end _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) @@ -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 diff --git a/test/schema.sql b/test/schema.sql index 9fee281..7582ed0 100644 --- a/test/schema.sql +++ b/test/schema.sql @@ -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, @@ -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; \ No newline at end of file