aanndryyyy / bolt-calculator

Calculator for Bolt Drive
https://aanndryyyy.github.io/bolt-calculator/
GNU General Public License v3.0
1 stars 1 forks source link

Wrong if-condition #1

Open kaurilves opened 1 year ago

kaurilves commented 1 year ago

When certain conditions meet, the calculator calculates a more expensive price for the customer. The cause is an incorrect if-condition located in src/routes/+page.svelte function get_duration_price(). Provided condition ( ( minutes + hours60 )car.price.minute >= car.price.day ). There, the hours are converted into minutes, the remaining minutes are added to it, then minutes are multiplied by the minute price and finally the result is compared with the daily price. If the daily price is less or equal, then 1 day is incremented into days variable. In other words, the daily price is compared only with the more expensive minute price. The result is that in a certain range of minutes, the application calculates the price as more expensive (daily price), although in reality the hourly price + minute price or even just the hourly price would be cheaper (as in the following example). For example lets take Skoda Scala. If you set the time period to 225 minutes and 0km, the correct price should be €19.96 (4h x €4.99). Instead, this calculator gives a price of 27.89 (daily price), which is considerably more expensive.

Correct statement should be if (minutes car.price.minute + hours car.price.hour >= car.price.day).

Our lecturer gave us (first year students) a simple Python assignment where we had to make the same calculator and then check the results on that calculator. On some students , this bug could actually short-circuit the wires. :)

aanndryyyy commented 1 year ago

@kaurilves what a great find! Thanks! However, this repository will soon be archived as it has been replaced by a newer version at https://rentalize.eu. You can have a look at that project and see if the pricing logic is accurate for all providers, starting with Bolt: https://github.com/aanndryyyy/car-sharing-comparison/blob/main/src/helpers/calculators/calculateBoltPrice.ts. There we are utilising unit tests to check the logic, so this condition could be added there.

I guess your initial assignment was to reverse-engineer the pricing logic?

Faulty logic location: https://github.com/aanndryyyy/bolt-calculator/blob/2a28c4d08b52b38ae66e9aa3e10ed2ab70002cf9/src/routes/%2Bpage.svelte#L28