Merge pull request #490 from hargata/Hargata/fix.alt.fuel

Fix Alternate Fuel Mileage Bug
This commit is contained in:
Hargata Softworks
2024-04-12 08:04:28 -06:00
committed by GitHub
3 changed files with 29 additions and 30 deletions

View File

@@ -8,7 +8,7 @@ namespace CarCareTracker.Helper
/// </summary> /// </summary>
public static class StaticHelper public static class StaticHelper
{ {
public static string VersionNumber = "1.3.0"; public static string VersionNumber = "1.3.1";
public static string DbName = "data/cartracker.db"; public static string DbName = "data/cartracker.db";
public static string UserConfigPath = "config/userConfig.json"; public static string UserConfigPath = "config/userConfig.json";
public static string GenericErrorMessage = "An error occurred, please try again later"; public static string GenericErrorMessage = "An error occurred, please try again later";

View File

@@ -175,28 +175,28 @@ function convertGasConsumptionUnits(currentUnit, destinationUnit, save) {
case "l": case "l":
$("[data-gas-type='consumption']").map((index, elem) => { $("[data-gas-type='consumption']").map((index, elem) => {
var convertedAmount = globalParseFloat(elem.innerText) * 3.785; var convertedAmount = globalParseFloat(elem.innerText) * 3.785;
elem.innerText = convertedAmount.toFixed(2); elem.innerText = globalFloatToString(convertedAmount.toFixed(2));
sender.text(sender.text().replace(sender.attr("data-unit"), "l")); sender.text(sender.text().replace(sender.attr("data-unit"), "l"));
sender.attr("data-unit", "l"); sender.attr("data-unit", "l");
}); });
$("[data-gas-type='unitcost']").map((index, elem) => { $("[data-gas-type='unitcost']").map((index, elem) => {
var convertedAmount = globalParseFloat(elem.innerText) / 3.785; var convertedAmount = globalParseFloat(elem.innerText) / 3.785;
var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2; var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2;
elem.innerText = `${getGlobalConfig().currencySymbol}${convertedAmount.toFixed(decimalPoints)}`; elem.innerText = `${getGlobalConfig().currencySymbol}${globalFloatToString(convertedAmount.toFixed(decimalPoints))}`;
}); });
if (save) { setDebounce(saveUserGasTabPreferences); } if (save) { setDebounce(saveUserGasTabPreferences); }
break; break;
case "imp gal": case "imp gal":
$("[data-gas-type='consumption']").map((index, elem) => { $("[data-gas-type='consumption']").map((index, elem) => {
var convertedAmount = globalParseFloat(elem.innerText) / 1.201; var convertedAmount = globalParseFloat(elem.innerText) / 1.201;
elem.innerText = convertedAmount.toFixed(2); elem.innerText = globalFloatToString(convertedAmount.toFixed(2));
sender.text(sender.text().replace(sender.attr("data-unit"), "imp gal")); sender.text(sender.text().replace(sender.attr("data-unit"), "imp gal"));
sender.attr("data-unit", "imp gal"); sender.attr("data-unit", "imp gal");
}); });
$("[data-gas-type='unitcost']").map((index, elem) => { $("[data-gas-type='unitcost']").map((index, elem) => {
var convertedAmount = globalParseFloat(elem.innerText) * 1.201; var convertedAmount = globalParseFloat(elem.innerText) * 1.201;
var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2; var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2;
elem.innerText = `${getGlobalConfig().currencySymbol}${convertedAmount.toFixed(decimalPoints)}`; elem.innerText = `${getGlobalConfig().currencySymbol}${globalFloatToString(convertedAmount.toFixed(decimalPoints))}`;
}); });
if (save) { setDebounce(saveUserGasTabPreferences); } if (save) { setDebounce(saveUserGasTabPreferences); }
break; break;
@@ -206,28 +206,28 @@ function convertGasConsumptionUnits(currentUnit, destinationUnit, save) {
case "US gal": case "US gal":
$("[data-gas-type='consumption']").map((index, elem) => { $("[data-gas-type='consumption']").map((index, elem) => {
var convertedAmount = globalParseFloat(elem.innerText) / 3.785; var convertedAmount = globalParseFloat(elem.innerText) / 3.785;
elem.innerText = convertedAmount.toFixed(2); elem.innerText = globalFloatToString(convertedAmount.toFixed(2));
sender.text(sender.text().replace(sender.attr("data-unit"), "US gal")); sender.text(sender.text().replace(sender.attr("data-unit"), "US gal"));
sender.attr("data-unit", "US gal"); sender.attr("data-unit", "US gal");
}); });
$("[data-gas-type='unitcost']").map((index, elem) => { $("[data-gas-type='unitcost']").map((index, elem) => {
var convertedAmount = globalParseFloat(elem.innerText) * 3.785; var convertedAmount = globalParseFloat(elem.innerText) * 3.785;
var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2; var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2;
elem.innerText = `${getGlobalConfig().currencySymbol}${convertedAmount.toFixed(decimalPoints)}`; elem.innerText = `${getGlobalConfig().currencySymbol}${globalFloatToString(convertedAmount.toFixed(decimalPoints))}`;
}); });
if (save) { setDebounce(saveUserGasTabPreferences); } if (save) { setDebounce(saveUserGasTabPreferences); }
break; break;
case "imp gal": case "imp gal":
$("[data-gas-type='consumption']").map((index, elem) => { $("[data-gas-type='consumption']").map((index, elem) => {
var convertedAmount = globalParseFloat(elem.innerText) / 4.546; var convertedAmount = globalParseFloat(elem.innerText) / 4.546;
elem.innerText = convertedAmount.toFixed(2); elem.innerText = globalFloatToString(convertedAmount.toFixed(2));
sender.text(sender.text().replace(sender.attr("data-unit"), "imp gal")); sender.text(sender.text().replace(sender.attr("data-unit"), "imp gal"));
sender.attr("data-unit", "imp gal"); sender.attr("data-unit", "imp gal");
}); });
$("[data-gas-type='unitcost']").map((index, elem) => { $("[data-gas-type='unitcost']").map((index, elem) => {
var convertedAmount = globalParseFloat(elem.innerText) * 4.546; var convertedAmount = globalParseFloat(elem.innerText) * 4.546;
var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2; var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2;
elem.innerText = `${getGlobalConfig().currencySymbol}${convertedAmount.toFixed(decimalPoints)}`; elem.innerText = `${getGlobalConfig().currencySymbol}${globalFloatToString(convertedAmount.toFixed(decimalPoints))}`;
}); });
if (save) { setDebounce(saveUserGasTabPreferences); } if (save) { setDebounce(saveUserGasTabPreferences); }
break; break;
@@ -237,28 +237,28 @@ function convertGasConsumptionUnits(currentUnit, destinationUnit, save) {
case "US gal": case "US gal":
$("[data-gas-type='consumption']").map((index, elem) => { $("[data-gas-type='consumption']").map((index, elem) => {
var convertedAmount = globalParseFloat(elem.innerText) * 1.201; var convertedAmount = globalParseFloat(elem.innerText) * 1.201;
elem.innerText = convertedAmount.toFixed(2); elem.innerText = globalFloatToString(convertedAmount.toFixed(2));
sender.text(sender.text().replace(sender.attr("data-unit"), "US gal")); sender.text(sender.text().replace(sender.attr("data-unit"), "US gal"));
sender.attr("data-unit", "US gal"); sender.attr("data-unit", "US gal");
}); });
$("[data-gas-type='unitcost']").map((index, elem) => { $("[data-gas-type='unitcost']").map((index, elem) => {
var convertedAmount = globalParseFloat(elem.innerText) / 1.201; var convertedAmount = globalParseFloat(elem.innerText) / 1.201;
var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2; var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2;
elem.innerText = `${getGlobalConfig().currencySymbol}${convertedAmount.toFixed(decimalPoints)}`; elem.innerText = `${getGlobalConfig().currencySymbol}${globalFloatToString(convertedAmount.toFixed(decimalPoints))}`;
}); });
if (save) { setDebounce(saveUserGasTabPreferences); } if (save) { setDebounce(saveUserGasTabPreferences); }
break; break;
case "l": case "l":
$("[data-gas-type='consumption']").map((index, elem) => { $("[data-gas-type='consumption']").map((index, elem) => {
var convertedAmount = globalParseFloat(elem.innerText) * 4.546; var convertedAmount = globalParseFloat(elem.innerText) * 4.546;
elem.innerText = convertedAmount.toFixed(2); elem.innerText = globalFloatToString(convertedAmount.toFixed(2));
sender.text(sender.text().replace(sender.attr("data-unit"), "l")); sender.text(sender.text().replace(sender.attr("data-unit"), "l"));
sender.attr("data-unit", "l"); sender.attr("data-unit", "l");
}); });
$("[data-gas-type='unitcost']").map((index, elem) => { $("[data-gas-type='unitcost']").map((index, elem) => {
var convertedAmount = globalParseFloat(elem.innerText) / 4.546; var convertedAmount = globalParseFloat(elem.innerText) / 4.546;
var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2; var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2;
elem.innerText = `${getGlobalConfig().currencySymbol}${convertedAmount.toFixed(decimalPoints)}`; elem.innerText = `${getGlobalConfig().currencySymbol}${globalFloatToString(convertedAmount.toFixed(decimalPoints))}`;
}); });
if (save) { setDebounce(saveUserGasTabPreferences); } if (save) { setDebounce(saveUserGasTabPreferences); }
break; break;
@@ -275,7 +275,7 @@ function convertFuelMileageUnits(currentUnit, destinationUnit, save) {
var convertedAmount = globalParseFloat(elem.innerText); var convertedAmount = globalParseFloat(elem.innerText);
if (convertedAmount > 0) { if (convertedAmount > 0) {
convertedAmount = 100 / convertedAmount; convertedAmount = 100 / convertedAmount;
elem.innerText = convertedAmount.toFixed(2); elem.innerText = globalFloatToString(convertedAmount.toFixed(2));
} }
}); });
//update labels up top. //update labels up top.
@@ -283,19 +283,19 @@ function convertFuelMileageUnits(currentUnit, destinationUnit, save) {
if (newAverage > 0) { if (newAverage > 0) {
newAverage = 100 / newAverage; newAverage = 100 / newAverage;
var averageLabel = $("#averageFuelMileageLabel"); var averageLabel = $("#averageFuelMileageLabel");
averageLabel.text(`${averageLabel.text().split(':')[0]}: ${newAverage.toFixed(2)}`); averageLabel.text(`${averageLabel.text().split(':')[0]}: ${globalFloatToString(newAverage.toFixed(2))}`);
} }
var newMin = globalParseFloat($("#minFuelMileageLabel").text().split(":")[1].trim()); var newMin = globalParseFloat($("#minFuelMileageLabel").text().split(":")[1].trim());
if (newMin > 0) { if (newMin > 0) {
newMin = 100 / newMin; newMin = 100 / newMin;
var minLabel = $("#minFuelMileageLabel"); var minLabel = $("#minFuelMileageLabel");
minLabel.text(`${minLabel.text().split(':')[0]}: ${newMin.toFixed(2)}`); minLabel.text(`${minLabel.text().split(':')[0]}: ${globalFloatToString(newMin.toFixed(2))}`);
} }
var newMax = globalParseFloat($("#maxFuelMileageLabel").text().split(":")[1].trim()); var newMax = globalParseFloat($("#maxFuelMileageLabel").text().split(":")[1].trim());
if (newMax > 0) { if (newMax > 0) {
newMax = 100 / newMax; newMax = 100 / newMax;
var maxLabel = $("#maxFuelMileageLabel"); var maxLabel = $("#maxFuelMileageLabel");
maxLabel.text(`${maxLabel.text().split(':')[0]}: ${newMax.toFixed(2)}`); maxLabel.text(`${maxLabel.text().split(':')[0]}: ${globalFloatToString(newMax.toFixed(2))}`);
} }
sender.text(sender.text().replace(sender.attr("data-unit"), "km/l")); sender.text(sender.text().replace(sender.attr("data-unit"), "km/l"));
sender.attr("data-unit", "km/l"); sender.attr("data-unit", "km/l");
@@ -309,27 +309,26 @@ function convertFuelMileageUnits(currentUnit, destinationUnit, save) {
var convertedAmount = globalParseFloat(elem.innerText); var convertedAmount = globalParseFloat(elem.innerText);
if (convertedAmount > 0) { if (convertedAmount > 0) {
convertedAmount = 100 / convertedAmount; convertedAmount = 100 / convertedAmount;
elem.innerText = convertedAmount.toFixed(2); elem.innerText = globalFloatToString(convertedAmount.toFixed(2));
} }
}); });
var newAverage = globalParseFloat($("#averageFuelMileageLabel").text().split(":")[1].trim()); var newAverage = globalParseFloat($("#averageFuelMileageLabel").text().split(":")[1].trim());
if (newAverage > 0) { if (newAverage > 0) {
newAverage = 100 / newAverage; newAverage = 100 / newAverage;
var averageLabel = $("#averageFuelMileageLabel"); var averageLabel = $("#averageFuelMileageLabel");
averageLabel.text(`${averageLabel.text().split(':')[0]}: ${newAverage.toFixed(2)}`); averageLabel.text(`${averageLabel.text().split(':')[0]}: ${globalFloatToString(newAverage.toFixed(2))}`);
} }
var newMin = globalParseFloat($("#minFuelMileageLabel").text().split(":")[1].trim()); var newMin = globalParseFloat($("#minFuelMileageLabel").text().split(":")[1].trim());
if (newMin > 0) { if (newMin > 0) {
newMin = 100 / newMin; newMin = 100 / newMin;
var minLabel = $("#minFuelMileageLabel"); var minLabel = $("#minFuelMileageLabel");
minLabel.text(`${minLabel.text().split(':')[0]}: ${newMin.toFixed(2)}`); minLabel.text(`${minLabel.text().split(':')[0]}: ${globalFloatToString(newMin.toFixed(2))}`);
} }
var newMax = globalParseFloat($("#maxFuelMileageLabel").text().split(":")[1].trim()); var newMax = globalParseFloat($("#maxFuelMileageLabel").text().split(":")[1].trim());
if (newMax > 0) { if (newMax > 0) {
newMax = 100 / newMax; newMax = 100 / newMax;
var maxLabel = $("#maxFuelMileageLabel"); var maxLabel = $("#maxFuelMileageLabel");
maxLabel.text(`${maxLabel.text().split(':')[0]}: ${newMax.toFixed(2)}`); maxLabel.text(`${maxLabel.text().split(':')[0]}: ${globalFloatToString(newMax.toFixed(2))}`);
} }
sender.text(sender.text().replace(sender.attr("data-unit"), "l/100km")); sender.text(sender.text().replace(sender.attr("data-unit"), "l/100km"));
sender.attr("data-unit", "l/100km"); sender.attr("data-unit", "l/100km");
@@ -358,17 +357,17 @@ function updateMPGLabels() {
if (!getGlobalConfig().useMPG && $("[data-gas='fueleconomy']").attr("data-unit") != 'km/l' && averageMPG > 0) { if (!getGlobalConfig().useMPG && $("[data-gas='fueleconomy']").attr("data-unit") != 'km/l' && averageMPG > 0) {
averageMPG = 100 / averageMPG; averageMPG = 100 / averageMPG;
} }
averageLabel.text(`${averageLabel.text().split(':')[0]}: ${averageMPG.toFixed(2)}`); averageLabel.text(`${averageLabel.text().split(':')[0]}: ${globalFloatToString(averageMPG.toFixed(2))}`);
} else { } else {
averageLabel.text(`${averageLabel.text().split(':')[0]}: 0.00`); averageLabel.text(`${averageLabel.text().split(':')[0]}: 0.00`);
} }
if (!getGlobalConfig().useMPG && $("[data-gas='fueleconomy']").attr("data-unit") != 'km/l') { if (!getGlobalConfig().useMPG && $("[data-gas='fueleconomy']").attr("data-unit") != 'km/l') {
maxLabel.text(`${maxLabel.text().split(':')[0]}: ${minMPG.toFixed(2)}`); maxLabel.text(`${maxLabel.text().split(':')[0]}: ${globalFloatToString(minMPG.toFixed(2))}`);
minLabel.text(`${minLabel.text().split(':')[0]}: ${maxMPG.toFixed(2)}`); minLabel.text(`${minLabel.text().split(':')[0]}: ${globalFloatToString(maxMPG.toFixed(2))}`);
} }
else { else {
minLabel.text(`${minLabel.text().split(':')[0]}: ${minMPG.toFixed(2)}`); minLabel.text(`${minLabel.text().split(':')[0]}: ${globalFloatToString(minMPG.toFixed(2))}`);
maxLabel.text(`${maxLabel.text().split(':')[0]}: ${maxMPG.toFixed(2)}`); maxLabel.text(`${maxLabel.text().split(':')[0]}: ${globalFloatToString(maxMPG.toFixed(2))}`);
} }
} }
} }

View File

@@ -486,13 +486,13 @@ function getRecordsDeltaStats(recordIds) {
costSum = costSum.toFixed(2); costSum = costSum.toFixed(2);
Swal.fire({ Swal.fire({
title: "Record Statistics", title: "Record Statistics",
html: `<p>Average Distance Traveled between Records: ${averageOdo}</p> html: `<p>Average Distance Traveled between Records: ${globalFloatToString(averageOdo)}</p>
<br /> <br />
<p>Average Days between Records: ${averageDays}</p> <p>Average Days between Records: ${averageDays}</p>
<br /> <br />
<p>Total Cost: ${getGlobalConfig().currencySymbol} ${costSum}</p> <p>Total Cost: ${getGlobalConfig().currencySymbol} ${globalFloatToString(costSum)}</p>
<br /> <br />
<p>Average Cost: ${getGlobalConfig().currencySymbol} ${averageSum}</p>` <p>Average Cost: ${getGlobalConfig().currencySymbol} ${globalFloatToString(averageSum)}</p>`
, ,
icon: "info" icon: "info"
}); });