Skip to content

Commit c63c3e1

Browse files
committed
timestamp switched to date and gps speed as fallback
1 parent 1ffe0fc commit c63c3e1

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

android/app/src/main/kotlin/com/beforbike/app/database/RideDbHelper.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -559,32 +559,31 @@ class RideDbHelper(context: Context) :
559559

560560
/**
561561
* Retorna os dados brutos para os gráficos do Flutter.
562-
* (Restaurado do seu código original para garantir compatibilidade com os gráficos)
563562
*/
564563
fun getActivityChartData(rideId: Long): List<Map<String, Any?>>? {
565564
val db = this.readableDatabase
566565

567566
val cursor = db.query(
568567
TelemetryEntry.TABLE_NAME,
569568
arrayOf(
569+
TelemetryEntry.COLUMN_CRANK_SPEED,
570570
TelemetryEntry.COLUMN_GPS_SPEED,
571571
TelemetryEntry.COLUMN_CADENCE,
572572
TelemetryEntry.COLUMN_POWER,
573573
TelemetryEntry.COLUMN_ALTITUDE,
574-
TelemetryEntry.COLUMN_GPS_TIMESTAMP
574+
TelemetryEntry.COLUMN_PACKET_DATE
575575
),
576576
"${TelemetryEntry.COLUMN_RIDE_ID} = ?",
577577
arrayOf(rideId.toString()),
578578
null, null,
579-
"${TelemetryEntry.COLUMN_GPS_TIMESTAMP} ASC"
579+
"${TelemetryEntry.COLUMN_PACKET_DATE} ASC"
580580
)
581581

582582
if (!cursor.moveToFirst()) {
583583
cursor.close()
584584
return null
585585
}
586586

587-
// Formatadores de data robustos (do seu código original)
588587
val dateFormatFallbackMillis = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.getDefault())
589588
val dateFormatFallback = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
590589
val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS", Locale.getDefault())
@@ -594,7 +593,7 @@ class RideDbHelper(context: Context) :
594593

595594
cursor.use {
596595
do {
597-
val timestampStr = it.getString(it.getColumnIndexOrThrow(TelemetryEntry.COLUMN_GPS_TIMESTAMP))
596+
val timestampStr = it.getString(it.getColumnIndexOrThrow(TelemetryEntry.COLUMN_PACKET_DATE))
598597

599598
// Tenta fazer o parse da data de várias formas
600599
val timestamp = try {
@@ -611,7 +610,9 @@ class RideDbHelper(context: Context) :
611610
}
612611
} ?: System.currentTimeMillis()
613612

614-
val speed = if (!it.isNull(it.getColumnIndexOrThrow(TelemetryEntry.COLUMN_GPS_SPEED))) {
613+
val speed = if (!it.isNull(it.getColumnIndexOrThrow(TelemetryEntry.COLUMN_CRANK_SPEED))) {
614+
it.getDouble(it.getColumnIndexOrThrow(TelemetryEntry.COLUMN_CRANK_SPEED))
615+
} else if (!it.isNull(it.getColumnIndexOrThrow(TelemetryEntry.COLUMN_GPS_SPEED))) {
615616
it.getDouble(it.getColumnIndexOrThrow(TelemetryEntry.COLUMN_GPS_SPEED))
616617
} else 0.0
617618

0 commit comments

Comments
 (0)