Skip to content

arturogonzalezm/trainsimulator

Repository files navigation

Build Status Coverage Status

Train Simulation Python

Requirements:

  1. Assume we live in city A and would like to travel to city E.
  2. Assume there are only up to 5 cities - A, B, C, D, E.
  3. Assume that you have some routes such as A connects to B, A connects to C, B connects to D, D connects to E, B connects to E.
  4. Assume you are given a timetable of train departures (station A departure) and train route times (journey time to go from eg A to B).
  5. Write a simulation which calculates the shortest time between city A and E and the route travelled using Python (2.7 or 3.X).
  6. Design the structure of the input train timetable and journey lengths for the simulation.
  7. Output the total time it takes to run and the route to the command line.
  8. Make sure the routes are configurable for custom user input of timetables and journey lengths.
  9. Ensure that this is production quality code including exception handling, unit tests etc. No third Party libraries to be used except in testing.

Technical Specs:

  • PyCharm or any editor/IDE that supports Python programming language
  • Developed in Python 3.6
  • The source code has been tested on MacOS and Linux and is compatible with Python 3.3 or later
  • TDD and unit testing unittest
  • Continuous Integration and testing Travis CI
  • Version control GitHub
  • Code coverage nosetests, coveralls, coverage

Third party libraries for testing purposes:

  • nose-parameterized
  • coverage
  • coveralls
  • tox
  • tox-travis

Instructions:

  1. Go inside your root directory.
  2. Open your Terminal/command line/command prompt and type:
python main.py
  1. Follow the instructions by entering the requested values.

Example:

Inputs(can be one input 10:00 or several inputs separated by space 10:00 11:00):

Please provide departure time with format 'hour:minute' for route A-B, separated by space, e.g 12:00, 15:32
->10:00
Please provide length of this route with format 'hour:minute', only one duration only
->1:30
*****A-C:
Please provide departure time with format 'hour:minute' for route A-C, separated by space, e.g 12:00, 15:32
->12:00
Please provide length of this route with format 'hour:minute', only one duration only
->1:30
*****B-D:
Please provide departure time with format 'hour:minute' for route B-D, separated by space, e.g 12:00, 15:32
->1:00
Please provide length of this route with format 'hour:minute', only one duration only
->00:30
*****D-E:
Please provide departure time with format 'hour:minute' for route D-E, separated by space, e.g 12:00, 15:32
->3:00
Please provide length of this route with format 'hour:minute', only one duration only
->1:00
*****B-E:
Please provide departure time with format 'hour:minute' for route B-E, separated by space, e.g 12:00, 15:32
->5:00
Please provide length of this route with format 'hour:minute', only one duration only
->2:00
The quickest route is ABDE, duration 18:0
0:00:00.014053

Output:

The quickest route is ABDE duration 18:0
0:00:00.014053

Tests:

  • To see the results of the tests performed by Travis CI please refer to test results

  • Please refer to coverage results to see the code coverage performed by coveralls

  • nosetests and coverage results:

Name                          Stmts   Miss Branch BrPart  Cover
---------------------------------------------------------------
trainsimulator.py                 0      0      0      0   100%
trainsimulator/exception.py      15      0      0      0   100%
trainsimulator/model.py         212      2     90      8    97%
trainsimulator/util.py           69      2     32      4    94%
---------------------------------------------------------------
TOTAL                           296      4    122     12    96%
----------------------------------------------------------------------
Ran 56 tests in 0.241s

OK
  • unittest results:

test_model

test_util

  • You can also run unittests with coverage and the results can be found inside docs/test_model and docs/test_util.

Overview:

diagram

UML:

Packages_trainsimulator:

oneuml

Classes_trainsimulator:

twouml

Packages_tests:

threeuml

Classes_tests:

fouruml

Classes_model:

fiveeuml

Classes_exception:

sixuml


Features:

  • The Train Network class is able to find all the possible combinations/routes between any two stations.
  • It calculates the time between each station.
  • Duration is configurable.
  • Timetable is configurable.
  • Journey length is configurable.

Notes:

  • This program was written assuming the train speed is always the same.
  • This program was written assuming the timetable is same everyday.
  • This project is primarily part of a coding assessment.
  • The command line is only using certain networks.

MIT License

Copyright (c) 2017 Arturo Gonzalez

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

trainsimulator - Advanced journey simulator.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published