Skip to content
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

Round outputs #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Systems

`systems` is a set of tools for describing, running and visualizing
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Tutorial

Please follow the [installation instructions](../) before continuing with these steps.
Expand Down Expand Up @@ -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!

7 changes: 5 additions & 2 deletions systems/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def render_html(self, results):
rows += ["</tbody>", "</table>"]
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 = []

Expand All @@ -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])

Expand Down
7 changes: 7 additions & 0 deletions systems/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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))


Expand Down