-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use descriptive_name for filenames and errors
- Loading branch information
Showing
3 changed files
with
126 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# diagnostic_utils.jl | ||
# | ||
# This file contains: | ||
# - get_descriptive_name: to condense ScheduledDiagnostic information into few characters. | ||
|
||
|
||
""" | ||
get_descriptive_name(variable::DiagnosticVariable, | ||
output_every, | ||
reduction_time_func; | ||
units_are_seconds = true) | ||
Return a compact, unique-ish, identifier generated from the given information. | ||
`output_every` is interpreted as in seconds if `units_are_seconds` is `true`. Otherwise, it | ||
is interpreted as in units of number of iterations. | ||
This function is useful for filenames and error messages. | ||
""" | ||
|
||
function get_descriptive_name( | ||
variable::DiagnosticVariable, | ||
output_every, | ||
reduction_time_func; | ||
units_are_seconds = true, | ||
) | ||
var = "$(variable.short_name)" | ||
isa_reduction = !isnothing(reduction_time_func) | ||
|
||
if units_are_seconds | ||
if isa_reduction | ||
red = "$(reduction_time_func)" | ||
|
||
# Convert period from seconds to days, hours, minutes, seconds | ||
period = "" | ||
|
||
days, rem_seconds = divrem(output_every, 24 * 60 * 60) | ||
hours, rem_seconds = divrem(rem_seconds, 60 * 60) | ||
minutes, seconds = divrem(rem_seconds, 60) | ||
|
||
if days > 0 | ||
period *= "$(days)d_" | ||
end | ||
if hours > 0 | ||
period *= "$(hours)h_" | ||
end | ||
if minutes > 0 | ||
period *= "$(minutes)m_" | ||
end | ||
if seconds > 0 | ||
period *= "$(seconds)s_" | ||
end | ||
|
||
suffix = period * red | ||
else | ||
# Not a reduction | ||
suffix = "inst" | ||
end | ||
else | ||
if isa_reduction | ||
suffix = "$(output_every)it_(reduction_time_func)" | ||
else | ||
suffix = "inst" | ||
end | ||
end | ||
return "$(var)_$(suffix)" | ||
end |