JuliaRheology / RHEOS.jl

RHEOS - Open Source Rheology data analysis software
MIT License
39 stars 9 forks source link

Introduce functions to simplify the log management #87

Closed akabla closed 1 year ago

akabla commented 4 years ago

The code is made complex and untidy due to the construction of the log. Now that it has the right functionality, it would be good to wrap the repeated code into functions. Here is a proposal:

Adding a new process:

function logadd_process(d, action, info)
    d.log == nothing ? nothing : [d.log; RheoLogItem( (type=:process, action... ), info ) ]
end

log = logadd_process(d,  (funct=:resample, params=(), keywords=() ), comment="Resample the data",)

Add analysis:

function logadd_analysis!(d, action, info)
    if d.log != nothing 
        push!(d.log, RheoLogItem( (type=:analysis, action...), info) )
    end
end

logadd_analysis!(data, (funct=:dynamicmodelfit, params=(model=model, ), keywords=(p0=p0, lo=lo, hi=hi, rel_tol=rel_tol, weights=weights)), 
                      (comment="Fiting rheological model to frequency spectrum", model_name=model.name, model_params=nt, time_taken=timetaken, stop_reason=ret, error=minf) )

Initialize log:

function loginit(savelog, action, info)
    if savelog
        RheoLogItem( (type=:source, action...), info )
    else
        nothing
    end
end

This may need revisiting. I think loginit should return the array rather than single RheoLogItem. tbd.

akabla commented 4 years ago

Using macros may be better in case it avoids having to evaluate/create the parameter when the log is not required.