diff --git a/Project.toml b/Project.toml index 9d96a92..27cc435 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "GrafCSV" uuid = "070ba913-1d04-4147-8b30-d43c8af0fb3e" -version = "0.2.3" +version = "0.3.0" [deps] CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" diff --git a/src/reader.jl b/src/reader.jl index 99618ef..efaf33c 100644 --- a/src/reader.jl +++ b/src/reader.jl @@ -22,9 +22,13 @@ mutable struct Reader <: PSRI.AbstractReader is_hourly::Bool end +function _parse_agents(row::AbstractVector{Symbol}) + return strip.(string.(row)[4:end]) +end + function _parse_unit(header::AbstractVector{<:AbstractString}) first_line_splitted = split(header[1], ',') - return first_line_splitted[4] + return strip(first_line_splitted[4]) end function _parse_stage_type(header::AbstractVector{<:AbstractString}) @@ -114,7 +118,7 @@ function PSRI.open( end rows_iterator = CSV.Rows(PATH_CSV; header = 4) - agent_names = string.(rows_iterator.names)[4:end] + agent_names = _parse_agents(rows_iterator.names) num_agents = length(agent_names) current_row, current_row_state = iterate(rows_iterator) diff --git a/test/data/businj.csv b/test/data/businj.csv new file mode 100644 index 0000000..31f2825 --- /dev/null +++ b/test/data/businj.csv @@ -0,0 +1,5 @@ +Varies per block? , 2,Unit ,MW , 2, 1, 2003 +Varies per sequence? , 1 +# of agents , 3 +Stag,Seq.,Blck,Barra 1 ,Barra 2 ,Barra 3 + 1, 1, 1, 10.000 , 2.0000 , -12.000 diff --git a/test/issues.jl b/test/issues.jl new file mode 100644 index 0000000..207e3d7 --- /dev/null +++ b/test/issues.jl @@ -0,0 +1,22 @@ +function issue13() + path = joinpath(".", "data", "businj") + + reader = PSRI.open( + GrafCSV.Reader, + path, + ) + + @test PSRI.data_unit(reader) == "MW" + @test PSRI.stage_type(reader) == PSRI.STAGE_MONTH + @test PSRI.initial_stage(reader) == 1 + @test PSRI.initial_year(reader) == 2003 + + @test PSRI.max_agents(reader) == 3 + @test PSRI.agent_names(reader)[1] == "Barra 1" + @test PSRI.agent_names(reader)[2] == "Barra 2" + @test PSRI.agent_names(reader)[3] == "Barra 3" +end + +function test_issues() + @testset "Issue 13" begin issue13() end +end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index c1a3eb5..38041b3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,11 +7,13 @@ include("utils.jl") include("read_and_write_monthly.jl") include("read_and_write_hourly.jl") include("time_series_utils.jl") +include("issues.jl") function test_all() @testset "Read and write with monthly data" begin test_read_and_write_monthly() end @testset "Read and write with hourly data" begin test_read_and_write_hourly() end @testset "Utils" begin test_time_series_utils() end + @testset "Issues" begin test_issues() end end test_all()