Workflow graph: polish

This commit is contained in:
Dmitry
2017-09-05 09:44:33 -07:00
parent 993c802047
commit fa12ef632a
2 changed files with 24 additions and 6 deletions
+11 -3
View File
@@ -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 + ' <<collapsed commits>>'
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
+13 -3
View File
@@ -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: