-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Metrics - plotting for multiple revisions initial #3577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
26acb20
61c2b5d
7a65199
2715fcd
46b8e20
bcad3ee
1b3d925
906bd9a
7d03767
d968b34
a80f3c9
ffbfba7
1511204
224f339
fffbbad
66e1151
12169aa
4726fe8
6cb26aa
8a145a1
9d76c9a
26b5644
8cd3be9
8978a63
0a3df45
c920952
b78f43c
4a675d3
ec81363
944f1d2
f7ff4c2
4dd72ae
df35c49
7e3503f
469bf78
ee3879c
0317b31
117c2fc
b3b3a3a
d53a187
47ee620
66c7091
4d1c20f
22041d3
f9709c6
02aee4e
119935f
9c35481
7d351f8
972b61f
766bf57
29dfeaf
19e8d26
accf07c
df45b48
263262a
8d85e3d
2988168
4e32431
28ae4d9
ff648d8
7e00009
ad9c8d8
0c453aa
893939c
0a5b945
c235d00
7120764
6fcd98f
dcac66a
b5219df
9bc6c3f
5ef304a
39c5d10
aed0634
8263820
8a6d9e4
9b947e0
a6b2faf
8d12dd4
d9b42fb
6a9a3f3
010dd64
58da963
241466d
feb7029
d8e508a
3bbbb6e
a51cce2
fee7a2f
5f95cca
a39a741
4f37355
39a1662
84fd893
b7f6861
5f2793c
dad99ee
218e2f1
0c6159d
eeef8ff
333882d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,243 @@ | ||
| import argparse | ||
| 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.", | ||
jorgeorpinel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe link to some doc where we explain templates? Something like
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.", | ||
jorgeorpinel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| 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", | ||
|
||
| action="store_true", | ||
| default=False, | ||
| help="Provided CSV ot TSV datafile does not have a header.", | ||
jorgeorpinel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
| 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) | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pared @jorgeorpinel
please:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #3577 (review)