Skip to content

Model service of simpl-div example game using Simpl framework

License

Notifications You must be signed in to change notification settings

simplworld/simpl-div-model

Repository files navigation

simpl-div-model - example multi player simulation model service.

Python Setup (assumes Python 3.6 and simpl-games-api server running)

Install simpl-div-model

$ git clone https://github.com/simplworld/simpl-div-model.git
$ cd simpl-div-model

Local Docker Setup

The Simpl API server needs to be started first to create the simpl bridge network.

Install simpl-games-api master and run it in docker-compose so that it exposes itself as hostname api on port 8100.

You also need to have a is_staff=True user in the simpl-games-api database that corresponds to the SIMPL_GAMES_AUTH setting used here.

After you clone the repo, run:

$ docker-compose up

this will create the Docker image and run it. The first time you run it it will error as it can't find the simpl-div game in the API.

In a separate terminal, create a shell into the simpl-div-model container by running:

$ docker-compose run --rm model.backend bash

Once you are in the container shell, run this command:

$ ./manage.py create_default_env

You should see this create the 'simpl-div' game, phases, users, etc.

Exit from the shell then stop and restart the docker container by running these commands:

$ docker-compose down
$ docker-compose up

You should now see a startup log message to the effect of:

Game `simpl-div` installed in 2.063s.

This means the simpl-div-model is able to successfully communicate with the API.

Local Setup Without Docker

Create a virtual environment and install Python dependencies

$ mkvirtualenv simpl-div-model
$ pip install -r requirements.txt

Run model service

$ export DJANGO_SETTINGS_MODULE=simpl_div_model.settings
$ ./manage.py run_modelservice

If you need some serious debugging help, the model_service includes the ability to do

$ ./manage.py run_modelservice --loglevel=debug

Which will turn on verbose debugging of the Autobahn/Crossbar daemon to help debug interactions between the browser and model service backend.

Run model service as 2 processes

  1. Get a copy of the currently in use crossbar configuration by running ./manage.py run_modelservice --print-config > config.json
  2. Edit config.json to remove the entire {"type": "guest", ...} stanza and final line
  3. Run crossbar service:
    ./manage.py run_modelservice --config=./config.json --loglevel info --settings=simpl_div_model.settings
  4. In a separate terminal, run guest service:
    HOSTNAME=localhost PORT=8080 ./manage.py run_guest --settings=simpl_div_model.settings

Run unit tests

$ export DJANGO_SETTINGS_MODULE=simpl_div_model.settings
$ py.test

Development commands:

1 - To setup up database for simpl-div development use:

  1. Creates the simpl-div game with two phases (Play and Debrief) and two roles ("Dividend" and "Divisor").
  2. Adds a 'default' run..
  3. Adds 1 leader ('[email protected]'/'leader') to the run.
  4. Adds 2 players to the run ('s#@div.edu'/'s#' where # is between 1..2. Each player has a private scenario and period 1.
  5. The run is set to 'Play' phase

execute:

$ ./manage.py create_default_env

To make it easier to recreate the default run you can pass the --reset option to delete the default run and recreate it from scratch like this:

$ ./manage.py create_default_env --reset

To create a run with a non-default name, use:

./manage.py create_default_env -n <name>

where: name is the run name (default is 'default') and the base of player email ids (default is 's')

Modelservice Profiling

Run modelservice profiling tests locally

  1. Run simpl-games-api modelservice
  2. Run simpl-div-model modelservice

Create and activate a virtual environment:

$ mkvirtualenv simpl-div-model
$ pip install -r requirements.txt

Create a test run named 'a' with 4 players named after the run (e.g. run 'a' with players '[email protected]', etc)

$ ./manage.py create_default_env -n a

To run each player test once for each user in the emails/emails-4.txt file, run:

$ profile.sh -m game.profilers -u emails/emails-4.txt -g 1

to launch a separate profiling task for each email in the file:

./manage.py profile -m game.profilers -g 1 -w 4 --log-level error --user-email [email protected]
./manage.py profile -m game.profilers -g 1 -w 4 --log-level error --user-email [email protected]
./manage.py profile -m game.profilers -g 1 -w 4 --log-level error --user-email [email protected]
./manage.py profile -m game.profilers -g 1 -w 4 --log-level error --user-email [email protected]

Once all tasks complete, message will be printed out indicating how many seconds it took to run all profile tests

If the run is not configured to submit new decisions for each profile user, error messages will be printed out.

Before rerunning the profiling test, recreate the test run:

./manage.py create_default_env -n a --reset

Copyright © 2018 The Wharton School,  The University of Pennsylvania 

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

About

Model service of simpl-div example game using Simpl framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published