Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
26acb20
init
pared Mar 30, 2020
61c2b5d
rename to plot data insertion basig on dicts update
pared Mar 31, 2020
7a65199
revision support
pared Mar 31, 2020
2715fcd
roll back revision
pared Apr 1, 2020
46b8e20
plot makedirs for backward compatibility
pared Apr 1, 2020
bcad3ee
log path
pared Apr 1, 2020
1b3d925
pretty plot link to visualization page
pared Apr 1, 2020
906bd9a
make target default title
pared Apr 1, 2020
7d03767
efiop review
pared Apr 1, 2020
d968b34
efiop review
pared Apr 1, 2020
a80f3c9
proper id generation
pared Apr 2, 2020
ffbfba7
proper id generation
pared Apr 2, 2020
1511204
add confusion matrix template
pared Apr 2, 2020
224f339
refactor tests
pared Apr 2, 2020
fffbbad
plot from dvct file
pared Apr 3, 2020
66e1151
plot multiple initial
pared Apr 2, 2020
12169aa
add some missing metric file tests
pared Apr 2, 2020
4726fe8
plot from dvct
pared Apr 3, 2020
6cb26aa
brush up commands
pared Apr 3, 2020
8a145a1
fix confusion matrix multiple plot
pared Apr 3, 2020
9d76c9a
plot: change confusion matrix data schema
pared Apr 6, 2020
26b5644
should be working as intended
pared Apr 8, 2020
8cd3be9
support for src file in dvct files
pared Apr 8, 2020
8978a63
minor fixes
pared Apr 8, 2020
0a3df45
plot: support json templates
pared Apr 9, 2020
c920952
plot: rename confusion template
pared Apr 9, 2020
b78f43c
plot: polish command behaviour
pared Apr 9, 2020
4a675d3
fix test for json
pared Apr 10, 2020
ec81363
plot: test command
pared Apr 10, 2020
944f1d2
some minor fixes for tests
pared Apr 10, 2020
f7ff4c2
plot: unit test loading
pared Apr 10, 2020
4dd72ae
plot: unit test loading
pared Apr 10, 2020
df35c49
plot: handle TODOS
pared Apr 10, 2020
7e3503f
cleanup
pared Apr 10, 2020
469bf78
use mocker
pared Apr 10, 2020
ee3879c
plot: support tsv
pared Apr 10, 2020
0317b31
plot: command refactoring
pared Apr 10, 2020
117c2fc
plot: fix windows issues with tests
pared Apr 10, 2020
b3b3a3a
plot: test: some more windows fixes
pared Apr 10, 2020
d53a187
plot: _load_from_revisions complexity fix
pared Apr 10, 2020
47ee620
plot: reduce complexity
pared Apr 10, 2020
66c7091
plot: complexity reduction
pared Apr 10, 2020
4d1c20f
plot: deepsource suggestions
pared Apr 10, 2020
22041d3
plot: move template path evaluation
pared Apr 10, 2020
f9709c6
fixup
pared Apr 10, 2020
02aee4e
fixup
pared Apr 10, 2020
119935f
exception on no datafile and no template
pared Apr 13, 2020
9c35481
json metric load with OrderedDict
pared Apr 13, 2020
7d351f8
plot: improve handling non-existing files on revisions
pared Apr 13, 2020
972b61f
plot: improve handling non-existing files on revisions
pared Apr 13, 2020
766bf57
change default plot path
pared Apr 13, 2020
29dfeaf
some exceptions and fixes
pared Apr 14, 2020
19e8d26
add yaml metrics support
pared Apr 14, 2020
accf07c
fixup
pared Apr 14, 2020
df45b48
some more suggestions
pared Apr 14, 2020
263262a
default filename fix
pared Apr 14, 2020
8d85e3d
efiop review requests
pared Apr 15, 2020
2988168
log exception on failur
pared Apr 15, 2020
4e32431
move revisions deduction to commands
pared Apr 15, 2020
28ae4d9
json templates
pared Apr 16, 2020
ff648d8
extract template filling to separate method
pared Apr 16, 2020
7e00009
some parsing improvements
pared Apr 17, 2020
ad9c8d8
add columns functionality
pared Apr 17, 2020
0c453aa
extract default data transformation to separate method
pared Apr 20, 2020
893939c
plot: initial support for jsonpath
pared Apr 20, 2020
0a5b945
plot: rename columns to filters, tests are dict based
pared Apr 21, 2020
c235d00
plot: fixups
pared Apr 21, 2020
7120764
plot: refactoring
pared Apr 22, 2020
6fcd98f
repo: plot: convert to package
pared Apr 22, 2020
dcac66a
plot: data loading refactor, support searching for data
pared Apr 22, 2020
b5219df
plot: raise if wrong fields provided
pared Apr 22, 2020
9bc6c3f
plot: command description
pared Apr 22, 2020
5ef304a
plot: default: pass y axis info for default plot
pared Apr 23, 2020
39c5d10
plot: get rid of fieldnames, expect ordered data
pared Apr 23, 2020
aed0634
plot: handle default plot in separate method
pared Apr 23, 2020
8263820
plot: fix default
pared Apr 23, 2020
8a6d9e4
plot: command option names fixes
pared Apr 23, 2020
9b947e0
refactoring
pared Apr 23, 2020
a6b2faf
fixes
pared Apr 23, 2020
8d12dd4
plot: provide option for stdout redirection
pared Apr 24, 2020
d9b42fb
plot: rename show-json to no-html
pared Apr 24, 2020
6a9a3f3
plot: add no-csv-header option
pared Apr 24, 2020
010dd64
plot: improve error message for wrongly structured metric
pared Apr 24, 2020
58da963
plot: match template name exactly, whit suffix appended only
pared Apr 27, 2020
241466d
plot: dmpetrov and ivan review
pared Apr 27, 2020
feb7029
plot: refactor --stdout help message
pared Apr 28, 2020
d8e508a
plot: move template to repo/plot
pared Apr 28, 2020
3bbbb6e
plot: add -x and -y options
pared Apr 29, 2020
a51cce2
plot: add -x and -y options
pared Apr 29, 2020
fee7a2f
plot: command: order change
pared Apr 29, 2020
5f95cca
plot: scatter
pared Apr 29, 2020
a39a741
plot: rename confusion matrix template, new name generation format
pared Apr 30, 2020
4f37355
plot: add title anchor
pared Apr 30, 2020
39a1662
plot: review from jorgeorpinel
pared Apr 30, 2020
84fd893
plot: rename filter and result options to select and file
pared Apr 30, 2020
b7f6861
plot: add --title, --x-title, --y-title
pared Apr 30, 2020
5f2793c
plot: xlab ylab
pared Apr 30, 2020
dad99ee
Update dvc/repo/plot/template.py
pared May 1, 2020
218e2f1
Update dvc/repo/plot/template.py
pared May 1, 2020
0c6159d
efiop review
pared May 1, 2020
eeef8ff
plot: bash completion
pared May 1, 2020
333882d
plot: static code analysis fixes
pared May 1, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dvc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
update,
version,
git_hook,
plot,
)
from .command.base import fix_subparsers
from .exceptions import DvcParserError
Expand Down Expand Up @@ -74,6 +75,7 @@
version,
update,
git_hook,
plot,
]


