mirror of
https://github.com/vide/matedroid.git
synced 2026-01-20 00:03:17 +08:00
feat(stats): add "Most Distance Day" record
Shows the day with the most total distance driven, displayed in the Records section of Stats for Nerds alongside the "Busiest Day" record. Added: - mostDistanceDay query to DriveSummaryDao (all-time and year range) - MostDistanceDayResult data class - mostDistanceDay field to QuickStats - Display in StatsScreen Records section with 🛣️ emoji 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.5
parent
524e43c169
commit
3a20c32cfb
@@ -186,6 +186,26 @@ interface DriveSummaryDao {
|
||||
@Query("SELECT COUNT(DISTINCT DATE(startDate)) FROM drives_summary WHERE carId = :carId")
|
||||
suspend fun countDrivingDays(carId: Int): Int
|
||||
|
||||
// Most distance in a single day
|
||||
@Query("""
|
||||
SELECT DATE(startDate) as day, SUM(distance) as totalDistance
|
||||
FROM drives_summary
|
||||
WHERE carId = :carId
|
||||
GROUP BY DATE(startDate)
|
||||
ORDER BY totalDistance DESC LIMIT 1
|
||||
""")
|
||||
suspend fun mostDistanceDay(carId: Int): MostDistanceDayResult?
|
||||
|
||||
@Query("""
|
||||
SELECT DATE(startDate) as day, SUM(distance) as totalDistance
|
||||
FROM drives_summary
|
||||
WHERE carId = :carId
|
||||
AND startDate >= :startDate AND startDate < :endDate
|
||||
GROUP BY DATE(startDate)
|
||||
ORDER BY totalDistance DESC LIMIT 1
|
||||
""")
|
||||
suspend fun mostDistanceDayInRange(carId: Int, startDate: String, endDate: String): MostDistanceDayResult?
|
||||
|
||||
// === Queries for Detail Sync ===
|
||||
|
||||
// Get drive IDs that need detail processing
|
||||
@@ -222,3 +242,8 @@ data class BusiestDayResult(
|
||||
val day: String,
|
||||
val count: Int
|
||||
)
|
||||
|
||||
data class MostDistanceDayResult(
|
||||
val day: String,
|
||||
val totalDistance: Double
|
||||
)
|
||||
|
||||
@@ -80,7 +80,8 @@ class StatsRepository @Inject constructor(
|
||||
|
||||
firstDriveDate = driveSummaryDao.firstDriveDate(carId),
|
||||
firstChargeDate = chargeSummaryDao.firstChargeDate(carId),
|
||||
busiestDay = driveSummaryDao.busiestDay(carId)
|
||||
busiestDay = driveSummaryDao.busiestDay(carId),
|
||||
mostDistanceDay = driveSummaryDao.mostDistanceDay(carId)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -113,7 +114,8 @@ class StatsRepository @Inject constructor(
|
||||
|
||||
firstDriveDate = driveSummaryDao.firstDriveDate(carId), // Always show first ever
|
||||
firstChargeDate = chargeSummaryDao.firstChargeDate(carId), // Always show first ever
|
||||
busiestDay = driveSummaryDao.busiestDayInRange(carId, startDate, endDate)
|
||||
busiestDay = driveSummaryDao.busiestDayInRange(carId, startDate, endDate),
|
||||
mostDistanceDay = driveSummaryDao.mostDistanceDayInRange(carId, startDate, endDate)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.matedroid.domain.model
|
||||
|
||||
import com.matedroid.data.local.dao.BusiestDayResult
|
||||
import com.matedroid.data.local.dao.MostDistanceDayResult
|
||||
import com.matedroid.data.local.entity.ChargeSummary
|
||||
import com.matedroid.data.local.entity.DriveSummary
|
||||
|
||||
@@ -60,7 +61,8 @@ data class QuickStats(
|
||||
// === Time Stats ===
|
||||
val firstDriveDate: String?,
|
||||
val firstChargeDate: String?,
|
||||
val busiestDay: BusiestDayResult?
|
||||
val busiestDay: BusiestDayResult?,
|
||||
val mostDistanceDay: MostDistanceDayResult?
|
||||
)
|
||||
|
||||
/**
|
||||
|
||||
@@ -563,6 +563,9 @@ private fun RecordsCard(
|
||||
|
||||
// Group 6: Other records
|
||||
val otherRecords = mutableListOf<RecordData>()
|
||||
quickStats.mostDistanceDay?.let { day ->
|
||||
otherRecords.add(RecordData("🛣️", "Most Distance Day", "%.1f km".format(day.totalDistance), day.day, null))
|
||||
}
|
||||
quickStats.busiestDay?.let { day ->
|
||||
otherRecords.add(RecordData("📅", "Busiest Day", "${day.count} drives", day.day, null))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user