Skip to content

Commit

Permalink
Use tooltip to display filenames #975
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Peng committed Jun 7, 2018
1 parent 6853e5f commit 2050a97
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 14 deletions.
29 changes: 27 additions & 2 deletions src/sos/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,29 @@ def convert_time(self, info):
info['duration_str'] = format_duration(info['duration'])
return info

def convert_filelist(self, info):
def get_label(files):
label = os.path.basename(files[0])
if len(label) > 20:
label = label[:10] + '..' + label[-4:]
if len(files) > 1:
label += f', ... ({len(files)})'
return label
def get_tooltip(files):
if len(files) == 1:
return f'<small><code>{files[0]}</code></small>'
else:
#return f'<ul>{"".join(f"<li>{x}</li>" for x in files)}</ul>'
return f'<small><code>{"<br>".join(x for x in files)}</code></small>'

if 'input' in info and info['input']:
info['input_str'] = f'''<a href="#" data-toggle="tooltip" data-html="true"
title="{get_tooltip(info['input'])}">{get_label(info['input'])}</a>'''
if 'output' in info and info['output']:
info['output_str'] = f'''<a href="#" data-toggle="tooltip" data-html="true"
title="{get_tooltip(info['output'])}">{get_label(info['output'])}</a>'''
return info

def workflows(self):
try:
# workflows has format
Expand Down Expand Up @@ -85,8 +108,9 @@ def tasks(self):

def steps(self):
try:
return {wf: [self.convert_time(eval(x)) for x in steps] for wf, steps in self.data['step'].items()}
except:
return {wf: [self.convert_filelist(self.convert_time(eval(x))) for x in steps] for wf, steps in self.data['step'].items()}
except Exception as e:
env.logger.warning(e)
return {}

def tracked_files(self):
Expand All @@ -110,6 +134,7 @@ def calc_timeline(info, start_time, total_duration):
1, int(info['duration'] * 100 / total_duration))
info['after_percent'] = 100 - \
info['before_percent'] - info['during_percent']
return info


def render_report(output_file, workflow_id):
Expand Down
10 changes: 8 additions & 2 deletions src/sos/step_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1723,12 +1723,18 @@ def run(self):
if self.completed['__step_skipped__'].is_integer():
self.completed['__step_skipped__'] = int(
self.completed['__step_skipped__'])
def file_only(targets):
if not isinstance(targets, sos_targets):
env.logger.warning(f"Unexpected input or output target for reporting. Empty list returned: {targets}")
return []
else:
return [str(x) for x in targets._targets if isinstance(x, file_target)]
step_info = {
'start_time': self.start_time,
'stepname': self.step.step_name(True),
'substeps': len(self._substeps),
'input': short_repr(env.sos_dict['step_input']) if env.sos_dict['step_input'] else '',
'output': short_repr(env.sos_dict['step_output']) if env.sos_dict['step_output'] else '',
'input': file_only(env.sos_dict['step_input']),
'output': file_only(env.sos_dict['step_output']),
'completed': dict(self.completed),
'end_time': time.time()
}
Expand Down
10 changes: 5 additions & 5 deletions src/sos/templates/workflow_report.css
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ tbody tr:hover {
font-style: normal;
}

footer a {
a {
text-decoration: none;
}

footer a:link, a:visited {
color: black;
a:link, a:visited {
color: black;
}

footer a:hover {
color: red;
a:hover {
color: red;
}
22 changes: 17 additions & 5 deletions src/sos/templates/workflow_report.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">

<title>{{workflow_name}}</title>
<style type="text/css">
{% include "workflow_report.css" %}
Expand Down Expand Up @@ -130,8 +134,8 @@
<tr>
<td></td>
<td>{{ step.stepname }}</td>
<td>{{ step.input }}</td>
<td>{{ step.output }}</td>
<td>{{ step.input_str }}</td>
<td>{{ step.output_str }}</td>
<td>{{ step.start_time_str }}</td>
<td>{{ step.duration_str }}</td>
<td>
Expand Down Expand Up @@ -209,8 +213,16 @@
<img class="dag-image" src="data:image/png;base64,{{ workflows[master_id].dag_img }}">
{% endif %}

<footer>
<footer>
Report generated by <a href="https://vatlab.github.io/sos-docs/">SoS Workflow Engine</a> version {{sos_version}}, by {{ user }} on {{ time_now_str }}
</footer>
</body>
</footer>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
</script>
</body>
</html>

0 comments on commit 2050a97

Please sign in to comment.