chocochino / go-cli

Ride-hailing simulation in CLI for SEA CFX's second stage elimination

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-cli

  • This is a simple CLI written as ruby gem
  • This gem is created by Livia Lohanda to fulfill second stage in Software Engineering Academy COMPFEST X - GO-JEK.

Dependencies

  • Ruby version 2.5+
  • Bundler version 1.16+ gem install bundler

Installation

  • cd to directory go_cli
  • rake install to install gem locally

Running

  • cd to directory go_cli
  • go-cli to run with random user location and 5 randomly generated drivers in 20*20 map. This is the default setting.
  • go-cli <n> <x> <y> to run with 5 randomly generated drivers in n*n map and user positioned in (x,y)
  • go-cli <filename>.yml to run with pre-determined values. If loading failed, gem will run as if there are no arguments.
  • On running there are four options
    1. Show map. This is shown using coordinate system (x-axis from left-to-right, y-axis from bottom-to-top).
    2. Order GO-RIDE. Make sure the destination's coordinate are written in format x,y.
    3. View history. All confirmed rides will be logged in gem-generated file history.csv. Deleting this file will make you lose your ride logs.
    4. Exit program.

Pre-determined values

You can run this gem with some values determined by yourself instead of being randomly generated by the gem. Those values are:

  • Map size
  • User's position
  • All driver's data

These values must be written in a YAML file and placed at the same directory as installation. See sample.yml to see how the values are written.

Make sure all number values are non-negative numbers.

Map size

Map size is derived from map-size variable. Write map-size: <n> without <> and the gem will be running using n*n map.

User's position

User's position is derived from user variable. Write

user:
  x: <x>
  y: <y>

without <> and the gem will be running with the user placed in (x,y)

Driver's details

Driver details is derived from drivers variable. Drivers with no name will have their names assigned by gem. Drivers positioned outside the map's range will not be included. For example, if the map size is 20 and we write

drivers:
  -
    name: "Hasan"
    x: 5
    y: 6
  - 
    x: 7
    y: 1
  - 
    name: "Udin"
    x: 21
    y: 10
  -
    y: 9
    x: 10

this is how the gem will process the file input:

  • Driver 1 will be named "Hasan", positioned at (5,6)
  • Driver 2 will be named "No. 2" using gem's default naming convention, positioned at (7,1)
  • Driver 3 will not be assigned, because it was positioned outside the map area.
  • Driver 4 will be named "No. 3" using gem's default naming convention, positioned at (10,9)

Notable design decisions

  • The program is created as Ruby gem with Bundler because gems are easy to pack into a program and more portable. Also, using Bundler, a lot of setup has been done under-the-hood, so I can focus on creating the CLI instead of figuring out how to make this program runs in Linux and Windows (my environment was Ubuntu 16.04 for Windows 10).
  • The testing was done manually (not really TDD) because I implemented the file input at the very last stage, so I cannot write the RSpec test program.
  • File input use YAML text file because it can be easily converted into hashes. By using hashes, user do not need to worry about the order of the input.
  • Ride logs are stored in CSV text file because it is easy to manipulate. For example, if we need to modify data types in logs, or retrieve only specific column/row from the logs, this can be easily done using Ruby's built-in commands.
  • Coordinates are stored in a class named Coordinates instead of arrays to ease assigning methods and make initialization more robust. For example, in case the coordinates are in negative numbers, they will be converted into non-negative numbers first.
  • Driver and User both inherit class Person. The difference of these objects lies in name and ID assignation.
  • Order, Map, and FileParser are grouped in modules to increase modularity. They are not written as classes because in implementation, these command-groups does not need instances.

About

Ride-hailing simulation in CLI for SEA CFX's second stage elimination


Languages

Language:Ruby 99.2%Language:Shell 0.8%