added support for UK MPG
This commit is contained in:
@@ -46,7 +46,8 @@ namespace CarCareTracker.Controllers
|
|||||||
UseMPG = bool.Parse(_config[nameof(UserConfig.UseMPG)]),
|
UseMPG = bool.Parse(_config[nameof(UserConfig.UseMPG)]),
|
||||||
UseDescending = bool.Parse(_config[nameof(UserConfig.UseDescending)]),
|
UseDescending = bool.Parse(_config[nameof(UserConfig.UseDescending)]),
|
||||||
EnableAuth = bool.Parse(_config[nameof(UserConfig.EnableAuth)]),
|
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);
|
return PartialView("_Settings", userConfig);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -250,6 +250,7 @@ namespace CarCareTracker.Controllers
|
|||||||
result = result.OrderBy(x => x.Date).ThenBy(x => x.Mileage).ToList();
|
result = result.OrderBy(x => x.Date).ThenBy(x => x.Mileage).ToList();
|
||||||
//check if the user uses MPG or Liters per 100km.
|
//check if the user uses MPG or Liters per 100km.
|
||||||
bool useMPG = bool.Parse(_config[nameof(UserConfig.UseMPG)]);
|
bool useMPG = bool.Parse(_config[nameof(UserConfig.UseMPG)]);
|
||||||
|
bool useUKMPG = bool.Parse(_config[nameof(UserConfig.UseUKMPG)]);
|
||||||
var computedResults = new List<GasRecordViewModel>();
|
var computedResults = new List<GasRecordViewModel>();
|
||||||
int previousMileage = 0;
|
int previousMileage = 0;
|
||||||
decimal unFactoredConsumption = 0.00M;
|
decimal unFactoredConsumption = 0.00M;
|
||||||
@@ -257,9 +258,19 @@ namespace CarCareTracker.Controllers
|
|||||||
//perform computation.
|
//perform computation.
|
||||||
for (int i = 0; i < result.Count; i++)
|
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)
|
if (i > 0)
|
||||||
{
|
{
|
||||||
var currentObject = result[i];
|
|
||||||
var deltaMileage = currentObject.Mileage - previousMileage;
|
var deltaMileage = currentObject.Mileage - previousMileage;
|
||||||
var gasRecordViewModel = new GasRecordViewModel()
|
var gasRecordViewModel = new GasRecordViewModel()
|
||||||
{
|
{
|
||||||
@@ -267,22 +278,22 @@ namespace CarCareTracker.Controllers
|
|||||||
VehicleId = currentObject.VehicleId,
|
VehicleId = currentObject.VehicleId,
|
||||||
Date = currentObject.Date.ToShortDateString(),
|
Date = currentObject.Date.ToShortDateString(),
|
||||||
Mileage = currentObject.Mileage,
|
Mileage = currentObject.Mileage,
|
||||||
Gallons = currentObject.Gallons,
|
Gallons = convertedConsumption,
|
||||||
Cost = currentObject.Cost,
|
Cost = currentObject.Cost,
|
||||||
DeltaMileage = deltaMileage,
|
DeltaMileage = deltaMileage,
|
||||||
CostPerGallon = (currentObject.Cost / currentObject.Gallons)
|
CostPerGallon = (currentObject.Cost / convertedConsumption)
|
||||||
};
|
};
|
||||||
if (currentObject.IsFillToFull)
|
if (currentObject.IsFillToFull)
|
||||||
{
|
{
|
||||||
//if user filled to full.
|
//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
|
//reset unFactored vars
|
||||||
unFactoredConsumption = 0;
|
unFactoredConsumption = 0;
|
||||||
unFactoredMileage = 0;
|
unFactoredMileage = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unFactoredConsumption += currentObject.Gallons;
|
unFactoredConsumption += convertedConsumption;
|
||||||
unFactoredMileage += deltaMileage;
|
unFactoredMileage += deltaMileage;
|
||||||
gasRecordViewModel.MilesPerGallon = 0;
|
gasRecordViewModel.MilesPerGallon = 0;
|
||||||
}
|
}
|
||||||
@@ -292,18 +303,18 @@ namespace CarCareTracker.Controllers
|
|||||||
{
|
{
|
||||||
computedResults.Add(new GasRecordViewModel()
|
computedResults.Add(new GasRecordViewModel()
|
||||||
{
|
{
|
||||||
Id = result[i].Id,
|
Id = currentObject.Id,
|
||||||
VehicleId = result[i].VehicleId,
|
VehicleId = currentObject.VehicleId,
|
||||||
Date = result[i].Date.ToShortDateString(),
|
Date = currentObject.Date.ToShortDateString(),
|
||||||
Mileage = result[i].Mileage,
|
Mileage = currentObject.Mileage,
|
||||||
Gallons = result[i].Gallons,
|
Gallons = convertedConsumption,
|
||||||
Cost = result[i].Cost,
|
Cost = currentObject.Cost,
|
||||||
DeltaMileage = 0,
|
DeltaMileage = 0,
|
||||||
MilesPerGallon = 0,
|
MilesPerGallon = 0,
|
||||||
CostPerGallon = (result[i].Cost / result[i].Gallons)
|
CostPerGallon = (currentObject.Cost / currentObject.Gallons)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
previousMileage = result[i].Mileage;
|
previousMileage = currentObject.Mileage;
|
||||||
}
|
}
|
||||||
if (_useDescending)
|
if (_useDescending)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ namespace CarCareTracker.MapProfile
|
|||||||
{
|
{
|
||||||
Map(m => m.Date).Name(["date", "fuelup_date"]);
|
Map(m => m.Date).Name(["date", "fuelup_date"]);
|
||||||
Map(m => m.Odometer).Name(["odometer"]);
|
Map(m => m.Odometer).Name(["odometer"]);
|
||||||
Map(m => m.FuelConsumed).Name(["gallons", "liters", "litres"]);
|
Map(m => m.FuelConsumed).Name(["gallons", "liters", "litres", "consumption", "fuelconsumed"]);
|
||||||
Map(m => m.Cost).Name(["cost", "total cost", "totalcost"]);
|
Map(m => m.Cost).Name(["cost", "total cost", "totalcost", "total price"]);
|
||||||
Map(m => m.Notes).Name("notes", "note");
|
Map(m => m.Notes).Name("notes", "note");
|
||||||
Map(m => m.Price).Name(["price"]);
|
Map(m => m.Price).Name(["price"]);
|
||||||
Map(m => m.PartialFuelUp).Name(["partial_fuelup"]);
|
Map(m => m.PartialFuelUp).Name(["partial_fuelup"]);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
public bool UseDescending { get; set; }
|
public bool UseDescending { get; set; }
|
||||||
public bool EnableAuth { get; set; }
|
public bool EnableAuth { get; set; }
|
||||||
public bool HideZero { get; set; }
|
public bool HideZero { get; set; }
|
||||||
|
public bool UseUKMPG {get;set;}
|
||||||
public string UserNameHash { get; set; }
|
public string UserNameHash { get; set; }
|
||||||
public string UserPasswordHash { 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">
|
<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>
|
<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>
|
||||||
|
<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>
|
||||||
<div class="col-12 col-md-6">
|
<div class="col-12 col-md-6">
|
||||||
<div class="form-check form-switch">
|
<div class="form-check form-switch">
|
||||||
@@ -81,7 +85,8 @@
|
|||||||
enableCsvImports: $("#enableCsvImports").is(':checked'),
|
enableCsvImports: $("#enableCsvImports").is(':checked'),
|
||||||
useMPG: $("#useMPG").is(':checked'),
|
useMPG: $("#useMPG").is(':checked'),
|
||||||
useDescending: $("#useDescending").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){
|
$.post('/Home/WriteToSettings', { userConfig: userConfigObject}, function(data){
|
||||||
if (data) {
|
if (data) {
|
||||||
|
|||||||
@@ -3,19 +3,34 @@
|
|||||||
@{
|
@{
|
||||||
var enableCsvImports = bool.Parse(Configuration[nameof(UserConfig.EnableCsvImports)]);
|
var enableCsvImports = bool.Parse(Configuration[nameof(UserConfig.EnableCsvImports)]);
|
||||||
var useMPG = bool.Parse(Configuration[nameof(UserConfig.UseMPG)]);
|
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 hideZero = bool.Parse(Configuration[nameof(UserConfig.HideZero)]);
|
||||||
var useKwh = Model.UseKwh;
|
var useKwh = Model.UseKwh;
|
||||||
string consumptionUnit;
|
string consumptionUnit;
|
||||||
string fuelEconomyUnit;
|
string fuelEconomyUnit;
|
||||||
|
string distanceUnit;
|
||||||
if (useKwh)
|
if (useKwh)
|
||||||
{
|
{
|
||||||
consumptionUnit = "kWh";
|
consumptionUnit = "kWh";
|
||||||
fuelEconomyUnit = useMPG ? "mi/kWh" : "kWh/100km";
|
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";
|
fuelEconomyUnit = useMPG ? "mpg" : "l/100km";
|
||||||
}
|
}
|
||||||
|
if (useUKMPG)
|
||||||
|
{
|
||||||
|
distanceUnit = "mi.";
|
||||||
|
} else {
|
||||||
|
distanceUnit = useMPG ? "mi" : "km";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="d-flex justify-content-between">
|
<div class="d-flex justify-content-between">
|
||||||
@@ -52,7 +67,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr class="d-flex">
|
<tr class="d-flex">
|
||||||
<th scope="col" class="col-2">Date Refueled</th>
|
<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-2">Consumption(@(consumptionUnit))</th>
|
||||||
<th scope="col" class="col-4">Fuel Economy(@(fuelEconomyUnit))</th>
|
<th scope="col" class="col-4">Fuel Economy(@(fuelEconomyUnit))</th>
|
||||||
<th scope="col" class="col-1">Cost</th>
|
<th scope="col" class="col-1">Cost</th>
|
||||||
|
|||||||
@@ -2,17 +2,30 @@
|
|||||||
@model GasRecordInputContainer
|
@model GasRecordInputContainer
|
||||||
@{
|
@{
|
||||||
var useMPG = bool.Parse(Configuration[nameof(UserConfig.UseMPG)]);
|
var useMPG = bool.Parse(Configuration[nameof(UserConfig.UseMPG)]);
|
||||||
|
var useUKMPG = bool.Parse(Configuration[nameof(UserConfig.UseUKMPG)]);
|
||||||
var useKwh = Model.UseKwh;
|
var useKwh = Model.UseKwh;
|
||||||
var isNew = Model.GasRecord.Id == 0;
|
var isNew = Model.GasRecord.Id == 0;
|
||||||
string consumptionUnit;
|
string consumptionUnit;
|
||||||
|
string distanceUnit;
|
||||||
if (useKwh)
|
if (useKwh)
|
||||||
{
|
{
|
||||||
consumptionUnit = "kWh";
|
consumptionUnit = "kWh";
|
||||||
|
} else if (useUKMPG)
|
||||||
|
{
|
||||||
|
consumptionUnit = "liters";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
consumptionUnit = useMPG ? "gallons" : "liters";
|
consumptionUnit = useMPG ? "gallons" : "liters";
|
||||||
}
|
}
|
||||||
|
if (useUKMPG)
|
||||||
|
{
|
||||||
|
distanceUnit = "miles";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
distanceUnit = useMPG ? "miles" : "kilometers";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h5 class="modal-title">@(isNew ? "Add New Gas Record" : "Edit Gas Record")</h5>
|
<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">
|
<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>
|
<span class="input-group-text"><i class="bi bi-calendar-event"></i></span>
|
||||||
</div>
|
</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)">
|
<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>
|
<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)">
|
<input type="text" id="gasRecordGallons" class="form-control" placeholder="Amount of gas refueled" value="@(isNew ? "" : Model.GasRecord.Gallons)">
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
"UseDescending": false,
|
"UseDescending": false,
|
||||||
"EnableAuth": false,
|
"EnableAuth": false,
|
||||||
"HideZero": false,
|
"HideZero": false,
|
||||||
|
"UseUKMPG": false,
|
||||||
"UserNameHash": "",
|
"UserNameHash": "",
|
||||||
"UserPasswordHash": ""
|
"UserPasswordHash": ""
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user