Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data file parsing is custom, consider using DataFrames #16

Open
odow opened this issue Dec 13, 2022 · 1 comment
Open

Data file parsing is custom, consider using DataFrames #16

odow opened this issue Dec 13, 2022 · 1 comment

Comments

@odow
Copy link
Collaborator

odow commented Dec 13, 2022

x-ref #12 (comment)

We essentially have a customized CSV reader:

JADE.jl/src/data.jl

Lines 10 to 67 in b705880

"""
parsefile(f::Function, file::String, trim::Bool = false)
This function reads in a data file and extracts each of the non-comment / non-empty rows,
splits into into a vector using ',' as the delimiter, and then applies some custom processing `f`.
### Required Arugments
`f` custom function that processes a line of the data file.
`file` path of the file.
### Keyword Arguments
`trim` if `true` trailing commas will be discarded.
"""
function parsefile(f::Function, file::String, trim::Bool = false)
open(file, "r") do io
while !eof(io)
items, skip_line = getitems(io, trim)
skip_line && continue
f(items)
end
end
end
"""
getitems(io::IOStream, trim::Bool)
This function takes an `IOStream` for a CSV file and reading the first line, decarding empty / comment rows, and
otherwise splitting into into a vector using ',' as the delimiter. This vector is returned.
### Required Arugments
`io` `IOStream` object for a CSV file.
`trim` if `true` trailing commas will be discarded.
"""
function getitems(io::IOStream, trim::Bool)
line = strip(readline(io))
if (line == "" || first(line) == '%') # comment char
return String[], true
end
# drop trailling comments
line = split(line, '%')[1]
items = strip.(split(line, ","))
if trim
while length(items) > 0 && items[end] == ""
deleteat!(items, length(items))
end
end
if length(items) == 0 || maximum(length.(items)) == 0
return String[], true
end
return items, false
end

evaluate whether this is the best solution.

@adow031
Copy link
Member

adow031 commented Dec 20, 2022

The formats for files were inherited from DOASA to ensure backward compatibility for the EA's tests. Late in the process it was decided not to maintain this backwards compatibility strictly..but files didn't change.

Some of the files have optional alternative options, so I might be able to standardise things, but will need to maintain the old code until JADE 2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants