Skip to content

Commit

Permalink
Create a seconds function
Browse files Browse the repository at this point in the history
  • Loading branch information
visr committed Apr 9, 2024
1 parent 2ddec81 commit e0f0b1d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion core/src/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1009,13 +1009,22 @@ function exists(db::DB, tablename::String)
return !isempty(query)
end

"""
seconds(period::Millisecond)::Float64
Convert a period of type Millisecond to a Float64 in seconds.
You get Millisecond objects when subtracting two DateTime objects.
Dates.value returns the number of milliseconds.
"""
seconds(period::Millisecond)::Float64 = 0.001 * Dates.value(period)

"""
seconds_since(t::DateTime, t0::DateTime)::Float64
Convert a DateTime to a float that is the number of seconds since the start of the
simulation. This is used to convert between the solver's inner float time, and the calendar.
"""
seconds_since(t::DateTime, t0::DateTime)::Float64 = 0.001 * Dates.value(t - t0)
seconds_since(t::DateTime, t0::DateTime)::Float64 = seconds(t - t0)

"""
datetime_since(t::Real, t0::DateTime)::DateTime
Expand Down
2 changes: 1 addition & 1 deletion core/src/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function basin_table(
end

time = repeat(data.time[begin:(end - 1)]; inner = nbasin)
Δtime_seconds = 0.001 * Dates.value.(diff(data.time))
Δtime_seconds = seconds.(diff(data.time))
Δtime = repeat(Δtime_seconds; inner = nbasin)
node_id = repeat(Int32.(data.node_id); outer = ntsteps)
storage_rate = Δstorage ./ Δtime
Expand Down
2 changes: 1 addition & 1 deletion utils/runstats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ toml_paths = get_testmodels()
runs = OrderedDict{String, Any}[]
for toml_path in toml_paths
config = Ribasim.Config(toml_path)
println(basename(toml_path))
println(basename(dirname(toml_path)))
# run first to compile, if this takes too long perhaps we can shorten the duration
Ribasim.run(config)
timed = @timed Ribasim.run(config)
Expand Down

0 comments on commit e0f0b1d

Please sign in to comment.