GithubHelp home page GithubHelp logo

tklos / mpk Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 681 KB

Stringline plots for buses and trams in Wrocław

Home Page: https://mpk.tk.usermd.net

License: GNU General Public License v3.0

Python 91.16% CSS 2.08% JavaScript 0.51% HTML 6.25%
data-visualisation django matplotlib python transportation-network public-transport stringline-plots trams buses data-science

mpk's Introduction

Stringline plots for buses and trams in Wrocław

How it works

Getting data

Miejskie Przedsiębiorstwo Komunikacyjne — the transportation company in Wrocław (http://mpk.wroc.pl/) provides positions of their buses and trams by querying their API endpoint, e.g.:

$ curl --insecure https://mpk.wroc.pl/bus_position --data 'busList[][]=8&busList[][]=31'
[
    {"name":"31","type":"tram","y":17.01899,"x":51.09238,"k":14482003},
    {"name":"31","type":"tram","y":16.959703,"x":51.140003,"k":14481968},
    {"name":"8","type":"tram","y":17.038694,"x":51.108288,"k":14483257},
    ...
]

MPK also provides GPS coordinates of bus/tram stops and list of stops per route.

Processing

The location data is converted into the position along the route, i.e. last visited stop and percentage of distance covered to the next one. Data are collected a couple of times per minute and saved in the database.

Data visualisation

provided by a Django app, also on https://mpk.tk.usermd.net/.

Sample results

  • Normal data Normal data

  • Some delays Some delays

Installation

  • Install liberation fonts from https://github.com/liberationfonts/liberation-fonts
  • Clone the repository
  • Create a Python>=3.8 virtual environment
  • Create wsgi.py, manage.py and files in mpk/settings/ based on their .template versions
  • Update crontab based on MANAGEMENT/0-crontab
  • Add routes as described in the following section

Adding route

Before adding the first route, add stops locations:

Adding route:

  • Download XML-rozkladyjazdy.zip from https://www.wroclaw.pl/open-data/dataset/rozkladjazdytransportupublicznegoxml_data
  • Copy (line).xml to mpk/resources/routes/
  • If needed, manually modify (line).xml
    There can be only two route versions ("wariant" tags) in the file, corresponding to the two directions of the route. They should have the same stop names, in reverse order. Most of the time, the ones we are interested in are the first ones in the file.
    • Stops in one direction, e.g. "DWORZEC GŁÓWNY (Stawowa)" from line 31, might be removed or copied to the route in the other direction with the same "id" parameter. \u2191 and \u2193 or and can be used for upwards and downwards arrow to mark stops in one direction.
    • Stops with different names in the two directions can be removed or added with the combined name, e.g. "Urząd Wojewódzki / Poczta Główna" from line D.
    • "numer" and "czas" arguments are not read
  • Add route
    (env) $ ./manage.py add_route (line)
  • If needed, manually modify display_name in stops_stop table to make stop names fit on the plot.
  • (0031.xml and 000d.xml from December 2019 are in MANAGEMENT/1-add-stops-and-routes/sample-data/)

mpk's People

Contributors

tklos avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.