From 13ba9d0f5304c96f5e685bbd5201df732ca80b15 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 4 Sep 2017 13:36:51 -0700 Subject: [PATCH] Show target metric deltas --- dvc/graph/commit.py | 12 +++++++++++- dvc/graph/workflow.py | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/dvc/graph/commit.py b/dvc/graph/commit.py index 8dacfae38..6cce7dd03 100644 --- a/dvc/graph/commit.py +++ b/dvc/graph/commit.py @@ -14,6 +14,7 @@ class Commit(object): self._comment = comment self._is_target = is_target self._target_metric = target_metric + self._target_metric_delta = None self._branch_tips = [] if branch_tips is None else branch_tips self._is_collapsed = False @@ -41,11 +42,13 @@ class Commit(object): metric_text = '' if self._is_target and self._target_metric: metric_text = '\nTarget metric: {}'.format(self._target_metric) + if self._target_metric_delta is not None: + metric_text += ' ({:+f})'.format(self._target_metric_delta) if self._is_collapsed: return branch_text + self.COLLAPSED_TEXT + metric_text - return branch_text + self._comment[:self.TEXT_LIMIT] + '\n' + self.hash + metric_text + return branch_text + self._comment[:self.TEXT_LIMIT] + metric_text + '\n' + self.hash @property def is_repro(self): @@ -73,3 +76,10 @@ class Commit(object): def add_branch_tips(self, tips): for tip in tips: self._branch_tips.append(tip) + + def set_target_metric_delta(self, value): + self._target_metric_delta = value + + @property + def target_metric_delta(self): + return self._target_metric_delta diff --git a/dvc/graph/workflow.py b/dvc/graph/workflow.py index e6870b48c..4c72fdd67 100644 --- a/dvc/graph/workflow.py +++ b/dvc/graph/workflow.py @@ -1,6 +1,7 @@ import networkx as nx from dvc.exceptions import DvcException +from dvc.logger import Logger class WorkflowError(DvcException): @@ -9,13 +10,13 @@ class WorkflowError(DvcException): class Workflow(object): - def __init__(self, target, merges_map, branches_map=None, root='', no_repro_commits=True): + def __init__(self, target, merges_map, branches_map=None, no_repro_commits=True): self._target = target self._merges_map = merges_map self._branches_map = branches_map self._commits = {} - self._root = root + self._root_hash = None self._edges = {} self._back_edges = {} @@ -35,11 +36,16 @@ class Workflow(object): self._back_edges[commit.hash] = set() for p in commit.parent_hashes: self._back_edges[commit.hash].add(p) + + if not commit.parent_hashes: + self._root_hash = commit.hash pass def build_graph(self): g = nx.DiGraph(name='DVC Workflow', directed=False) + self.derive_target_metric_deltas() + if self._no_repro_commits: self.collapse_repro_commits() @@ -120,3 +126,29 @@ class Workflow(object): for h in commit_hashes: edges[h].remove(hash) edges[h] |= child_commit_hashes + + def derive_target_metric_deltas(self): + if not self._target: + return + + if self._root_hash not in self._commits: + Logger.warn('Root commit cannot be found') + + current_target_metric = None + commit = self._commits[self._root_hash] + self._traverse_target_metric(commit, current_target_metric) + pass + + def _traverse_target_metric(self, commit, current_target_metric): + new_target_metric = current_target_metric + if commit.target_metric is not None: + new_target_metric = commit.target_metric + if current_target_metric is None: + commit.set_target_metric_delta(0.0) + else: + commit.set_target_metric_delta(new_target_metric - current_target_metric) + + if commit.hash in self._edges: + for hash in self._edges[commit.hash]: + self._traverse_target_metric(self._commits[hash], new_target_metric) + pass