From 618399cb09deebb1236a931a5b8b1751ab9d5525 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GENO133\\IvanPlex" Date: Thu, 25 Jan 2024 08:31:56 -0700 Subject: [PATCH] more gas fixes due to european locale. --- Controllers/VehicleController.cs | 5 +---- Helper/GasHelper.cs | 10 ++++++++-- Views/Home/_Settings.cshtml | 2 +- Views/Vehicle/_CostMakeUpReport.cshtml | 12 ++++++------ Views/Vehicle/_Gas.cshtml | 2 +- Views/Vehicle/_GasCostByMonthReport.cshtml | 2 +- Views/Vehicle/_MPGByMonthReport.cshtml | 2 +- 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Controllers/VehicleController.cs b/Controllers/VehicleController.cs index bcbf285..4532d23 100644 --- a/Controllers/VehicleController.cs +++ b/Controllers/VehicleController.cs @@ -317,7 +317,6 @@ namespace CarCareTracker.Controllers var vehicleRecords = _gasRecordDataAccess.GetGasRecordsByVehicleId(vehicleId); bool useMPG = _config.GetUserConfig(User).UseMPG; bool useUKMPG = _config.GetUserConfig(User).UseUKMPG; - vehicleRecords = vehicleRecords.OrderBy(x => x.Date).ThenBy(x => x.Mileage).ToList(); var convertedRecords = _gasHelper.GetGasRecordViewModels(vehicleRecords, useMPG, useUKMPG); var exportData = convertedRecords.Select(x => new GasRecordExportModel { @@ -530,8 +529,6 @@ namespace CarCareTracker.Controllers public IActionResult GetGasRecordsByVehicleId(int vehicleId) { var result = _gasRecordDataAccess.GetGasRecordsByVehicleId(vehicleId); - //need it in ascending order to perform computation. - result = result.OrderBy(x => x.Date).ThenBy(x => x.Mileage).ToList(); //check if the user uses MPG or Liters per 100km. var userConfig = _config.GetUserConfig(User); bool useMPG = userConfig.UseMPG; @@ -994,7 +991,7 @@ namespace CarCareTracker.Controllers var gasViewModels = _gasHelper.GetGasRecordViewModels(gasRecords, useMPG, useUKMPG); if (gasViewModels.Any()) { - averageMPG = _gasHelper.GetAverageGasMileage(gasViewModels); + averageMPG = _gasHelper.GetAverageGasMileage(gasViewModels, useMPG); } vehicleHistory.MPG = averageMPG; //insert servicerecords diff --git a/Helper/GasHelper.cs b/Helper/GasHelper.cs index cacad93..2d12758 100644 --- a/Helper/GasHelper.cs +++ b/Helper/GasHelper.cs @@ -5,11 +5,11 @@ namespace CarCareTracker.Helper public interface IGasHelper { List GetGasRecordViewModels(List result, bool useMPG, bool useUKMPG); - string GetAverageGasMileage(List results); + string GetAverageGasMileage(List results, bool useMPG); } public class GasHelper : IGasHelper { - public string GetAverageGasMileage(List results) + public string GetAverageGasMileage(List results, bool useMPG) { var recordWithCalculatedMPG = results.Where(x => x.MilesPerGallon > 0); var minMileage = results.Min(x => x.Mileage); @@ -19,12 +19,18 @@ namespace CarCareTracker.Helper var totalGallonsConsumed = recordWithCalculatedMPG.Sum(x => x.Gallons); var deltaMileage = maxMileage - minMileage; var averageGasMileage = (maxMileage - minMileage) / totalGallonsConsumed; + if (!useMPG) + { + averageGasMileage = 100 / averageGasMileage; + } return averageGasMileage.ToString("F"); } return "0"; } public List GetGasRecordViewModels(List result, bool useMPG, bool useUKMPG) { + //need to order by to get correct results + result = result.OrderBy(x => x.Date).ThenBy(x => x.Mileage).ToList(); var computedResults = new List(); int previousMileage = 0; decimal unFactoredConsumption = 0.00M; diff --git a/Views/Home/_Settings.cshtml b/Views/Home/_Settings.cshtml index f899ca1..149570b 100644 --- a/Views/Home/_Settings.cshtml +++ b/Views/Home/_Settings.cshtml @@ -154,7 +154,7 @@
- Version 1.0.7 + Version 1.0.8

