Giter Club home page Giter Club logo

railostools's Introduction

RailOSTools

RailOS Tools C++ RailOS Tools Python RailOSTools Java RailOS Tools Rust

Railway Operation Simulator Toolkit

RailOSTools provides a set of tools for working with Railway Operation Simulator program files. The repository contains various API language implementations to provide access to Railway Operation Simulator session and file properties

Python

codecov

All command line tools are available under the parent railostools command:

$ railostools
Usage: railostools [OPTIONS] COMMAND [ARGS]...

  Python based utilities for Railway Operation Simulator

Options:
  --debug / --normal  Run in debug mode
  --help              Show this message and exit.

Commands:
  ttb2json  Extract RailOS timetable file to json

Command Line Interface

Parsing .ttb Files

The command ttb2json converts a .ttb file to a JSON file containing the metadata for the services. This allows for easier data interpretation within other projects.

$ railostools ttb2json --help
Usage: railostools ttb2json [OPTIONS] TTB_FILE

  Extract RailOS timetable file to json

Options:
  --output TEXT  JSON output file
  --help         Show this message and exit.

Parsing .rly Files

The command rly2json converts a .rly file to a JSON file containing the metadata for route elements. This allows for easier data interpretation within other projects.

$ railostools rly2json --help
Usage: railostools rly2json [OPTIONS] RLY_FILE

  Extract RailOS railway file to json

Options:
  --output TEXT  JSON output file
  --help         Show this message and exit.

API

Features within railostools can also be accessed via the dedicated Python API.

The TTBParser Class

from railostools.ttb import TTBParser

# Create a parser instance for parsing files
my_parser = TTBParser()

# Parse a timetable file
my_parser.parse('Enoshima_Week_2021.ttb')

# Can access various information
print(f'Timetable starts at {my_parser.start_time}')
print(my_parser.comments)

# Print out all data
print(my_parser.data)

# Save data as JSON file
my_parser.dump('Enoshima_Week_2021.json')

The RlyParser Class

from railostools.rly import RlyParser

# Create a parser instance for parsing files
my_parser = RlyParser()

# Parse a timetable file
my_parser.parse('Antwerpen_Centraal.rly')

# Can access various information
print(f'Number of elements are {my_parser.n_active_elements+my_parser.n_inactive_elements}')

# Print out all data
print(my_parser.data)

# Save data as JSON file
my_parser.dump('Antwerpen_Centraal.json')

Performance Log Monitoring

The performance log parsing module can asynchronously monitor the Railway Operation Simulator logs directory extracting contents which can then be processed by applications live. The Monitor class is designed to only retrieve data when it has been confirmed by file modification time that the log has been updated. These times are also used to fetch the latest log during running. The class uses the Python asyncio library.

import railostools.performance
import asyncio
from railostools.performance import Monitor

ROS_LOG_DIR = 'C:\\Program Files (x86)\\RailwayOperationSimulator\\Railway\\Performance\ logs'

# Create a new monitor pointing to the RailOS log directory
my_monitor = Monitor(ROS_LOG_DIR)

# Create a listener function which will just print the data
# MUST have 'monitor' as an argument, this is the monitor instance
async def listener(monitor: railostools.performance.Monitor, user_name: str) -> None:
    # Run until the monitor stops
    while monitor.running:
        print(f"Running for user '{user_name}'")
        print(monitor.data)
        await asyncio.sleep(10)

# Attach listener function to the async loop of the monitor
# arguments are given as a dictionary
my_monitor.exec_in_parallel(listener, {'user_name': 'John'})

# Finally run the monitor
my_monitor.run()

railostools's People

Contributors

artemis-beta avatar daniel-gill avatar jkwok678 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.