stats
This commit is contained in:
parent
db49cf17cd
commit
e103168802
|
@ -0,0 +1,64 @@
|
||||||
|
//
|
||||||
|
// DistanceBetweenFillupsTrendChartView.swift
|
||||||
|
// Gas Man
|
||||||
|
//
|
||||||
|
// Created by Kameron Kenny on 3/19/25.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import Charts
|
||||||
|
import CoreData
|
||||||
|
|
||||||
|
struct DistanceBetweenFillupsTrendChartView: View {
|
||||||
|
let fuelLogs: [FuelLog]
|
||||||
|
|
||||||
|
// Compute trend data by sorting logs by date ascending,
|
||||||
|
// then mapping each log's date and pricePerGalon.
|
||||||
|
var trendData: [(date: Date, distance: Double)] {
|
||||||
|
let sortedLogs = fuelLogs.sorted { ($0.date ?? Date()) < ($1.date ?? Date()) }
|
||||||
|
var data: [(Date, Double)] = []
|
||||||
|
// Start from index 1 because we need a previous log to compute the difference.
|
||||||
|
for i in 1..<sortedLogs.count {
|
||||||
|
let previous = sortedLogs[i - 1]
|
||||||
|
let current = sortedLogs[i]
|
||||||
|
if let date = current.date,
|
||||||
|
current.odometer > previous.odometer,
|
||||||
|
current.fuelVolume > 0 {
|
||||||
|
let distance = (current.odometer - previous.odometer)
|
||||||
|
data.append((date, distance))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack {
|
||||||
|
if trendData.isEmpty {
|
||||||
|
Text("No trend data available.")
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
} else {
|
||||||
|
Chart {
|
||||||
|
ForEach(trendData, id: \.date) { point in
|
||||||
|
LineMark(
|
||||||
|
x: .value("Date", point.date),
|
||||||
|
y: .value("Distance", point.distance)
|
||||||
|
)
|
||||||
|
PointMark(
|
||||||
|
x: .value("Date", point.date),
|
||||||
|
y: .value("Price", point.distance)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.chartXAxis {
|
||||||
|
AxisMarks(values: .automatic(desiredCount: 4))
|
||||||
|
}
|
||||||
|
.chartYAxis {
|
||||||
|
AxisMarks(values: .automatic(desiredCount: 5))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
.navigationTitle("Distance Between Fuel-ups Trend")
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
//
|
||||||
|
// GalPerFuelUpTrendChartView.swift
|
||||||
|
// Gas Man
|
||||||
|
//
|
||||||
|
// Created by Kameron Kenny on 3/19/25.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import Charts
|
||||||
|
import CoreData
|
||||||
|
|
||||||
|
struct GalPerFuelUpTrendChartView: View {
|
||||||
|
let fuelLogs: [FuelLog]
|
||||||
|
|
||||||
|
// Compute trend data by sorting logs by date ascending,
|
||||||
|
// then mapping each log's date and pricePerGalon.
|
||||||
|
var trendData: [(date: Date, gal: Double)] {
|
||||||
|
let sortedLogs = fuelLogs.sorted { ($0.date ?? Date()) < ($1.date ?? Date()) }
|
||||||
|
return sortedLogs.compactMap { log in
|
||||||
|
if let date = log.date {
|
||||||
|
return (date, log.fuelVolume)
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack {
|
||||||
|
if trendData.isEmpty {
|
||||||
|
Text("No trend data available.")
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
} else {
|
||||||
|
Chart {
|
||||||
|
ForEach(trendData, id: \.date) { point in
|
||||||
|
LineMark(
|
||||||
|
x: .value("Date", point.date),
|
||||||
|
y: .value("Price", point.gal)
|
||||||
|
)
|
||||||
|
PointMark(
|
||||||
|
x: .value("Date", point.date),
|
||||||
|
y: .value("Price", point.gal)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.chartXAxis {
|
||||||
|
AxisMarks(values: .automatic(desiredCount: 4))
|
||||||
|
}
|
||||||
|
.chartYAxis {
|
||||||
|
AxisMarks(values: .automatic(desiredCount: 5))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
.navigationTitle("Fuel Volume Trend")
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
//
|
||||||
|
// PriceTrendChartView.swift
|
||||||
|
// Gas Man
|
||||||
|
//
|
||||||
|
// Created by Kameron Kenny on 3/19/25.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import Charts
|
||||||
|
import CoreData
|
||||||
|
|
||||||
|
struct PricePerGallonTrendChartView: View {
|
||||||
|
let fuelLogs: [FuelLog]
|
||||||
|
|
||||||
|
// Compute trend data by sorting logs by date ascending,
|
||||||
|
// then mapping each log's date and pricePerGalon.
|
||||||
|
var trendData: [(date: Date, price: Double)] {
|
||||||
|
let sortedLogs = fuelLogs.sorted { ($0.date ?? Date()) < ($1.date ?? Date()) }
|
||||||
|
return sortedLogs.compactMap { log in
|
||||||
|
if let date = log.date {
|
||||||
|
return (date, log.pricePerGalon)
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack {
|
||||||
|
if trendData.isEmpty {
|
||||||
|
Text("No price trend data available.")
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
} else {
|
||||||
|
Chart {
|
||||||
|
ForEach(trendData, id: \.date) { point in
|
||||||
|
LineMark(
|
||||||
|
x: .value("Date", point.date),
|
||||||
|
y: .value("Price", point.price)
|
||||||
|
)
|
||||||
|
PointMark(
|
||||||
|
x: .value("Date", point.date),
|
||||||
|
y: .value("Price", point.price)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.chartXAxis {
|
||||||
|
AxisMarks(values: .automatic(desiredCount: 4))
|
||||||
|
}
|
||||||
|
.chartYAxis {
|
||||||
|
AxisMarks(values: .automatic(desiredCount: 5))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
.navigationTitle("Price/Gallon Trend")
|
||||||
|
}
|
||||||
|
}
|
|
@ -172,6 +172,14 @@ struct StatsView: View {
|
||||||
Text("N/A")
|
Text("N/A")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
NavigationLink(destination: PricePerGallonTrendChartView(fuelLogs: filteredFuelLogs)) {
|
||||||
|
HStack {
|
||||||
|
Text("Trends:")
|
||||||
|
Spacer()
|
||||||
|
Image(systemName: "chart.bar.fill")
|
||||||
|
.foregroundColor(.blue)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Distance Between Fill-Ups Stats
|
// Distance Between Fill-Ups Stats
|
||||||
|
@ -204,6 +212,14 @@ struct StatsView: View {
|
||||||
Text("N/A")
|
Text("N/A")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
NavigationLink(destination: DistanceBetweenFillupsTrendChartView(fuelLogs: filteredFuelLogs)) {
|
||||||
|
HStack {
|
||||||
|
Text("Trends:")
|
||||||
|
Spacer()
|
||||||
|
Image(systemName: "chart.bar.fill")
|
||||||
|
.foregroundColor(.blue)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gallons per Fill-Up Stats
|
// Gallons per Fill-Up Stats
|
||||||
|
@ -236,6 +252,14 @@ struct StatsView: View {
|
||||||
Text("N/A")
|
Text("N/A")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
NavigationLink(destination: GalPerFuelUpTrendChartView(fuelLogs: filteredFuelLogs)) {
|
||||||
|
HStack {
|
||||||
|
Text("Trends:")
|
||||||
|
Spacer()
|
||||||
|
Image(systemName: "chart.bar.fill")
|
||||||
|
.foregroundColor(.blue)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.navigationTitle("Stats")
|
.navigationTitle("Stats")
|
||||||
|
|
Loading…
Reference in New Issue