Missed fillups
This commit is contained in:
parent
e4818a2c2f
commit
00d6d89fcb
|
@ -23,9 +23,9 @@ struct AddFuelLogView: View {
|
|||
@State private var locationName = ""
|
||||
@State private var selectedOctane: Int = 87 // Default or from previous record
|
||||
@State private var pricePerGalon = ""
|
||||
// New Full Tank toggle; default is on (true)
|
||||
@State private var fullTank: Bool = true
|
||||
|
||||
@State private var missedPrevious: Bool = false
|
||||
|
||||
// Allowed octane options
|
||||
let octaneOptions = [87, 89, 91, 92, 93, 95]
|
||||
|
||||
|
@ -115,6 +115,9 @@ struct AddFuelLogView: View {
|
|||
Toggle("Full Tank", isOn: $fullTank)
|
||||
.toggleStyle(SwitchToggleStyle(tint: .blue))
|
||||
|
||||
Toggle("Missed Previous Fill-up", isOn: $missedPrevious)
|
||||
.toggleStyle(SwitchToggleStyle(tint: .blue))
|
||||
|
||||
Button("Get Current Location") {
|
||||
locationManager.requestLocation()
|
||||
}
|
||||
|
@ -255,8 +258,8 @@ struct AddFuelLogView: View {
|
|||
newLog.locationName = locationName
|
||||
newLog.octane = Int16(selectedOctane)
|
||||
newLog.pricePerGalon = Double(pricePerGalon) ?? 0
|
||||
// Set the fullTank property from the toggle:
|
||||
newLog.fullTank = fullTank
|
||||
newLog.missedPrevious = missedPrevious
|
||||
|
||||
if let vehicleID = selectedVehicleID,
|
||||
let selectedVehicle = vehicles.first(where: { $0.id == vehicleID }) {
|
||||
|
|
|
@ -24,8 +24,8 @@ struct EditFuelLogView: View {
|
|||
@State private var locationName = ""
|
||||
@State private var selectedOctane: Int = 87
|
||||
@State private var pricePerGalon = ""
|
||||
// Full Tank toggle
|
||||
@State private var fullTank: Bool = true
|
||||
@State private var missedPrevious: Bool = false
|
||||
|
||||
// Allowed octane options
|
||||
let octaneOptions = [87, 89, 91, 92, 93, 95]
|
||||
|
@ -89,6 +89,9 @@ struct EditFuelLogView: View {
|
|||
Toggle("Full Tank", isOn: $fullTank)
|
||||
.toggleStyle(SwitchToggleStyle(tint: .blue))
|
||||
|
||||
Toggle("Missed Previous Fill-up", isOn: $missedPrevious)
|
||||
.toggleStyle(SwitchToggleStyle(tint: .blue))
|
||||
|
||||
Button("Get Current Location") {
|
||||
// Optionally trigger location update
|
||||
}
|
||||
|
@ -130,6 +133,7 @@ struct EditFuelLogView: View {
|
|||
cost = String(format: "%.2f", fuelLog.cost)
|
||||
pricePerGalon = String(format: "%.3f", fuelLog.pricePerGalon)
|
||||
fullTank = fuelLog.fullTank
|
||||
missedPrevious = fuelLog.missedPrevious
|
||||
locationCoordinates = fuelLog.locationCoordinates ?? ""
|
||||
locationName = fuelLog.locationName ?? ""
|
||||
selectedOctane = Int(fuelLog.octane)
|
||||
|
@ -187,6 +191,7 @@ struct EditFuelLogView: View {
|
|||
fuelLog.octane = Int16(selectedOctane)
|
||||
fuelLog.pricePerGalon = Double(pricePerGalon) ?? 0
|
||||
fuelLog.fullTank = fullTank
|
||||
fuelLog.missedPrevious = missedPrevious
|
||||
|
||||
do {
|
||||
try viewContext.save()
|
||||
|
|
|
@ -73,6 +73,21 @@ struct FuelLogDetailView: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
Section {
|
||||
HStack {
|
||||
Text("Previous Fill-Up")
|
||||
Spacer()
|
||||
if fuelLog.missedPrevious {
|
||||
Image(systemName: "xmark.circle.fill")
|
||||
.foregroundColor(.red)
|
||||
Text("Missed")
|
||||
} else {
|
||||
Image(systemName: "checkmark.circle.fill")
|
||||
.foregroundColor(.green)
|
||||
Text("Exists")
|
||||
}
|
||||
}
|
||||
}
|
||||
Section(header: Text("Location")) {
|
||||
HStack {
|
||||
Text("Coordinates:")
|
||||
|
|
|
@ -57,7 +57,7 @@ struct FuelLogListView: View {
|
|||
let current = logs[i]
|
||||
let next = logs[i + 1]
|
||||
// Only include if fullTank is true, fuelVolume is positive, and odometer difference is positive.
|
||||
if current.fullTank, current.fuelVolume > 0, current.odometer > next.odometer {
|
||||
if current.fullTank, !current.missedPrevious, current.fuelVolume > 0, current.odometer > next.odometer {
|
||||
let mpg = (current.odometer - next.odometer) / current.fuelVolume
|
||||
mpgValues.append(mpg)
|
||||
}
|
||||
|
@ -152,6 +152,7 @@ struct FuelLogListView: View {
|
|||
let mpg: Double? = {
|
||||
// Only calculate MPG if fullTank is true.
|
||||
guard log.fullTank else { return nil }
|
||||
guard !log.missedPrevious else { return nil }
|
||||
guard index < filteredFuelLogs.count - 1 else { return nil }
|
||||
let previousLog = filteredFuelLogs[index + 1]
|
||||
let milesDriven = log.odometer - previousLog.odometer
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<attribute name="id" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
|
||||
<attribute name="locationCoordinates" optional="YES" attributeType="String"/>
|
||||
<attribute name="locationName" optional="YES" attributeType="String"/>
|
||||
<attribute name="missedPrevious" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
|
||||
<attribute name="octane" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="odometer" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
|
||||
<attribute name="pricePerGalon" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
|
||||
|
|
|
@ -14,7 +14,7 @@ struct MPGTrendChartView: View {
|
|||
for i in 1..<sortedLogs.count {
|
||||
let previous = sortedLogs[i - 1]
|
||||
let current = sortedLogs[i]
|
||||
if current.fullTank, let date = current.date,
|
||||
if current.fullTank, !current.missedPrevious, let date = current.date,
|
||||
current.odometer > previous.odometer,
|
||||
current.fuelVolume > 0 {
|
||||
let mpg = (current.odometer - previous.odometer) / current.fuelVolume
|
||||
|
|
|
@ -49,7 +49,7 @@ struct StatsView: View {
|
|||
for i in 0..<logs.count - 1 {
|
||||
let current = logs[i]
|
||||
let next = logs[i + 1]
|
||||
if current.fullTank, current.fuelVolume > 0, current.odometer > next.odometer {
|
||||
if current.fullTank, !current.missedPrevious, current.fuelVolume > 0, current.odometer > next.odometer {
|
||||
let mpg = (current.odometer - next.odometer) / current.fuelVolume
|
||||
mpgValues.append(mpg)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue