Bug 378967 - Fuel consumption conversion incorrect
Summary: Fuel consumption conversion incorrect
Alias: None
Product: frameworks-kunitconversion
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: 5.32.0
Platform: Fedora RPMs Linux
: NOR normal
Target Milestone: ---
Assignee: John Layt
: 387959 (view as bug list)
Depends on:
Reported: 2017-04-19 14:50 UTC by Radek Novacek
Modified: 2019-04-15 03:01 UTC (History)
6 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.58

Screenshot from KRunner (14.51 KB, image/png)
2017-04-19 14:54 UTC, Radek Novacek

Note You need to log in before you can comment on or make changes to this bug.
Description Radek Novacek 2017-04-19 14:50:57 UTC
Fuel consumption unit conversion doesn't work for some unit combination. Discovered using KRunner Unit Converter plugin.

Expected values:
100 mpg (US) = 2.35215 l/100km
10 l/100 km = 23.5215 mpg (US)
20 kmpl = 5 l/100km

Actual values:
100 mpg (US) = 0.4251700680272109 l/100km
10 l/100 km = 2351.9999999999995 mpg (US)
20 kmpl = 0.2 l/100km

Given that kmpl to mpg conversion is correct (20kmpl = 47.04mpg) I guess that just l/100km is incorrect.

I've used Google Unit Conversion for checking the values (like "https://www.google.com/search?q=100 mpg to l/100km")
Comment 1 Radek Novacek 2017-04-19 14:54:30 UTC
Created attachment 105098 [details]
Screenshot from KRunner
Comment 2 Christoph Feck 2017-04-27 11:54:02 UTC
I doubt KUnitConversion handles reciprocals, so either the units should get removed, or some major rework is needed.
Comment 3 Christoph Feck 2018-01-02 18:13:29 UTC
*** Bug 387959 has been marked as a duplicate of this bug. ***
Comment 4 Kai Uwe Broulik 2018-01-02 18:30:35 UTC
It seems KUnitConversion cannot handle an inverse fraction.
n mpg = 253 / n l/100km
The code tries to do "something" in that direction by overriding toDefault()/fromDefault() but that clearly breaks in one or other form (either mpg→l/100km or, if you fix that, mpg→mpgi and mpg→km/l)
Comment 5 madcatx 2019-04-11 12:41:40 UTC
For those interested, please review the following patch

Comment 6 Albert Astals Cid 2019-04-14 15:59:46 UTC
Git commit bc7495095baa7a70e756c4d2044de2197d1a4e3b by Albert Astals Cid, on behalf of Michal Malý.
Committed on 14/04/2019 at 15:59.
Pushed by aacid into branch 'master'.

Fix l/100 km to MPG conversion

Previous code (probably) worked only for l/100 km -> MPG but not the other way around. Fix this by using reciprocal conversion when necessary.

38.7 MPG -> 6.077 l/100 km; 16.455 km/l; 46.482 MPGI
16.455 km/l -> 6.077 l/100 km; 38.7 MPG
46.48 MPGI -> 6.077 l/100 km

Seems good to me.

Reviewers: broulik, #frameworks, aacid

Subscribers: apol, aacid, meven, kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D20284

M  +20   -0    autotests/convertertest.cpp
M  +23   -9    src/fuel_efficiency.cpp