Skip to content

Commit

Permalink
bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
thevolatilebit committed Jan 31, 2023
1 parent 86b387a commit 046e0bf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
26 changes: 15 additions & 11 deletions src/loadsave.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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)
Expand All @@ -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).
Expand Down
5 changes: 3 additions & 2 deletions tutorial/loadsave/loadsave.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
@import_network model2.toml sir_acs_2

0 comments on commit 046e0bf

Please sign in to comment.