Skip to content

Commit

Permalink
Enable jupyter notebooks, update test data
Browse files Browse the repository at this point in the history
  • Loading branch information
munterfi committed Jul 17, 2024
1 parent 2fb0517 commit d8a627f
Show file tree
Hide file tree
Showing 8 changed files with 1,360 additions and 322 deletions.
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,38 @@
Analysis and visualization of results from the scheduler service. Part of the Innosuisse project
Rolling Stock Scheduling (RSSched) by SBB and ETH Zurich.

# Usage

To get started with the whole RSSched project, have a look at this [step-by-step instruction](https://github.com/rolling-stock-scheduling/.github/blob/main/getting_started.md).

## Setup

1. install poetry a package manager for python: https://python-poetry.org/docs/

2. install the dependencies for this project via:

```sh
poetry install
```

## Plots
## Usage

Visualize a rolling stock scheduling response from the solver:

```sh
poetry run rssched-plot rssched/data/small_test_response.json
```

Visualize scheduler output:
## Development

Before committing, run the following commands from the project root directory:

```sh
poetry run rssched-plot your/schedule.json
poetry run isort .
poetry run black .
poetry run pytest
```

Note: If working with jupyter notebooks, also delete the cell outputs before committing.

---

© 2024 SBB CFF FFS. Licensed under MIT.
101 changes: 101 additions & 0 deletions notebooks/analyze-depot-vehicles.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Depot Vehicle Analysis\n",
"\n",
"This notebooks illustrates the usage of the **rssched-analysis** package to read rolling stock scheduling responses from the solver.\n",
"\n",
"Run `poetry install` first, and set the ipykernel from the workspace `.venv`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from rssched.io.reader import import_response\n",
"\n",
"import pandas as pd\n",
"\n",
"SOLVER_RESPONSE_FILE = \"../rssched/data/small_test_response.json\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"response = import_response(SOLVER_RESPONSE_FILE)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Vehicles per depot"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data = []\n",
"\n",
"for depot_load in response.schedule.depot_loads:\n",
" depot = depot_load.depot\n",
" for load in depot_load.load:\n",
" vehicle_type = load.vehicle_type\n",
" spawn_count = load.spawn_count\n",
" data.append({\"location\": depot, \"type\": vehicle_type, \"count\": spawn_count})\n",
"\n",
"depots = pd.DataFrame(data)\n",
"depots.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Total vehicle demand"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"vehicles = depots.groupby(\"type\")[\"count\"].sum().reset_index()\n",
"vehicles.head()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
1,107 changes: 892 additions & 215 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.11"
python = "^3.10"
numpy = "^1.26.4"
pandas = "^2.2.1"
plotly = "^5.20.0"
Expand All @@ -16,11 +16,12 @@ pydantic = "^2.6.4"

[tool.poetry.group.dev.dependencies]
pytest = "^8.1.1"
black = "^24.3.0"
black = {extras = ["jupyter"], version = "^24.4.2"}
isort = "^5.13.2"
mypy = "^1.9.0"
flake8 = "^7.0.0"
pydocstyle = "^6.3.0"
ipykernel = "^6.29.5"

[tool.poetry.scripts]
rssched-plot = 'rssched.cli:app'
Expand Down
3 changes: 2 additions & 1 deletion rssched/cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import time
from pathlib import Path
from typing import Annotated

import typer
from typer import Argument, echo
import time

from rssched.io.reader import import_response
from rssched.visualization.plot import generate_plots

Expand Down
8 changes: 7 additions & 1 deletion rssched/data/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ class PkgDataAccess:
def __init__(self) -> None:
pass

@staticmethod
def locate_request() -> Path:
data_folder = resources.files("rssched.data")
file_path = data_folder / "small_test_request.json"
return file_path

@staticmethod
def locate_response() -> Path:
data_folder = resources.files("rssched.data")
file_path = data_folder / "output_small_test_input.json"
file_path = data_folder / "small_test_response.json"
return file_path
Loading

0 comments on commit d8a627f

Please sign in to comment.