Git Product home page Git Product logo

gympass-race's Introduction

Gympass

This is the solution to this coding challenge Gympass.

This app was built using Elixir. Make sure that you have it installed on your machine ;)

Running tests

On terminal, run:

$ mix test

Running the application

I decided to use escript to run the application from the command line. There are probably better ways to do that with Elixir, but the lack of production code with it led me to this approach.

Compiling

$ mix escript.build

Running

./gympass --file <file_name>

(There is a file named race_log in the root folder, you can use it)

You should get the output like:


๐Ÿ Gympass Kart Race ๐ŸŽ ๐ŸŽ ๐ŸŽ

Position  Pilot                  Laps    Time           Best Lap       Avg Lap Speed  After 1st              
1         038 โ€“ F.MASSA          4       00:04:11.578   00:01:03.170   44.245         00:00:00.0             
2         002 โ€“ K.RAIKKONEN      4       00:04:15.153   00:01:03.076   43.627         00:00:03.575           
3         033 โ€“ R.BARRICHELLO    4       00:04:16.080   00:01:04.002   43.467         00:00:04.502           
4         023 โ€“ M.WEBBER         4       00:04:17.722   00:01:04.216   43.191         00:00:06.144           
5         015 โ€“ F.ALONSO         4       00:04:54.221   00:01:07.011   38.066         00:00:42.643           
6         011 โ€“ S.VETTEL         3       00:06:27.276   00:01:18.097   25.745         00:02:15.698           


โฑ The best lap
Pilot                  Time           
002 โ€“ K.RAIKKONEN      00:01:03.076

or, in case of empty files:

Error: empty_log

Decisions and next steps

I am not proficient in Elixir, but it is something I've been looking into and am very excited about. It's syntax makes functional programming easy to learn and use.

I've decided to pass all the data into a stream of modifications, abusing on data manipulation with map and reduce because I underrstand thast situations like the one proposed by the exercise is more about transforming data than recognizing entities, classes, models. That is also the reason why I didn't choose an object oriented language such as Ruby or C#.

As for Elixir, I didn't use OTP, for two reasons. The first one is: I don't want to impress you with things I have never worked with and am not proficient. Elixir really shines when using OTP, but I just wanted to solve this by using a simple and plain FP approach. Second I don't think the problem demanded.

Could I use it? Sure. I can see a scenario where I am parsing a log file thousands of times bigger, then I could have made each line or each chunk of lines to be processed in isolation and paralelised. If anything goes wrong with it, the process can be restarted or something like that. The magic of OTP.

I also think I could have stressed more the wrong messages scenarios. Log files with wrong formats and things like that. I have only tested scenarios with valid data.

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.