mirror of
https://github.com/hargata/lubelog.git
synced 2025-12-10 00:46:08 -06:00
added support for UK MPG
This commit is contained in:
parent
3fa3dbaa8c
commit
26012bf27a
@ -46,7 +46,8 @@ namespace CarCareTracker.Controllers
|
||||
UseMPG = bool.Parse(_config[nameof(UserConfig.UseMPG)]),
|
||||
UseDescending = bool.Parse(_config[nameof(UserConfig.UseDescending)]),
|
||||
EnableAuth = bool.Parse(_config[nameof(UserConfig.EnableAuth)]),
|
||||
HideZero = bool.Parse(_config[nameof(UserConfig.HideZero)])
|
||||
HideZero = bool.Parse(_config[nameof(UserConfig.HideZero)]),
|
||||
UseUKMPG = bool.Parse(_config[nameof(UserConfig.UseUKMPG)])
|
||||
};
|
||||
return PartialView("_Settings", userConfig);
|
||||
}
|
||||
|
||||
@ -250,6 +250,7 @@ namespace CarCareTracker.Controllers
|
||||
result = result.OrderBy(x => x.Date).ThenBy(x => x.Mileage).ToList();
|
||||
//check if the user uses MPG or Liters per 100km.
|
||||
bool useMPG = bool.Parse(_config[nameof(UserConfig.UseMPG)]);
|
||||
bool useUKMPG = bool.Parse(_config[nameof(UserConfig.UseUKMPG)]);
|
||||
var computedResults = new List<GasRecordViewModel>();
|
||||
int previousMileage = 0;
|
||||
decimal unFactoredConsumption = 0.00M;
|
||||
@ -257,9 +258,19 @@ namespace CarCareTracker.Controllers
|
||||
//perform computation.
|
||||
for (int i = 0; i < result.Count; i++)
|
||||
{
|
||||
var currentObject = result[i];
|
||||
decimal convertedConsumption;
|
||||
if (useUKMPG && useMPG)
|
||||
{
|
||||
//if we're using UK MPG and the user wants imperial calculation insteace of l/100km
|
||||
//if UK MPG is selected then the gas consumption are stored in liters but need to convert into UK gallons for computation.
|
||||
convertedConsumption = currentObject.Gallons / 4.546M;
|
||||
} else
|
||||
{
|
||||
convertedConsumption = currentObject.Gallons;
|
||||
}
|
||||
if (i > 0)
|
||||
{
|
||||
var currentObject = result[i];
|
||||
var deltaMileage = currentObject.Mileage - previousMileage;
|
||||
var gasRecordViewModel = new GasRecordViewModel()
|
||||
{
|
||||
@ -267,22 +278,22 @@ namespace CarCareTracker.Controllers
|
||||
VehicleId = currentObject.VehicleId,
|
||||
Date = currentObject.Date.ToShortDateString(),
|
||||
Mileage = currentObject.Mileage,
|
||||
Gallons = currentObject.Gallons,
|
||||
Gallons = convertedConsumption,
|
||||
Cost = currentObject.Cost,
|
||||
DeltaMileage = deltaMileage,
|
||||
CostPerGallon = (currentObject.Cost / currentObject.Gallons)
|
||||
CostPerGallon = (currentObject.Cost / convertedConsumption)
|
||||
};
|
||||
if (currentObject.IsFillToFull)
|
||||
{
|
||||
//if user filled to full.
|
||||
gasRecordViewModel.MilesPerGallon = useMPG ? ((unFactoredMileage + deltaMileage) / (unFactoredConsumption + currentObject.Gallons)) : 100 / ((unFactoredMileage + deltaMileage) / (unFactoredConsumption + currentObject.Gallons));
|
||||
gasRecordViewModel.MilesPerGallon = useMPG ? ((unFactoredMileage + deltaMileage) / (unFactoredConsumption + convertedConsumption)) : 100 / ((unFactoredMileage + deltaMileage) / (unFactoredConsumption + convertedConsumption));
|
||||
//reset unFactored vars
|
||||
unFactoredConsumption = 0;
|
||||
unFactoredMileage = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
unFactoredConsumption += currentObject.Gallons;
|
||||
unFactoredConsumption += convertedConsumption;
|
||||
unFactoredMileage += deltaMileage;
|
||||
gasRecordViewModel.MilesPerGallon = 0;
|
||||
}
|
||||
@ -292,18 +303,18 @@ namespace CarCareTracker.Controllers
|
||||
{
|
||||
computedResults.Add(new GasRecordViewModel()
|
||||
{
|
||||
Id = result[i].Id,
|
||||
VehicleId = result[i].VehicleId,
|
||||
Date = result[i].Date.ToShortDateString(),
|
||||
Mileage = result[i].Mileage,
|
||||
Gallons = result[i].Gallons,
|
||||
Cost = result[i].Cost,
|
||||
Id = currentObject.Id,
|
||||
VehicleId = currentObject.VehicleId,
|
||||
Date = currentObject.Date.ToShortDateString(),
|
||||
Mileage = currentObject.Mileage,
|
||||
Gallons = convertedConsumption,
|
||||
Cost = currentObject.Cost,
|
||||
DeltaMileage = 0,
|
||||
MilesPerGallon = 0,
|
||||
CostPerGallon = (result[i].Cost / result[i].Gallons)
|
||||
CostPerGallon = (currentObject.Cost / currentObject.Gallons)
|
||||
});
|
||||
}
|
||||
previousMileage = result[i].Mileage;
|
||||
previousMileage = currentObject.Mileage;
|
||||
}
|
||||
if (_useDescending)
|
||||
{
|
||||
|
||||
@ -9,8 +9,8 @@ namespace CarCareTracker.MapProfile
|
||||
{
|
||||
Map(m => m.Date).Name(["date", "fuelup_date"]);
|
||||
Map(m => m.Odometer).Name(["odometer"]);
|
||||
Map(m => m.FuelConsumed).Name(["gallons", "liters", "litres"]);
|
||||
Map(m => m.Cost).Name(["cost", "total cost", "totalcost"]);
|
||||
Map(m => m.FuelConsumed).Name(["gallons", "liters", "litres", "consumption", "fuelconsumed"]);
|
||||
Map(m => m.Cost).Name(["cost", "total cost", "totalcost", "total price"]);
|
||||
Map(m => m.Notes).Name("notes", "note");
|
||||
Map(m => m.Price).Name(["price"]);
|
||||
Map(m => m.PartialFuelUp).Name(["partial_fuelup"]);
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
public bool UseDescending { get; set; }
|
||||
public bool EnableAuth { get; set; }
|
||||
public bool HideZero { get; set; }
|
||||
public bool UseUKMPG {get;set;}
|
||||
public string UserNameHash { get; set; }
|
||||
public string UserPasswordHash { get; set;}
|
||||
}
|
||||
|
||||
@ -18,6 +18,10 @@
|
||||
<input class="form-check-input" onChange="updateSettings()" type="checkbox" role="switch" id="useMPG" checked="@Model.UseMPG">
|
||||
<label class="form-check-label" for="useMPG">Use Imperial Calculation for Fuel Economy Calculations(MPG)<br /><small class="text-body-secondary">This Will Also Change Units to Miles and Gallons</small></label>
|
||||
</div>
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" onChange="updateSettings()" type="checkbox" role="switch" id="useUKMPG" checked="@Model.UseUKMPG">
|
||||
<label class="form-check-label" for="useUKMPG">Use UK MPG Calculation<br /><small class="text-body-secondary">Input Gas Consumption in Liters, it will be converted to UK Gals for MPG Calculation</small></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-md-6">
|
||||
<div class="form-check form-switch">
|
||||
@ -81,7 +85,8 @@
|
||||
enableCsvImports: $("#enableCsvImports").is(':checked'),
|
||||
useMPG: $("#useMPG").is(':checked'),
|
||||
useDescending: $("#useDescending").is(':checked'),
|
||||
hideZero: $("#hideZero").is(":checked")
|
||||
hideZero: $("#hideZero").is(":checked"),
|
||||
useUKMpg: $("#useUKMPG").is(":checked")
|
||||
}
|
||||
$.post('/Home/WriteToSettings', { userConfig: userConfigObject}, function(data){
|
||||
if (data) {
|
||||
|
||||
@ -3,19 +3,34 @@
|
||||
@{
|
||||
var enableCsvImports = bool.Parse(Configuration[nameof(UserConfig.EnableCsvImports)]);
|
||||
var useMPG = bool.Parse(Configuration[nameof(UserConfig.UseMPG)]);
|
||||
var useUKMPG = bool.Parse(Configuration[nameof(UserConfig.UseUKMPG)]);
|
||||
var hideZero = bool.Parse(Configuration[nameof(UserConfig.HideZero)]);
|
||||
var useKwh = Model.UseKwh;
|
||||
string consumptionUnit;
|
||||
string fuelEconomyUnit;
|
||||
string distanceUnit;
|
||||
if (useKwh)
|
||||
{
|
||||
consumptionUnit = "kWh";
|
||||
fuelEconomyUnit = useMPG ? "mi/kWh" : "kWh/100km";
|
||||
} else
|
||||
}
|
||||
else if (useMPG && useUKMPG)
|
||||
{
|
||||
consumptionUnit = useMPG ? "gal" : "l";
|
||||
consumptionUnit = "imp gal";
|
||||
fuelEconomyUnit = "mpg";
|
||||
}
|
||||
else
|
||||
{
|
||||
consumptionUnit = useMPG ? "US gal" : "l";
|
||||
fuelEconomyUnit = useMPG ? "mpg" : "l/100km";
|
||||
}
|
||||
if (useUKMPG)
|
||||
{
|
||||
distanceUnit = "mi.";
|
||||
} else {
|
||||
distanceUnit = useMPG ? "mi" : "km";
|
||||
}
|
||||
|
||||
}
|
||||
<div class="row">
|
||||
<div class="d-flex justify-content-between">
|
||||
@ -52,7 +67,7 @@
|
||||
<thead>
|
||||
<tr class="d-flex">
|
||||
<th scope="col" class="col-2">Date Refueled</th>
|
||||
<th scope="col" class="col-2">Odometer(@(useMPG ? "mi." : "km"))</th>
|
||||
<th scope="col" class="col-2">Odometer(@distanceUnit)</th>
|
||||
<th scope="col" class="col-2">Consumption(@(consumptionUnit))</th>
|
||||
<th scope="col" class="col-4">Fuel Economy(@(fuelEconomyUnit))</th>
|
||||
<th scope="col" class="col-1">Cost</th>
|
||||
|
||||
@ -2,17 +2,30 @@
|
||||
@model GasRecordInputContainer
|
||||
@{
|
||||
var useMPG = bool.Parse(Configuration[nameof(UserConfig.UseMPG)]);
|
||||
var useUKMPG = bool.Parse(Configuration[nameof(UserConfig.UseUKMPG)]);
|
||||
var useKwh = Model.UseKwh;
|
||||
var isNew = Model.GasRecord.Id == 0;
|
||||
string consumptionUnit;
|
||||
string distanceUnit;
|
||||
if (useKwh)
|
||||
{
|
||||
consumptionUnit = "kWh";
|
||||
} else if (useUKMPG)
|
||||
{
|
||||
consumptionUnit = "liters";
|
||||
}
|
||||
else
|
||||
{
|
||||
consumptionUnit = useMPG ? "gallons" : "liters";
|
||||
}
|
||||
if (useUKMPG)
|
||||
{
|
||||
distanceUnit = "miles";
|
||||
}
|
||||
else
|
||||
{
|
||||
distanceUnit = useMPG ? "miles" : "kilometers";
|
||||
}
|
||||
}
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">@(isNew ? "Add New Gas Record" : "Edit Gas Record")</h5>
|
||||
@ -29,7 +42,7 @@
|
||||
<input type="text" id="gasRecordDate" placeholder="Date refueled" class="form-control" value="@Model.GasRecord.Date">
|
||||
<span class="input-group-text"><i class="bi bi-calendar-event"></i></span>
|
||||
</div>
|
||||
<label for="gasRecordMileage">Odometer Reading(@(useMPG ? "miles" : "kilometers"))</label>
|
||||
<label for="gasRecordMileage">Odometer Reading(@distanceUnit)</label>
|
||||
<input type="number" id="gasRecordMileage" class="form-control" placeholder="Odometer reading when refueled" value="@(isNew ? "" : Model.GasRecord.Mileage)">
|
||||
<label for="gasRecordGallons">Fuel Consumption(@(consumptionUnit))</label>
|
||||
<input type="text" id="gasRecordGallons" class="form-control" placeholder="Amount of gas refueled" value="@(isNew ? "" : Model.GasRecord.Gallons)">
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
"UseDescending": false,
|
||||
"EnableAuth": false,
|
||||
"HideZero": false,
|
||||
"UseUKMPG": false,
|
||||
"UserNameHash": "",
|
||||
"UserPasswordHash": ""
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user