Skip to content

Commit

Permalink
Merge pull request #17 from psrenergy/feature/name
Browse files Browse the repository at this point in the history
Removed trailing spaces from agents name and unit
  • Loading branch information
raphasampaio authored Nov 23, 2023
2 parents 1f07471 + 11132aa commit b5aed2a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
8 changes: 6 additions & 2 deletions src/reader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions test/data/businj.csv
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions test/issues.jl
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit b5aed2a

Please sign in to comment.