@@ -589,7 +589,8 @@ namespace CarCareTracker.Controllers
|
||||
Gallons = result.Gallons,
|
||||
IsFillToFull = result.IsFillToFull,
|
||||
MissedFuelUp = result.MissedFuelUp,
|
||||
Notes = result.Notes
|
||||
Notes = result.Notes,
|
||||
Tags = result.Tags
|
||||
};
|
||||
var vehicleData = _dataAccess.GetVehicleById(convertedResult.VehicleId);
|
||||
var vehicleIsElectric = vehicleData.IsElectric;
|
||||
|
||||
@@ -11,16 +11,12 @@ namespace CarCareTracker.Helper
|
||||
{
|
||||
public string GetAverageGasMileage(List<GasRecordViewModel> results, bool useMPG)
|
||||
{
|
||||
var recordsToCalculateGallons = results.Where(x => x.MilesPerGallon > 0 || !x.IsFillToFull);
|
||||
var recordWithCalculatedMPG = recordsToCalculateGallons.Where(x => x.MilesPerGallon > 0);
|
||||
var mileageAdjustment = results.Where(x => x.MissedFuelUp).Sum(y => y.DeltaMileage);
|
||||
if (recordWithCalculatedMPG.Any())
|
||||
var recordsToCalculate = results.Where(x => x.IncludeInAverage);
|
||||
if (recordsToCalculate.Any())
|
||||
{
|
||||
var maxMileage = recordWithCalculatedMPG.Max(x => x.Mileage);
|
||||
var minMileage = recordWithCalculatedMPG.Min(x => x.Mileage);
|
||||
var totalGallonsConsumed = recordsToCalculateGallons.Sum(x => x.Gallons);
|
||||
var deltaMileage = maxMileage - minMileage - mileageAdjustment;
|
||||
var averageGasMileage = (deltaMileage) / totalGallonsConsumed;
|
||||
var totalMileage = recordsToCalculate.Sum(x => x.DeltaMileage);
|
||||
var totalGallons = recordsToCalculate.Sum(x => x.Gallons);
|
||||
var averageGasMileage = totalMileage / totalGallons;
|
||||
if (!useMPG)
|
||||
{
|
||||
averageGasMileage = 100 / averageGasMileage;
|
||||
@@ -68,7 +64,8 @@ namespace CarCareTracker.Helper
|
||||
CostPerGallon = convertedConsumption > 0.00M ? currentObject.Cost / convertedConsumption : 0,
|
||||
IsFillToFull = currentObject.IsFillToFull,
|
||||
MissedFuelUp = currentObject.MissedFuelUp,
|
||||
Notes = currentObject.Notes
|
||||
Notes = currentObject.Notes,
|
||||
Tags = currentObject.Tags
|
||||
};
|
||||
if (currentObject.MissedFuelUp)
|
||||
{
|
||||
@@ -120,7 +117,8 @@ namespace CarCareTracker.Helper
|
||||
CostPerGallon = convertedConsumption > 0.00M ? currentObject.Cost / convertedConsumption : 0,
|
||||
IsFillToFull = currentObject.IsFillToFull,
|
||||
MissedFuelUp = currentObject.MissedFuelUp,
|
||||
Notes = currentObject.Notes
|
||||
Notes = currentObject.Notes,
|
||||
Tags = currentObject.Tags
|
||||
});
|
||||
}
|
||||
previousMileage = currentObject.Mileage;
|
||||
|
||||
@@ -18,5 +18,6 @@
|
||||
public bool MissedFuelUp { get; set; } = false;
|
||||
public string Notes { get; set; }
|
||||
public List<UploadedFiles> Files { get; set; } = new List<UploadedFiles>();
|
||||
public List<string> Tags { get; set; } = new List<string>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
public bool MissedFuelUp { get; set; } = false;
|
||||
public string Notes { get; set; }
|
||||
public List<UploadedFiles> Files { get; set; } = new List<UploadedFiles>();
|
||||
public List<string> Tags { get; set; } = new List<string>();
|
||||
public GasRecord ToGasRecord() { return new GasRecord {
|
||||
Id = Id,
|
||||
Cost = Cost,
|
||||
@@ -28,7 +29,8 @@
|
||||
Files = Files,
|
||||
IsFillToFull = IsFillToFull,
|
||||
MissedFuelUp = MissedFuelUp,
|
||||
Notes = Notes
|
||||
Notes = Notes,
|
||||
Tags = Tags
|
||||
}; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,5 +21,7 @@
|
||||
public bool IsFillToFull { get; set; }
|
||||
public bool MissedFuelUp { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public List<string> Tags { get; set; } = new List<string>();
|
||||
public bool IncludeInAverage { get { return MilesPerGallon > 0 || (!IsFillToFull && !MissedFuelUp); } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
var userConfig = config.GetUserConfig(User);
|
||||
var useDarkMode = userConfig.UseDarkMode;
|
||||
var enableCsvImports = userConfig.EnableCsvImports;
|
||||
var useMPG = userConfig.UseMPG;
|
||||
var useMarkDown = userConfig.UseMarkDownOnSavedNotes;
|
||||
var useThreeDecimals = userConfig.UseThreeDecimalGasCost;
|
||||
var shortDatePattern = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
|
||||
@@ -54,7 +55,8 @@
|
||||
enableCsvImport : "@enableCsvImports" == "True",
|
||||
useMarkDown: "@useMarkDown" == "True",
|
||||
currencySymbol: decodeHTMLEntities("@numberFormat.CurrencySymbol"),
|
||||
useThreeDecimals: "@useThreeDecimals" == "True"
|
||||
useThreeDecimals: "@useThreeDecimals" == "True",
|
||||
useMPG: "@useMPG" == "True"
|
||||
}
|
||||
}
|
||||
function getShortDatePattern() {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
var gasCostFormat = useThreeDecimals ? "C3" : "C2";
|
||||
var useKwh = Model.UseKwh;
|
||||
var useHours = Model.UseHours;
|
||||
var recordTags = Model.GasRecords.SelectMany(x => x.Tags).Distinct();
|
||||
string preferredFuelEconomyUnit = userConfig.PreferredGasMileageUnit;
|
||||
string preferredGasUnit = userConfig.PreferredGasUnit;
|
||||
string consumptionUnit;
|
||||
@@ -41,7 +42,7 @@
|
||||
<div class="row">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="d-flex align-items-center flex-wrap">
|
||||
<span class="ms-2 badge bg-success">@($"# of Gas Records: {Model.GasRecords.Count()}")</span>
|
||||
<span class="ms-2 badge bg-success" data-aggregate-type="count">@($"# of Gas Records: {Model.GasRecords.Count()}")</span>
|
||||
@if (Model.GasRecords.Where(x => x.MilesPerGallon > 0).Any())
|
||||
{
|
||||
<span class="ms-2 badge bg-primary" id="averageFuelMileageLabel">@($"Average Fuel Economy: {gasHelper.GetAverageGasMileage(Model.GasRecords, useMPG)}")</span>
|
||||
@@ -56,7 +57,17 @@
|
||||
}
|
||||
}
|
||||
<span class="ms-2 badge bg-success">@($"Total Fuel Consumed: {Model.GasRecords.Sum(x => x.Gallons).ToString("F")}")</span>
|
||||
<span class="ms-2 badge bg-success">@($"Total Cost: {Model.GasRecords.Sum(x => x.Cost).ToString(gasCostFormat)}")</span>
|
||||
<span class="ms-2 badge bg-success" data-aggregate-type="sum">@($"Total Cost: {Model.GasRecords.Sum(x => x.Cost).ToString(gasCostFormat)}")</span>
|
||||
@foreach (string recordTag in recordTags)
|
||||
{
|
||||
<span onclick="toggleGasFilter(this)" class="user-select-none ms-2 rounded-pill badge bg-secondary tagfilter" style="cursor:pointer;">@recordTag</span>
|
||||
}
|
||||
<datalist id="tagList">
|
||||
@foreach (string recordTag in recordTags)
|
||||
{
|
||||
<!option value="@recordTag"></!option>
|
||||
}
|
||||
</datalist>
|
||||
</div>
|
||||
@if (enableCsvImports)
|
||||
{
|
||||
@@ -98,12 +109,12 @@
|
||||
<tbody>
|
||||
@foreach (GasRecordViewModel gasRecord in Model.GasRecords)
|
||||
{
|
||||
<tr class="d-flex" style="cursor:pointer;" onclick="showEditGasRecordModal(@gasRecord.Id)">
|
||||
<tr class="d-flex" style="cursor:pointer;" onclick="showEditGasRecordModal(@gasRecord.Id)" data-tags='@string.Join(" ", gasRecord.Tags)'>
|
||||
<td class="col-2">@gasRecord.Date</td>
|
||||
<td class="col-2">@gasRecord.Mileage</td>
|
||||
<td class="col-2" data-gas-type="consumption">@gasRecord.Gallons.ToString("F")</td>
|
||||
<td class="col-4" data-gas-type="fueleconomy">@(gasRecord.MilesPerGallon == 0 ? "---" : gasRecord.MilesPerGallon.ToString("F"))</td>
|
||||
<td class="col-1">@((hideZero && gasRecord.Cost == default) ? "---" : gasRecord.Cost.ToString(gasCostFormat))</td>
|
||||
<td class="col-2" data-gas-type="mileage" data-gas-aggregate="@gasRecord.DeltaMileage">@gasRecord.Mileage</td>
|
||||
<td class="col-2" data-gas-type="consumption" data-gas-aggregate="@gasRecord.Gallons">@gasRecord.Gallons.ToString("F")</td>
|
||||
<td class="col-4" data-gas-type="fueleconomy" data-aggregated='@(gasRecord.IncludeInAverage.ToString().ToLower())'>@(gasRecord.MilesPerGallon == 0 ? "---" : gasRecord.MilesPerGallon.ToString("F"))</td>
|
||||
<td class="col-1" data-record-type="cost">@((hideZero && gasRecord.Cost == default) ? "---" : gasRecord.Cost.ToString(gasCostFormat))</td>
|
||||
<td class="col-1" data-gas-type="unitcost">@((hideZero && gasRecord.CostPerGallon == default) ? "---" : gasRecord.CostPerGallon.ToString(gasCostFormat))</td>
|
||||
</tr>
|
||||
}
|
||||
@@ -130,4 +141,5 @@
|
||||
{
|
||||
@:convertGasConsumptionUnits(decodeHTMLEntities('@consumptionUnit'), decodeHTMLEntities('@preferredGasUnit'), false);
|
||||
}
|
||||
|
||||
</script>
|
||||
@@ -76,6 +76,13 @@
|
||||
{
|
||||
<input type="text" id="gasRecordCost" class="form-control" placeholder="Cost of gas refueled" value="@(isNew ? "" : Model.GasRecord.Cost)">
|
||||
}
|
||||
<label for="gasRecordTag">Tags(optional)</label>
|
||||
<select multiple class="form-select" id="gasRecordTag">
|
||||
@foreach (string tag in Model.GasRecord.Tags)
|
||||
{
|
||||
<!option value="@tag">@tag</!option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6 col-12">
|
||||
<label for="gasRecordNotes">Notes(optional)<a class="link-underline link-underline-opacity-0" onclick="showLinks(this)"><i class="bi bi-markdown ms-2"></i></a></label>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
$("#gasRecordModalContent").html(data);
|
||||
//initiate datepicker
|
||||
initDatePicker($('#gasRecordDate'));
|
||||
initTagSelector($("#gasRecordTag"));
|
||||
$('#gasRecordModal').modal('show');
|
||||
}
|
||||
});
|
||||
@@ -14,6 +15,7 @@ function showEditGasRecordModal(gasRecordId) {
|
||||
$("#gasRecordModalContent").html(data);
|
||||
//initiate datepicker
|
||||
initDatePicker($('#gasRecordDate'));
|
||||
initTagSelector($("#gasRecordTag"));
|
||||
$('#gasRecordModal').modal('show');
|
||||
$('#gasRecordModal').off('shown.bs.modal').on('shown.bs.modal', function () {
|
||||
if (getGlobalConfig().useMarkDown) {
|
||||
@@ -80,6 +82,7 @@ function getAndValidateGasRecordValues() {
|
||||
var gasIsFillToFull = $("#gasIsFillToFull").is(":checked");
|
||||
var gasIsMissed = $("#gasIsMissed").is(":checked");
|
||||
var gasNotes = $("#gasRecordNotes").val();
|
||||
var gasTags = $("#gasRecordTag").val();
|
||||
var vehicleId = GetVehicleId().vehicleId;
|
||||
var gasRecordId = getGasRecordModelData().id;
|
||||
//validation
|
||||
@@ -90,7 +93,7 @@ function getAndValidateGasRecordValues() {
|
||||
} else {
|
||||
$("#gasRecordDate").removeClass("is-invalid");
|
||||
}
|
||||
if (gasMileage.trim() == '' || parseInt(gasMileage) < 0) {
|
||||
if (gasMileage.trim() == '' || isNaN(gasMileage) || parseInt(gasMileage) < 0) {
|
||||
hasError = true;
|
||||
$("#gasRecordMileage").addClass("is-invalid");
|
||||
} else {
|
||||
@@ -128,6 +131,7 @@ function getAndValidateGasRecordValues() {
|
||||
gallons: gasGallons,
|
||||
cost: gasCost,
|
||||
files: uploadedFiles,
|
||||
tags: gasTags,
|
||||
isFillToFull: gasIsFillToFull,
|
||||
missedFuelUp: gasIsMissed,
|
||||
notes: gasNotes
|
||||
@@ -257,17 +261,20 @@ function convertFuelMileageUnits(currentUnit, destinationUnit, save) {
|
||||
var newAverage = globalParseFloat($("#averageFuelMileageLabel").text().replace("Average Fuel Economy: ", ""));
|
||||
if (newAverage > 0) {
|
||||
newAverage = 100 / newAverage;
|
||||
$("#averageFuelMileageLabel").text(`Average Fuel Economy: ${newAverage.toFixed(2)}`)
|
||||
var averageLabel = $("#averageFuelMileageLabel");
|
||||
averageLabel.text(`${averageLabel.text().split(':')[0]}: ${newAverage.toFixed(2)}`);
|
||||
}
|
||||
var newMin = globalParseFloat($("#minFuelMileageLabel").text().replace("Min Fuel Economy: ", ""));
|
||||
if (newMin > 0) {
|
||||
newMin = 100 / newMin;
|
||||
$("#minFuelMileageLabel").text(`Min Fuel Economy: ${newMin.toFixed(2)}`)
|
||||
var minLabel = $("#minFuelMileageLabel");
|
||||
minLabel.text(`${minLabel.text().split(':')[0]}: ${newMin.toFixed(2)}`);
|
||||
}
|
||||
var newMax = globalParseFloat($("#maxFuelMileageLabel").text().replace("Max Fuel Economy: ", ""));
|
||||
if (newMax > 0) {
|
||||
newMax = 100 / newMax;
|
||||
$("#maxFuelMileageLabel").text(`Max Fuel Economy: ${newMax.toFixed(2)}`)
|
||||
var maxLabel = $("#maxFuelMileageLabel");
|
||||
maxLabel.text(`${maxLabel.text().split(':')[0]}: ${newMax.toFixed(2)}`);
|
||||
}
|
||||
sender.text(sender.text().replace(sender.attr("data-unit"), "km/l"));
|
||||
sender.attr("data-unit", "km/l");
|
||||
@@ -287,17 +294,20 @@ function convertFuelMileageUnits(currentUnit, destinationUnit, save) {
|
||||
var newAverage = globalParseFloat($("#averageFuelMileageLabel").text().replace("Average Fuel Economy: ", ""));
|
||||
if (newAverage > 0) {
|
||||
newAverage = 100 / newAverage;
|
||||
$("#averageFuelMileageLabel").text(`Average Fuel Economy: ${newAverage.toFixed(2)}`)
|
||||
var averageLabel = $("#averageFuelMileageLabel");
|
||||
averageLabel.text(`${averageLabel.text().split(':')[0]}: ${newAverage.toFixed(2)}`);
|
||||
}
|
||||
var newMin = globalParseFloat($("#minFuelMileageLabel").text().replace("Min Fuel Economy: ", ""));
|
||||
if (newMin > 0) {
|
||||
newMin = 100 / newMin;
|
||||
$("#minFuelMileageLabel").text(`Min Fuel Economy: ${newMin.toFixed(2)}`)
|
||||
var minLabel = $("#minFuelMileageLabel");
|
||||
minLabel.text(`${minLabel.text().split(':')[0]}: ${newMin.toFixed(2)}`);
|
||||
}
|
||||
var newMax = globalParseFloat($("#maxFuelMileageLabel").text().replace("Max Fuel Economy: ", ""));
|
||||
if (newMax > 0) {
|
||||
newMax = 100 / newMax;
|
||||
$("#maxFuelMileageLabel").text(`Max Fuel Economy: ${newMax.toFixed(2)}`)
|
||||
var maxLabel = $("#maxFuelMileageLabel");
|
||||
maxLabel.text(`${maxLabel.text().split(':')[0]}: ${newMax.toFixed(2)}`);
|
||||
}
|
||||
sender.text(sender.text().replace(sender.attr("data-unit"), "l/100km"));
|
||||
sender.attr("data-unit", "l/100km");
|
||||
@@ -307,6 +317,34 @@ function convertFuelMileageUnits(currentUnit, destinationUnit, save) {
|
||||
}
|
||||
}
|
||||
}
|
||||
function toggleGasFilter(sender) {
|
||||
filterTable('gas-tab-pane', sender);
|
||||
updateMPGLabels();
|
||||
}
|
||||
function updateMPGLabels() {
|
||||
var averageLabel = $("#averageFuelMileageLabel");
|
||||
var minLabel = $("#minFuelMileageLabel");
|
||||
var maxLabel = $("#maxFuelMileageLabel");
|
||||
if (averageLabel.length > 0 && minLabel.length > 0 && maxLabel.length > 0) {
|
||||
var rowsToAggregate = $("[data-aggregated='true']").parent(":not('.override-hide')");
|
||||
var rowMPG = rowsToAggregate.children('[data-gas-type="fueleconomy"]').toArray().map(x => globalParseFloat(x.textContent));
|
||||
var maxMPG = rowMPG.length > 0 ? rowMPG.reduce((a, b) => a > b ? a : b) : 0;
|
||||
var minMPG = rowMPG.length > 0 ? rowMPG.filter(x=>x>0).reduce((a, b) => a < b ? a : b) : 0;
|
||||
var totalMilesTraveled = rowMPG.length > 0 ? rowsToAggregate.children('[data-gas-type="mileage"]').toArray().map(x => globalParseFloat($(x).attr("data-gas-aggregate"))).reduce((a, b) => a + b) : 0;
|
||||
var totalGasConsumed = rowMPG.length > 0 ? rowsToAggregate.children('[data-gas-type="consumption"]').toArray().map(x => globalParseFloat($(x).attr("data-gas-aggregate"))).reduce((a, b) => a + b) : 0;
|
||||
if (totalGasConsumed > 0) {
|
||||
var averageMPG = totalMilesTraveled / totalGasConsumed;
|
||||
if (!getGlobalConfig().useMPG && $("[data-gas='fueleconomy']").attr("data-unit") != 'km/l' && averageMPG > 0) {
|
||||
averageMPG = 100 / averageMPG;
|
||||
}
|
||||
averageLabel.text(`${averageLabel.text().split(':')[0]}: ${averageMPG.toFixed(2)}`);
|
||||
} else {
|
||||
averageLabel.text(`${averageLabel.text().split(':')[0]}: 0.00`);
|
||||
}
|
||||
minLabel.text(`${minLabel.text().split(':')[0]}: ${minMPG.toFixed(2)}`);
|
||||
maxLabel.text(`${maxLabel.text().split(':')[0]}: ${maxMPG.toFixed(2)}`);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleUnits(sender) {
|
||||
event.preventDefault();
|
||||
|
||||
Reference in New Issue
Block a user