Proudly developed in the rural town of Price, Utah by Hargata Softworks. diff --git a/Views/Vehicle/_CostMakeUpReport.cshtml b/Views/Vehicle/_CostMakeUpReport.cshtml index 4f89530..63ed97f 100644 --- a/Views/Vehicle/_CostMakeUpReport.cshtml +++ b/Views/Vehicle/_CostMakeUpReport.cshtml @@ -12,14 +12,14 @@ labels: ["Service Records", "Repairs", "Upgrades", "Tax", "Fuel"], datasets: [ { - label: "Expenses by Category", + label: "Expenses by Type", backgroundColor: ["#003f5c", "#58508d", "#bc5090", "#ff6361", "#ffa600"], data: [ - @Model.ServiceRecordSum, - @Model.CollisionRecordSum, - @Model.UpgradeRecordSum, - @Model.TaxRecordSum, - @Model.GasRecordSum + globalParseFloat('@Model.ServiceRecordSum'), + globalParseFloat('@Model.CollisionRecordSum'), + globalParseFloat('@Model.UpgradeRecordSum'), + globalParseFloat('@Model.TaxRecordSum'), + globalParseFloat('@Model.GasRecordSum') ] } ] diff --git a/Views/Vehicle/_Gas.cshtml b/Views/Vehicle/_Gas.cshtml index f254bc0..25b7dee 100644 --- a/Views/Vehicle/_Gas.cshtml +++ b/Views/Vehicle/_Gas.cshtml @@ -41,7 +41,7 @@ @($"# of Gas Records: {Model.GasRecords.Count()}") @if (Model.GasRecords.Where(x => x.MilesPerGallon > 0).Any()) { - @($"Average Fuel Economy: {gasHelper.GetAverageGasMileage(Model.GasRecords)}") + @($"Average Fuel Economy: {gasHelper.GetAverageGasMileage(Model.GasRecords, useMPG)}") @($"Min Fuel Economy: {Model.GasRecords.Where(y => y.MilesPerGallon > 0)?.Min(x => x.MilesPerGallon).ToString("F") ?? "0"}") @($"Max Fuel Economy: {Model.GasRecords.Max(x => x.MilesPerGallon).ToString("F") ?? "0"}") } diff --git a/Views/Vehicle/_GasCostByMonthReport.cshtml b/Views/Vehicle/_GasCostByMonthReport.cshtml index 0c3de45..7bbe2ee 100644 --- a/Views/Vehicle/_GasCostByMonthReport.cshtml +++ b/Views/Vehicle/_GasCostByMonthReport.cshtml @@ -17,7 +17,7 @@ @foreach (CostForVehicleByMonth gasCost in Model) { @:barGraphLabels.push("@gasCost.MonthName"); - @:barGraphData.push(@gasCost.Cost); + @:barGraphData.push(globalParseFloat('@gasCost.Cost')); var index = sortedByMPG.FindIndex(x => x.MonthName == gasCost.MonthName); @:barGraphColors.push('@barGraphColors[index]'); } diff --git a/Views/Vehicle/_MPGByMonthReport.cshtml b/Views/Vehicle/_MPGByMonthReport.cshtml index 63bf960..e0bf9e6 100644 --- a/Views/Vehicle/_MPGByMonthReport.cshtml +++ b/Views/Vehicle/_MPGByMonthReport.cshtml @@ -18,7 +18,7 @@ @foreach (CostForVehicleByMonth gasCost in Model) { @:barGraphLabels.push("@gasCost.MonthName"); - @:barGraphData.push(@gasCost.Cost); + @:barGraphData.push(globalParseFloat('@gasCost.Cost')); var index = sortedByMPG.FindIndex(x => x.MonthName == gasCost.MonthName); @:barGraphColors.push('@barGraphColors[index]'); }