Expand Down
243 changes: 243 additions & 0 deletions dvc/command/plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
import argparse
Copy link
Contributor

@shcheklein shcheklein Apr 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pared @jorgeorpinel

please:

  • review CLI options, help, etc
  • adjust completion scripts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review CLI options, help, etc

Done in #3577 (review)

import logging
import os

from dvc.command.base import append_doc_link, CmdBase, fix_subparsers
from dvc.exceptions import DvcException
from dvc.repo.plot.data import WORKSPACE_REVISION_NAME

logger = logging.getLogger(__name__)


class CmdPLot(CmdBase):
def _revisions(self):
raise NotImplementedError

def _result_file(self):
if self.args.file:
return self.args.file

extension = self._result_extension()
base = self._result_basename()

result_file = base + extension
return result_file

def _result_basename(self):
if self.args.datafile:
return self.args.datafile
return "plot"

def _result_extension(self):
if not self.args.no_html:
return ".html"
elif self.args.template:
return os.path.splitext(self.args.template)[-1]
return ".json"

def run(self):
fields = None
jsonpath = None
if self.args.select:
if self.args.select.startswith("$"):
jsonpath = self.args.select
else:
fields = set(self.args.select.split(","))
try:
plot_string = self.repo.plot(
datafile=self.args.datafile,
template=self.args.template,
revisions=self._revisions(),
fields=fields,
x_field=self.args.x,
y_field=self.args.y,
path=jsonpath,
embed=not self.args.no_html,
csv_header=not self.args.no_csv_header,
title=self.args.title,
x_title=self.args.xlab,
y_title=self.args.ylab,
)

if self.args.stdout:
logger.info(plot_string)
else:
result_path = self._result_file()
with open(result_path, "w") as fobj:
fobj.write(plot_string)

logger.info(
"file://{}".format(
os.path.join(self.repo.root_dir, result_path)
)
)

except DvcException:
logger.exception("")
return 1

return 0


class CmdPlotShow(CmdPLot):
def _revisions(self):
return None


class CmdPlotDiff(CmdPLot):
def _revisions(self):
revisions = self.args.revisions or []
if len(revisions) <= 1:
if len(revisions) == 0 and self.repo.scm.is_dirty():
revisions.append("HEAD")
revisions.append(WORKSPACE_REVISION_NAME)
return revisions


def add_parser(subparsers, parent_parser):
PLOT_HELP = (
"Generating plots for continuous metrics stored in structured files "
"(JSON, CSV, TSV)."
)

