Skip to content
Snippets Groups Projects
Commit 1330423b authored by Florian Atteneder's avatar Florian Atteneder
Browse files

fix sorting of output directories and make prev next buttons periodic

parent db37608d
No related branches found
No related tags found
No related merge requests found
experiments
......@@ -115,10 +115,10 @@ function append_to(base_string, str)
end
function header_template(route_name, id, dir; skip_prev=false, skip_next=false)
function header_template(route_name, id, dir; prev_id=missing, next_id=missing)
link_prev = linkto(Symbol(route_name), sim_id=id-1)
link_next = linkto(Symbol(route_name), sim_id=id+1)
link_prev = linkto(Symbol(route_name), sim_id=prev_id)
link_next = linkto(Symbol(route_name), sim_id=next_id)
header_home_button = """
<a class="home" href="/">Home</a>
......@@ -134,9 +134,9 @@ function header_template(route_name, id, dir; skip_prev=false, skip_next=false)
"""
header = header_home_button
!skip_prev && (header = append_to(header, header_prev_button))
!ismissing(prev_id) && (header = append_to(header, header_prev_button))
header = append_to(header, header_text)
!skip_next && (header = append_to(header, header_next_button))
!ismissing(next_id) && (header = append_to(header, header_next_button))
return header
end
......@@ -144,29 +144,39 @@ end
function generate_html_sites(route_name, id, rootdir)
outputdirs = gather_outputdirs(rootdir)
filenames_plots = []
all_ids = Int64[]
for dir in outputdirs
this_id = match(r"_(\d)+$", dir)
isnothing(this_id) && continue
push!(all_ids, parse(Int64, first(this_id.captures)))
files = glob("$dir/*.png")
push!(filenames_plots, files)
table = gather_parameters(rootdir)
list_filenames = table."filename"
all_ids = map(list_filenames) do filename
id_match = match(r"_(\d+).toml$", filename)
isnothing(id_match) && error("Encountered filename with wrong pattern: '$filename'")
return parse(Int64, first(id_match.captures))
end
!(id in all_ids) && error("Could not locate an output directory with number $id")
table = gather_parameters(rootdir)
p = sortperm(all_ids)
table = table[p,:]
all_ids = all_ids[p]
list_filenames = list_filenames[p]
list_outputdirs = map(list_filenames) do filename
basename, _ = splitallext(filename)
joinpath(rootdir, basename)
end
list_plotnames = [ glob("$dir/*.png") for dir in list_outputdirs ]
parameters = [ dg1d.to_dict(FlatDict, row) for row in eachrow(table) ]
html_tables = [ to_markdown_table(p) for p in parameters ]
html_headers = [ header_template(route_name, id, dir,
skip_prev=!((id-1) in all_ids),
skip_next=!((id+1) in all_ids)
)
for dir in outputdirs ]
html_headers = map(list_outputdirs) do dir
idx = findfirst(i -> i == id, all_ids)
n_all_ids = length(all_ids)
prev_id, next_id = if idx == 1
all_ids[end], all_ids[2]
elseif idx == n_all_ids
all_ids[n_all_ids-1], all_ids[1]
else
all_ids[idx-1], all_ids[idx+1]
end
header_template(route_name, id, dir, prev_id=prev_id, next_id=next_id)
end
html_sites = [ html_twocolumn_scrollable(header, tbl, plts)
for (header, tbl,plts) in zip(html_headers, html_tables, filenames_plots) ]
for (header, tbl, plts) in zip(html_headers, html_tables, list_plotnames) ]
return html_sites
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment