From 046e0bfa3892e83b2260bcaae69588c53ce3459a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=ADma?= Date: Tue, 31 Jan 2023 02:12:56 +0100 Subject: [PATCH] bump version --- Project.toml | 2 +- src/loadsave.jl | 26 +++++++++++++++----------- tutorial/loadsave/loadsave.jl | 5 +++-- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Project.toml b/Project.toml index a58c715..e724b65 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ReactiveDynamics" uuid = "c7456e7d-545a-4b79-91ea-6e93d96dd4d4" -version = "0.2.4" +version = "0.2.5" [deps] CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" diff --git a/src/loadsave.jl b/src/loadsave.jl index 628c947..8263166 100644 --- a/src/loadsave.jl +++ b/src/loadsave.jl @@ -14,7 +14,7 @@ const RN_attrs = string.(propertynames(ReactionNetwork().subparts)) function get_attrs(object) object = object isa Symbol ? objects_aliases[object] : object - + filter(x -> occursin(object, x), RN_attrs) end @@ -67,12 +67,15 @@ function load_network(dict::Dict) end function import_network_csv(pathmap) - dict = Dict(); for (key, paths) in pathmap + dict = Dict() + for (key, paths) in pathmap push!(dict, key => []) for path in paths - data = DataFrame(CSV.File(path; delim=";;", types=String, stripwhitespace=true, comment="#")) + data = DataFrame(CSV.File(path; delim = ";;", types = String, + stripwhitespace = true, comment = "#")) for row in eachrow(data) - object = Dict(); for (attr, val) in Iterators.zip(keys(row), values(row)) + object = Dict() + for (attr, val) in Iterators.zip(keys(row), values(row)) !ismissing(val) && push!(object, string(attr) => val) end push!(dict[key], object) @@ -85,8 +88,9 @@ end function import_network(path::AbstractString) if splitext(path)[2] == ".csv" - pathmap = Dict(val => [] for val in [collect(values(objects_aliases)); "registered"]) - for row in CSV.File(path; delim=";;", stripwhitespace=true, comment="#") + pathmap = Dict(val => [] + for val in [collect(values(objects_aliases)); "registered"]) + for row in CSV.File(path; delim = ";;", stripwhitespace = true, comment = "#") push!(pathmap[row.type], joinpath(dirname(path), row.path)) end @@ -96,7 +100,6 @@ function import_network(path::AbstractString) end end - function export_network(acs::ReactionNetwork, path::AbstractString) if splitext(path)[2] == ".csv" exported_network = export_network(acs) @@ -105,18 +108,19 @@ function export_network(acs::ReactionNetwork, path::AbstractString) push!(paths, (key, "export-$key.csv")) objs_exported = DataFrame(Dict(attr => [] for attr in get_attrs(key))) for obj in objs - push!(objs_exported, [get(obj, key, missing) for key in names(objs_exported)]) + push!(objs_exported, + [get(obj, key, missing) for key in names(objs_exported)]) end - CSV.write(joinpath(dirname(path), "export-$key.csv"), objs_exported, delim=";;") + CSV.write(joinpath(dirname(path), "export-$key.csv"), objs_exported, + delim = ";;") end - CSV.write(path, paths, delim=";;") + CSV.write(path, paths, delim = ";;") else open(io -> TOML.print(io, export_network(acs)), path, "w+") end end - """ Export model to a file: this can be either a single TOML file encoding the entire model, or a batch of CSV files (a root file and a number of files, each per a class of objects). diff --git a/tutorial/loadsave/loadsave.jl b/tutorial/loadsave/loadsave.jl index 98c35a6..1a3f51b 100644 --- a/tutorial/loadsave/loadsave.jl +++ b/tutorial/loadsave/loadsave.jl @@ -21,7 +21,8 @@ sol_ = @solve prob_ trajectories=20 # export the same model (w/o registered functions) @export_network sir_acs modell.toml -mkpath("csv_"); @export_network sir_acs "csv_/model.csv" +mkpath("csv_"); +@export_network sir_acs "csv_/model.csv"; # load multiple models @load_models models.txt @@ -31,4 +32,4 @@ mkpath("csv_"); @export_network sir_acs "csv_/model.csv" @export_solution_as_csv sol sol.csv # another test -@import_network model2.toml sir_acs_2 \ No newline at end of file +@import_network model2.toml sir_acs_2