Skip to content
71 changes: 70 additions & 1 deletion maestrowf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from abc import ABCMeta, abstractmethod
import inspect
from io import StringIO
from collections import OrderedDict, defaultdict

import logging
import sys
Expand Down Expand Up @@ -168,6 +169,13 @@ def __init__(self, *args, **kwargs):
"bgcolor": "grey7",
"color": ""
}
self.update_theme()

def update_theme(self):
pass

def process_status_data(self, status_data):
return status_data

def layout(self, status_data, study_title=None, filter_dict=None):
"""Setup concrete status layout
Expand All @@ -183,7 +191,7 @@ def layout(self, status_data, study_title=None, filter_dict=None):

# Ensure status data is of type dict and isn't empty
if isinstance(status_data, dict) and status_data:
self._status_data = status_data
self._status_data = self.process_status_data(status_data)
else:
raise ValueError("Status data required to layout a table")

Expand Down Expand Up @@ -264,6 +272,67 @@ def render_to_str(self, theme=None, width=200):
return _printer.file.getvalue()


class SummaryStatusRenderer(FlatStatusRenderer):
"""Flat, simple summary table layout"""

layout_type = "summary" # Defines name in factory/cli

def update_theme(self):
self._theme_dict["Step Prefix"] = "blue"
Comment thread
FrankD412 marked this conversation as resolved.
self._theme_dict["State"] = "bold red"
self._theme_dict["Count"] = "blue"

def process_status_data(self, status_data):
"""Construct the summary dictionary"""
summary_data = OrderedDict()
Comment thread
FrankD412 marked this conversation as resolved.
Outdated
summary_data["Step Prefix"] = []
summary_data["State"] = []
summary_data["Count"] = []
prefix_set = set()
for step_name in status_data["Step Name"]:
prefix_set.add(step_name.split("-")[0])
for step_prefix in sorted(list(prefix_set)):
state_count = defaultdict(int)
for step_name, state in zip(status_data["Step Name"], status_data["State"]):
if step_name.split("-")[0] == step_prefix:
state_count[state] += 1
for state in sorted(list(state_count.keys())):
summary_data["Step Prefix"].append(step_prefix)
summary_data["State"].append(state)
summary_data["Count"].append(state_count[state])
return summary_data
Comment thread
crkrenn marked this conversation as resolved.


class Narrow2StatusRenderer(FlatStatusRenderer):
"""Flat, more simple table layout"""

layout_type = "narrow2" # Defines name in factory/cli

def process_status_data(self, status_data):
"""Construct the summary dictionary"""
columns = [
"Step Name",
"Job ID",
"Workspace",
"State",
"Submit Time",
"Start Time",
"End Time",
"Number Restarts",
]
narrow_data = OrderedDict()
Comment thread
FrankD412 marked this conversation as resolved.
Outdated
for column in columns:
narrow_data[column] = status_data[column]
date_columns = [
"Submit Time",
"Start Time",
"End Time",
]
for column in date_columns:
narrow_data[column] = [date[:-3] for date in narrow_data[column]]
return narrow_data


class NarrowStatusRenderer(BaseStatusRenderer):
"""Narrow terminal layout with parameter info"""

Expand Down