Skip to content

Commit

Permalink
enh: improve metadata display
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Jul 1, 2024
1 parent a558a8f commit 5636f44
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
0.9.2
- enh: show metadata table caption at top
- enh: show "pipeline" metadata
- enh: html.escape displayed metadata
- enh: display correct alias medium
0.9.1
- ref: do not use tempfile.TemporaryDirectory
- ref: create /tmp/matplotlib before importing matplotlib
Expand Down
6 changes: 3 additions & 3 deletions ckanext/dc_view/assets/dc_view.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
-webkit-column-count: 3;
-moz-column-count: 3;
column-count: 3;
-webkit-column-width: 320px;
-moz-column-width: 320px;
column-width: 320px;
-webkit-column-width: 350px;
-moz-column-width: 350px;
column-width: 350px;
}


Expand Down
36 changes: 20 additions & 16 deletions ckanext/dc_view/meta.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import html
import numbers

import dclab
from dclab.features.emodulus.viscosity import ALIAS_MEDIA


def render_metadata_html(res_dict):
Expand All @@ -13,26 +15,27 @@ def render_metadata_html(res_dict):
meta[sec] = {}
meta[sec][key] = res_dict[dckey]

html = []
html_code = []
for sec in ["experiment", "pipeline", "setup", "imaging", "fluorescence"]:
if sec in meta:
html += meta_html_table(meta, sec)
html.append("<br>")
html_code += meta_html_table(meta, sec)
html_code.append("<br>")

return "\n".join(html)
return "\n".join(html_code)


def meta_html_table(meta, sec):
html = [
'<table class="table table-striped table-bordered table-condensed dc_view">',
html_code = [
'<table class="table table-striped '
+ 'table-bordered table-condensed dc_view">',
f'<caption class="dc_view">{sec.capitalize()}</caption>',
]

kn = [(dclab.dfn.config_descr[sec][key], key) for key in meta[sec].keys()]
for name, key in sorted(kn):
value = meta[sec][key]
if isinstance(value, numbers.Number):
value = "{:.4g}".format(value)
value = f"{value:.4g}"

# Special cases
if sec == "experiment":
Expand All @@ -43,8 +46,9 @@ def meta_html_table(meta, sec):
elif sec == "setup":
if key == "chip region":
name = name.split(" (")[0]
elif key == "medium" and value == "CellCarrierB":
value = "CellCarrier B"
elif key == "medium" and value in ALIAS_MEDIA:
# Convert names to common names
value = ALIAS_MEDIA[value]
elif key == "module composition":
name = "Modules used"
value = ", ".join(value.split(","))
Expand All @@ -57,11 +61,11 @@ def meta_html_table(meta, sec):
units = units.strip("] ")
value += " " + units

html += [
'<tr>',
u'<th class="dataset-labels">{}</th>'.format(name),
u'<td class="dataset-details">{}</td>'.format(value),
'</tr>',
html_code += [
f'<tr>',
f'<th class="dataset-labels">{html.escape(name)}</th>',
f'<td class="dataset-details">{html.escape(value)}</td>',
f'</tr>',
]
html.append("</table>")
return html
html_code.append("</table>")
return html_code

0 comments on commit 5636f44

Please sign in to comment.