maltsev / UnitConversionBot

Telegram bot that converts units (e.g. feet → meters)
https://t.me/UnitConversionBot
GNU General Public License v3.0
8 stars 1 forks source link

Add fuel consumption conversion (L/100km ↔ km/L) #2

Open maltsev opened 4 years ago

maltsev commented 4 years ago

The function that does conversion doesn't support inverse linear relationships (i.e., more L/100km result in less km/L), so it should be rewritten first to support such conversions.

ghost commented 3 years ago

Nearly a year later and i am here writing again. So to convert mpg to L/100km and L/100km to mpg all you need to do is this: 23 L/100km is 10,227 mpg 235,215/(23 L/100km) = 10,227 mpg

235,215/input = output. Works both ways.

To convert to and from UK mpg(abritish gallon is not the same as an american gallon) to L/100km you need to do this: 282,481/input = output. Works both ways again

To convert to and from L/100km to km/L: 100/input = output

Converting from mpg to km/L is not possible in one step without averaging but this is what there is to do to convert them (km/L)2,352=(mpg) (km/L)2,825=(mpg(uk)) (mpg)/2,352=(km/L) (mpg(uk))/2,825=(km/L),

Thank you for your attention again. With these numbers it should be possible to implement fuel consumption relatively easily, right?

maltsev commented 3 years ago

With these numbers it should be possible to implement fuel consumption relatively easily, right?

Unfortunately, not :-(

The conversion itself is pretty straightforward indeed. The problem is how the conversion rules are defined in the code. Right now each category has a basic unit (e.g., 1 gram). Then all other units are defined as a multiplier to this basic unit (e.g., 1 kg = 1000 * 1 gram, 1 mg = 0.001 * 1 gram, and so on).

But mpgL/100km conversion isn't possible to write in such a was as the more mpg you have the less L/100km you'll get.