plot_parser = subparsers.add_parser(
"plot",
parents=[parent_parser],
description=append_doc_link(PLOT_HELP, "plot"),
help=PLOT_HELP,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
plot_subparsers = plot_parser.add_subparsers(
dest="cmd",
help="Use `dvc plot CMD --help` to display command-specific help.",
)

fix_subparsers(plot_subparsers)

SHOW_HELP = "Generate a plot image file from a continuous metrics file."
plot_show_parser = plot_subparsers.add_parser(
"show",
parents=[parent_parser],
description=append_doc_link(SHOW_HELP, "plot/show"),
help=SHOW_HELP,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
plot_show_parser.add_argument(
"-t",
"--template",
nargs="?",
default=None,
help="File to be injected with data.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe link to some doc where we explain templates? Something like

        help="Vega specification template file to inject with the data. See man.dvc.org/...",

See conversation in #3577 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same in line 192

)
plot_show_parser.add_argument(
"-f", "--file", default=None, help="Name of the generated file."
)
plot_show_parser.add_argument(
"-s",
"--select",
default=None,
help="Choose which field(s) or JSONPath to include in the plot.",
)
plot_show_parser.add_argument(
"-x", default=None, help="Field name for x axis."
)
plot_show_parser.add_argument(
"-y", default=None, help="Field name for y axis."
)
plot_show_parser.add_argument(
"--stdout",
action="store_true",
default=False,
help="Print plot specification to stdout.",
)
plot_show_parser.add_argument(
"--no-csv-header",
action="store_true",
default=False,
help="Required when CSV or TSV datafile does not have a header.",
)
plot_show_parser.add_argument(
"--no-html",
action="store_true",
default=False,
help="Do not wrap Vega plot JSON with HTML.",
)
plot_show_parser.add_argument("--title", default=None, help="Plot title.")
plot_show_parser.add_argument("--xlab", default=None, help="X axis title.")
plot_show_parser.add_argument("--ylab", default=None, help="Y axis title.")
plot_show_parser.add_argument(
"datafile",
nargs="?",
default=None,
help="Continuous metrics file to visualize.",
)
plot_show_parser.set_defaults(func=CmdPlotShow)

PLOT_DIFF_HELP = (
"Plot continuous metrics differences between commits in the DVC "
"repository, or between the last commit and the workspace."
)
plot_diff_parser = plot_subparsers.add_parser(
"diff",
parents=[parent_parser],
description=append_doc_link(PLOT_DIFF_HELP, "plot/diff"),
help=PLOT_DIFF_HELP,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
plot_diff_parser.add_argument(
"-t",
"--template",
nargs="?",
default=None,
help="File to be injected with data.",
)
plot_diff_parser.add_argument(
"-d",
"--datafile",
nargs="?",
default=None,
help="Continuous metrics file to visualize.",
)
plot_diff_parser.add_argument(
"-f", "--file", default=None, help="Name of the generated file."
)
plot_diff_parser.add_argument(
"-s",
"--select",
default=None,
help="Choose which field(s) or JSONPath to include in the plot.",
)
plot_diff_parser.add_argument(
"-x", default=None, help="Field name for x axis."
)
plot_diff_parser.add_argument(
"-y", default=None, help="Field name for y axis."
)
plot_diff_parser.add_argument(
"--stdout",
action="store_true",
default=False,
help="Print plot specification to stdout.",
)
plot_diff_parser.add_argument(
"--no-csv-header",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmpetrov @pared can we name it just --no-header? simpler and covers TSV case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree here, @dmpetrov ?

action="store_true",
default=False,
help="Provided CSV ot TSV datafile does not have a header.",
)
plot_diff_parser.add_argument(
"--no-html",
action="store_true",
default=False,
help="Do not wrap Vega plot JSON with HTML.",
)
plot_diff_parser.add_argument("--title", default=None, help="Plot title.")
plot_diff_parser.add_argument("--xlab", default=None, help="X axis title.")
plot_diff_parser.add_argument("--ylab", default=None, help="Y axis title.")
plot_diff_parser.add_argument(
"revisions",
nargs="*",
default=None,
help="Git revisions to plot from",
)
plot_diff_parser.set_defaults(func=CmdPlotDiff)
7 changes: 7 additions & 0 deletions dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Repo(object):
from dvc.repo.get import get
from dvc.repo.get_url import get_url
from dvc.repo.update import update
from dvc.repo.plot import plot

def __init__(self, root_dir=None):
from dvc.state import State
Expand Down Expand Up @@ -426,6 +427,12 @@ def stages(self):
"""
return self._collect_stages()

@cached_property
def plot_templates(self):
from dvc.repo.plot.template import PlotTemplates

return PlotTemplates(self.dvc_dir)

def _collect_stages(self):
from dvc.dvcfile import Dvcfile, is_valid_filename

Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def init(root_dir=os.curdir, no_scm=False, force=False, subdir=False):

proj = Repo(root_dir)

scm.add([config.files["repo"]])
scm.add([config.files["repo"], proj.plot_templates.templates_dir])

if scm.ignore_file:
scm.add([os.path.join(dvc_dir, scm.ignore_file)])
Expand Down
Loading