This repository shows how I solved a code challenge. Focus on the Git history, and check CodeChallengeChanges.md for clarifications and a summary of changes.
Welcome to the Taximeter code challenge! In this challenge, you'll be tasked with implementing a more advanced version of a taximeter. We currently have a simple implementation that calculates the fare based only on the distance traveled. However, we want to enhance this system to include dynamic pricing based on distance, time, and luggage.
Your task is to enhance the existing taximeter implementation to include the following features:
- Implement a pricing model where the price per kilometer is given in a configuration.
- Incorporate a pricing strategy that considers the time taken for each taxi ride.
- Include a supplement (5€) for each piece of luggage that the customer includes, reflected in the final price. This supplement can be added at any time during the ride.
- ATTENTION: We want to evaluate your coding skills, you are free to MODIFY, DELETE or ADD any code you think is necessary to make the code more readable, maintainable, and scalable. Take this as if you were the owner of the App.
- API Provided: You should use
LocationProviderclass, which is provided within the challenge, to obtain the list of point in real time, for full documentation about this tool, refers to down below. - Architecture and Libraries: You have the freedom to choose whatever architecture and libraries you deem suitable for the implementation.
- Production Readiness: Ensure that your solution is production-ready, we would like you to build it in the same way as if you were going to publish to the store.
- Documentation: Document your decisions, rationale, and any assumptions made during the implementation process, consider explaining why certain things are included and others are left out.
- User Interface (UI): The UI design is entirely up to you, but, to make it easier, lets consider the design team has provided us with a raw idea. But feel free to change it as you see it.
- Deliverable: You should commit and push in this repository as if it is the repository of the company you are working on.
Considerations:
- Pricing Configuration The pricing configuration (cost per KM and time...) should be retrieve from here as we assume that it could change at any time
- Dynamic Pricing: for each Km the price should increase the specified amount in the configuration, received through the field
price_per_km - Time Calculation: for each second the price should increase the specified amount in the configuration, received through the field
price_per_second - Luggage Supplement: Each piece of luggage incurs an extra charge of 5 euros. As you can see the supplements are left out of the configuration, so it is up to you to decide how to implement it.
- Extensible: The system should be designed in a way that allows for easy extension of the pricing model. For example, adding a new supplement or changing the pricing strategy should be simple. Helper: LocationProvider: This class is used to get the position (lat, long), and timestamp at realtime, the usage of this class is:
We provide 3 alternative ways of retrieving the route, Kotlin flow, Rx Streams and through simple callbacks, it is up to you to use whatever you like.
fun LocationProvider.getRouteFlow(routeItem, executionConfiguration): Flow<LocationPoint>
LocationProvider.getRouteRxObservable(routeItem, executionConfiguration): Observable<LocationPoint>
LocationProvider.getRouteCallback(routeItem, executionConfiguration, (LocationPoint) -> Unit): Flow<LocationPoint>
routeItem is an enum value that represents the route, it can be Route1, Route2, Route3. that we use to try different scenarios.
executionConfiguration is an enum that changes the speed of the emission of items in either the flow/Observable/Callback, it can be Default, Fast. To develop the UI of the challenge it is better to use the Default configuration,
but for testing the final computation Fast is the way to go, as it 100x times faster than the default configuration.
Assuming the following price configuration, and the currency EUR:
- Tariffs
- price per km: 20c
- price per second: 1c
- supplements:
- luggage: 5 euros/unit
- Distance: 11 kilometers
- Time: 1800 seconds
- Luggage: 1 piece
**Price Calculation - Scenario **
-
Price for 11 kilometers:
- 11km * 0.2 euro/km = 2.2 euros
-
Time for 1800 seconds:
- 1800 seconds * 0.01 euro/second = 18 euros
-
Luggage: 1 piece * 5 euros/piece = 5 euros
-
Total Fare: 2.2 euros + 18 euros + 5 euros = 25.2 euros
