Skip to content

Commit

Permalink
Adding precision option and formating of results
Browse files Browse the repository at this point in the history
  • Loading branch information
John Hawkins authored and John Hawkins committed Aug 8, 2023
1 parent 1dc8228 commit 38ed707
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions projit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def print_header(header):
print(full_header)

##########################################################################################
def task_compare(project, datasets, metric, format):
def task_compare(project, datasets, metric, format, precision):
"""
Compare results across muliple datasets.
This command loads the results for each dataset and extarcts just the records
Expand All @@ -104,6 +104,8 @@ def task_compare(project, datasets, metric, format):
print("*** WARNINGS ***")
print(warning)

results = results.round(precision)

if format == 'markdown':
print_results_markdown(title, results)
elif format == 'latex':
Expand Down Expand Up @@ -136,7 +138,7 @@ def extract_max_tags_lengths(project, asset, tags):


##########################################################################################
def task_list(subcmd, project, dataset, format, tags):
def task_list(subcmd, project, dataset, format, precision, tags):
"""
List content of a project from the command line
"""
Expand Down Expand Up @@ -234,6 +236,8 @@ def task_list(subcmd, project, dataset, format, tags):
else:
rez = project.get_results(dataset)
title += " on [%s]"%dataset

rez = rez.round(precision)

if format == 'markdown':
print_results_markdown(title, rez)
Expand Down Expand Up @@ -420,6 +424,7 @@ def print_usage(prog):
print(" -h, --help - Get command help")
print(" -m, --markdown - Use markdown format when printing results")
print(" -l, --latex - Use LaTeX format when printing results")
print(" -p, --precision <N> - Set the numerical precision to <N>")
print("")
print(" COMMON USAGE PATTERNS")
print(" ", prog, "init 'Project name' # Initialise project")
Expand Down Expand Up @@ -462,6 +467,7 @@ def cli_main():
parser.add_argument('-m', '--markdown', help='Use markdown for output', action='store_true')
parser.add_argument('-l', '--latex', help='Use LaTeX for output - overrides markdown', action='store_true')
parser.add_argument('-u', '--usage', help='Print detailed usage instructions with examples', action='store_true')
parser.add_argument('-p', '--precision', help='Define numerical precision', type=int, default=3)

subparsers = parser.add_subparsers(dest="cmd")

Expand Down Expand Up @@ -541,11 +547,11 @@ def cli_main():
format = 'latex'

if args.cmd == 'list':
task_list(args.subcmd, project, args.dataset, format, args.tags)
task_list(args.subcmd, project, args.dataset, format, args.precision, args.tags)

if args.cmd == 'compare':
datasets = args.datasets.split(",")
task_compare(project, datasets, args.metric, format)
task_compare(project, datasets, args.metric, format, args.precision)

if args.cmd == 'add':
task_add(project, args.asset, args.name, args.path)
Expand Down

0 comments on commit 38ed707

Please sign in to comment.