Skip to content

Commit

Permalink
Adding Derived Attribute section as simple rows pepkit/looper#82
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldcampbelljr committed Jan 11, 2024
1 parent fbf20a2 commit 632abab
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 11 deletions.
17 changes: 17 additions & 0 deletions pipestat/jinja_templates/derived_table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% if rows[0] is defined %}
<div class="row">
<div class="col-12">
<h5>Derived Attributes</h5>
</div>
</div>
<div class="row">
<div class="col-12">
<!-- the list of rows goes here -->
<div class="list-group" style="display:inline-block">
{% for row in rows %}
<a href='{{ row }}' class="list-group-item">{{ row }}</a>
{% endfor %}
</div>
</div>
</div>
{% endif %}
3 changes: 3 additions & 0 deletions pipestat/jinja_templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ <h4 style="margin-bottom: 0px;">Amendments: <code>{{ amendments|join(', ') }}</c
</tbody>
</table>
</div>
{% if derived_table is defined %}
{{ derived_table }}
{% endif %}
</div>
<div class="row">
<div class="col-3">
Expand Down
43 changes: 33 additions & 10 deletions pipestat/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,19 @@ def create_index_html(self, navbar, footer):

if self.looper_samples:
try:
sources = self.looper_samples[0]._mapped_attr["_project"].config["sample_modifiers"]['derive']['sources']
derived_table = self.create_derived_table(derived_attributes=sources)
sources = (
self.looper_samples[0]
._mapped_attr["_project"]
.config["sample_modifiers"]["derive"]["sources"]
)
attributes = (
self.looper_samples[0]
._mapped_attr["_project"]
.config["sample_modifiers"]["derive"]["attributes"]
)
derived_table = self.create_derived_table(
derived_sources=sources, derived_attributes=attributes
)
except KeyError:
# No sample modifers or sources, so just pass
derived_table = None
Expand All @@ -670,6 +681,7 @@ def create_index_html(self, navbar, footer):
pipeline_name=self.prj.cfg[PIPELINE_NAME],
stats_json=self._stats_to_json_str(),
project_objects=project_objects,
derived_table=derived_table,
footer=footer,
amendments="",
)
Expand All @@ -679,15 +691,26 @@ def create_index_html(self, navbar, footer):
render_jinja_template("index.html", self.jinja_env, template_vars),
)

def create_derived_table(self, derived_attributes):
print("Placeholder")
if derived_attributes:
for k,v in derived_attributes.items():
print(f"{k} {v}")


return None
def create_derived_table(self, derived_sources, derived_attributes):
rows = []
if derived_sources and derived_attributes:
# simply concatenate for now, pairing the derived attrribute to the key value pair
for i in range(len(derived_attributes)):
row_text = (
"Derived Attribute: "
+ derived_attributes[i]
+ "Source Key: "
+ list(derived_sources.keys())[i]
+ "Source Value: "
+ list(derived_sources.values())[i]
)
rows.append(row_text)

if rows != []:
template_vars = dict(rows=rows)
return render_jinja_template("derived_table.html", self.jinja_env, template_vars)
else:
return None

def create_project_objects(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pipestat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2164,4 +2164,4 @@ def test_temp(
statstsv = psm.table()
print(statstsv)
# data = YAMLConfigManager(filepath=os.path.join(temp_dir, "aggregate_results.yaml"))
# assert r_id in data[psm.pipeline_name][psm.pipeline_type].keys()
# assert r_id in data[psm.pipeline_name][psm.pipeline_type].keys()

0 comments on commit 632abab

Please sign in to comment.