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

Fit data extract function from log and test cases #165

Merged
merged 9 commits into from
Jul 23, 2024
42 changes: 42 additions & 0 deletions src/parse_log.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# parse_log.jl

"""
parse_log(log)

Parse a log of actions and extract model fitting entries into a dictionary.

# Arguments
- `log`: A list of tuples representing log entries.

# Returns
A dictionary where keys are model names and values are lists of dictionaries,
each containing model parameters, error, and index from the log.

# Example
```julia
data.log = [...] # Define your log data
models_data = parse_log(data.log)
println(models_data)

"""
function parse_log(log)
models_dict = Dict{String, Vector{Dict{String, Any}}}()

for (idx, entry) in enumerate(log)
if entry.action.funct == :modelfit
model_name = entry.info.model_name
model_params = entry.info.model_params
error = entry.info.error
SAYANTANDE marked this conversation as resolved.
Show resolved Hide resolved

model_entry = Dict("params" => model_params, "error" => error, "index" => idx)
SAYANTANDE marked this conversation as resolved.
Show resolved Hide resolved

if haskey(models_dict, model_name)
push!(models_dict[model_name], model_entry)
else
models_dict[model_name] = [model_entry]
end
end
end

return models_dict
end