From fa12ef632a74e6e6b92edbd582319e03ca937738 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 5 Sep 2017 09:44:33 -0700 Subject: [PATCH] Workflow graph: polish --- dvc/graph/commit.py | 14 +++++++++++--- dvc/graph/workflow.py | 16 +++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/dvc/graph/commit.py b/dvc/graph/commit.py index dab354ce5..79b6e4c66 100644 --- a/dvc/graph/commit.py +++ b/dvc/graph/commit.py @@ -1,7 +1,7 @@ class Commit(object): TEXT_LIMIT = 30 DVC_REPRO_PREFIX = 'DVC repro' - COLLAPSED_TEXT = DVC_REPRO_PREFIX + '\n<< collapsed commits >>' + COLLAPSED_TEXT = DVC_REPRO_PREFIX + ' <>' def __init__(self, hash, parents, name, date, comment, is_target=False, @@ -42,12 +42,20 @@ class Commit(object): if self._is_collapsed: return branch_text + self.COLLAPSED_TEXT + self._text_metrics_line() - return branch_text + self._comment[:self.TEXT_LIMIT] + self._text_metrics_line() + '\n' + self.hash + return branch_text + self._text_comment() + self._text_metrics_line() + '\n' + self._text_hash() + + def _text_hash(self): + return 'Commit: ' + self.hash + + def _text_comment(self): + if len(self._comment) < self.TEXT_LIMIT: + return self._comment + return self._comment[:self.TEXT_LIMIT] + '...' def _text_metrics_line(self): result = '' if self._is_target and self._target_metric: - result = '\nTarget metric: {}'.format(self._target_metric) + result = '\nTarget: {}'.format(self._target_metric) if self._target_metric_delta is not None: result += ' ({:+f})'.format(self._target_metric_delta) return result diff --git a/dvc/graph/workflow.py b/dvc/graph/workflow.py index 4d896d993..f33410b17 100644 --- a/dvc/graph/workflow.py +++ b/dvc/graph/workflow.py @@ -49,10 +49,11 @@ class Workflow(object): for hash in set(self._edges.keys() + self._back_edges.keys()): commit = self._commits[hash] + g.add_node(hash, attr_dict={ 'label': commit.text, - 'color': 'black' + 'color': self.node_color(commit) } ) @@ -67,6 +68,15 @@ class Workflow(object): A.draw(fname, format='jpeg', prog='dot') pass + @staticmethod + def node_color(commit): + if commit.target_metric_delta is not None: + if commit.target_metric_delta >= 0: + return 'green' + if commit.target_metric_delta < 0: + return 'red' + return 'black' + def _build_graph(self, curr, g): if '' not in self._commits or curr.hash not in self._commits: return @@ -95,7 +105,7 @@ class Workflow(object): child_commit_hashes = self._edges.get(commit.hash) if child_commit_hashes and all(self._commits[hash].is_repro for hash in child_commit_hashes): - self._upstream_metrics(child_commit_hashes, commit) + self._upstream_metrics_and_branch_tips(child_commit_hashes, commit) for hash in child_commit_hashes: self._commits[hash].add_parents(commit.parent_hashes) @@ -110,7 +120,7 @@ class Workflow(object): return False pass - def _upstream_metrics(self, child_commit_hashes, commit): + def _upstream_metrics_and_branch_tips(self, child_commit_hashes, commit): for hash in child_commit_hashes: if commit.has_target_metric: if not self._commits[hash].has_target_metric: