# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # REST API Examples

# Here are some examples that illustrate how to use the BPTK REST API (you need to start the demonstration server from a console by running the `run_server.sh` script in this directory. The server should then be running on port 5000.
#
# There is a companion repository on [Github](https://github.com/transentis/sim-covid-dashboard) that contains the source code for a web-based dashboard that uses the COVID-Simulation via the REST API. The dashboard was built using React and [BPTK-Widgets](http://bptk.transentis.com). You can test the dashboard live on [www.covid-sim.com](http://www.covid-sim.com)

# find documentation for the requests library on https://docs.python-requests.org/
import requests
import json

# Get a list of scenarios that the server knows about:

response = requests.get("http://localhost:5000/scenarios")

response

response.json()

# Get the equations known to the dashboard scenario:

response = requests.post(
    url="http://localhost:5000/equations",
    json = {
    "scenarioManager": "smSir",
    "scenario":"dashboard"
}
)

response

response.json()

# Get some data for a scenario and some equations:

response = requests.post(
    url="http://localhost:5000/run",
    json = {
    "scenario_managers": [
        "smSir"
    ],
    "scenarios": [
        "strong_social_distancing"
    ],
    "equations": [
        "recovered",
        "infectious"
    ]
}
)

data=response.json()["smSir"]["strong_social_distancing"]["equations"]

import pandas as pd

df=pd.DataFrame.from_dict(data)

df

df.plot()



StarcoderdataJupyterScriptsDedupFiltered