Skip to content

Commit

Permalink
implement table
Browse files Browse the repository at this point in the history
  • Loading branch information
stolarczyk committed Jun 16, 2020
1 parent 9d8cf80 commit 5194a7d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
4 changes: 3 additions & 1 deletion pipestat/const.py
Expand Up @@ -4,10 +4,12 @@
REPORT_CMD = "report"
INSPECT_CMD = "inspect"
REMOVE_CMD = "remove"
TABLE_CMD = "table"
SUBPARSER_MSGS = {
REPORT_CMD: "Report a result.",
INSPECT_CMD: "Inspect a database.",
REMOVE_CMD: "Remove a result."
REMOVE_CMD: "Remove a result.",
TABLE_CMD: "Create a results table."
}
LIBS_BY_BACKEND = {"mongo": ["pymongo", "mongodict"]}
CLASSES_BY_TYPE = {"integer": int, "float": float, "string": str,
Expand Down
20 changes: 16 additions & 4 deletions pipestat/helpers.py
Expand Up @@ -22,15 +22,27 @@ def build_argparser():
# common arguments
for cmd, desc in SUBPARSER_MSGS.items():
sps[cmd] = subparsers.add_parser(cmd, description=desc, help=desc)
sps[cmd].add_argument("-d", "--database", required=True, type=str,
metavar="DB", help="database to store results in")
sps[cmd].add_argument(
"-n", "--name", required=True, type=str, metavar="N",
help="name of the pipeline to report result for")

# remove, report and inspect
for cmd in [REMOVE_CMD, REPORT_CMD, INSPECT_CMD]:
sps[cmd].add_argument("-d", "--database", required=True, type=str,
metavar="DB", help="database to store results in")

# table
sps[TABLE_CMD].add_argument("-d", "--databases", required=True, nargs="+",
metavar="DB", help="collection of file paths "
"the results are stored in")

sps[TABLE_CMD].add_argument("-p", "--path", required=True, type=str,
metavar="P",
help="Path to the file where to store the result.")

# remove and report
for subparser in [REMOVE_CMD, REPORT_CMD]:
sps[subparser].add_argument(
for cmd in [REMOVE_CMD, REPORT_CMD]:
sps[cmd].add_argument(
"-i", "--id", required=True, type=str, metavar="ID",
help="id of the result to report")

Expand Down
16 changes: 15 additions & 1 deletion pipestat/pipestat.py
Expand Up @@ -3,6 +3,7 @@
import logging
import logmuse
import oyaml as yaml
import pandas as pd

from collections import Mapping

Expand Down Expand Up @@ -84,6 +85,15 @@ def cache(self):
"""
return self._cache

@property
def table(self):
"""
Tabular database
:return pandas.DataFrame: database in a table format
"""
return pd.DataFrame.from_dict(self.database[self.name], orient="index")

def report(self, id, type, value, cache=False, overwrite=False,
strict_type=False):
"""
Expand Down Expand Up @@ -195,12 +205,16 @@ def main():
global _LOGGER
_LOGGER = logmuse.logger_via_cli(args, make_root=True)
_LOGGER.debug("Args namespace:\n{}".format(args))
if args.command == TABLE_CMD:
pd.concat([PipeStatManager(d, args.name).table
for d in args.databases]).to_csv(args.path)
sys.exit(0)
psm = PipeStatManager(database=args.database, name=args.name)
if args.command == REPORT_CMD:
type = args.type
value = args.value
if args.type == "object" and os.path.exists(expandpath(value)):
# if reported type is object and value is and existing file path,
# if reported type is object and value is an existing file path,
# try to load it as JSON. This way nested objects can be
# reported using CLI
from json import load
Expand Down
1 change: 1 addition & 0 deletions requirements/requirements-all.txt
@@ -1,3 +1,4 @@
ubiquerg>=0.6.0-dev
logmuse>=0.2.5
oyaml
pandas>=1.0.0

0 comments on commit 5194a7d

Please sign in to comment.