diff --git a/README.md b/README.md index 2c63a45..fd657fa 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ - # Systems `systems` is a set of tools for describing, running and visualizing @@ -68,6 +67,17 @@ systems/ `systems-run` is used to run models: + $ systems-run --help + usage: parse.py [-h] [-r ROUNDS] [--csv] [-R ROUND_TO] + + options: + -h, --help show this help message and exit + -r ROUNDS, --rounds ROUNDS + number of rounds to run evaluation + --csv + -R ROUND_TO, --round-to ROUND_TO + number of digits to round outputs to + $ cat examples/hiring.txt | systems-run -r 3 PhoneScreens Onsites Offers Hires Employees Departures 0 0 0 0 0 5 0 diff --git a/docs/tutorial.md b/docs/tutorial.md index 52e1a43..22f0756 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -1,4 +1,3 @@ - # Tutorial Please follow the [installation instructions](../) before continuing with these steps. @@ -39,9 +38,12 @@ Then you could run the simulation for 10 rounds: 9 15 45 22 11 5 18 1 10 15 45 22 11 5 22 1 +Sometimes it may be clearer to round the outputs for display: + + systems-run --round-to 2 + You can also get the output as CSV: cat examples/links.txt | systems-run -r10 --csv Which you could... load into a spreadsheet or something to graph! - diff --git a/systems/models.py b/systems/models.py index b112eda..866bb74 100644 --- a/systems/models.py +++ b/systems/models.py @@ -325,7 +325,7 @@ def render_html(self, results): rows += ["", ""] return "\n".join(rows) - def render(self, results, sep='\t', pad=True): + def render(self, results, sep='\t', pad=True, round_to=None): "Render results to string from Model run." lines = [] @@ -338,7 +338,10 @@ def render(self, results, sep='\t', pad=True): for i, snapshot in enumerate(results): row = "%s" % i for j, col in enumerate(col_stocks): - num = str(snapshot[col.name]) + value = snapshot[col.name] + if round_to: + value = round(value, round_to) + num = str(value) if pad: num = num.ljust(col_size[j]) diff --git a/systems/parse.py b/systems/parse.py index 29d9edc..37ff1d0 100644 --- a/systems/parse.py +++ b/systems/parse.py @@ -121,6 +121,11 @@ def main(): help="number of rounds to run evaluation", default=10) p.add_argument('--csv', action='store_true', default=False) + p.add_argument( + '-R', + '--round-to', + type=int, + help="number of digits to round outputs to") args = p.parse_args() txt = sys.stdin.read() @@ -136,6 +141,8 @@ def main(): if args.csv: kwargs['sep'] = ',' kwargs['pad'] = False + if args.round_to: + kwargs['round_to'] = args.round_to print(model.render(results, **kwargs))