package com.jsbogang.womp.health;
|
|
import androidx.room.Dao;
|
import androidx.room.Insert;
|
import androidx.room.OnConflictStrategy;
|
import androidx.room.Query;
|
|
import java.util.List;
|
|
@Dao
|
public interface HealthDao {
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
void upsertSample(HealthSample sample);
|
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
void upsertSleep(SleepSession session);
|
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
void upsertCursor(SyncCursor cursor);
|
|
@Query("SELECT * FROM health_sample WHERE deviceMac = :mac AND timestamp >= :from AND timestamp < :to ORDER BY timestamp ASC")
|
List<HealthSample> samplesInRange(String mac, long from, long to);
|
|
@Query("SELECT * FROM health_sample WHERE deviceMac = :mac AND timestamp >= :from AND timestamp < :to ORDER BY timestamp DESC LIMIT 1")
|
HealthSample latestInRange(String mac, long from, long to);
|
|
@Query("SELECT * FROM health_sample WHERE deviceMac = :mac AND timestamp >= :from AND timestamp < :to AND heartRate > 0 ORDER BY timestamp DESC LIMIT 1")
|
HealthSample latestHeart(String mac, long from, long to);
|
|
@Query("SELECT * FROM health_sample WHERE deviceMac = :mac AND timestamp >= :from AND timestamp < :to AND bpHigh > 0 ORDER BY timestamp DESC LIMIT 1")
|
HealthSample latestBp(String mac, long from, long to);
|
|
@Query("SELECT * FROM health_sample WHERE deviceMac = :mac AND timestamp >= :from AND timestamp < :to AND spo2 > 0 ORDER BY timestamp DESC LIMIT 1")
|
HealthSample latestSpo2(String mac, long from, long to);
|
|
@Query("SELECT * FROM health_sample WHERE deviceMac = :mac AND timestamp >= :from AND timestamp < :to AND glucose > 0 ORDER BY timestamp DESC LIMIT 1")
|
HealthSample latestGlucose(String mac, long from, long to);
|
|
@Query("SELECT SUM(stepValue) FROM health_sample WHERE deviceMac = :mac AND timestamp >= :from AND timestamp < :to")
|
Integer sumSteps(String mac, long from, long to);
|
|
@Query("SELECT MAX(stepValue) FROM health_sample WHERE deviceMac = :mac AND timestamp >= :from AND timestamp < :to")
|
Integer maxSteps(String mac, long from, long to);
|
|
@Query("SELECT * FROM health_sample WHERE timestamp = :ts AND deviceMac = :mac LIMIT 1")
|
HealthSample find(long ts, String mac);
|
|
@Query("SELECT SUM(stepValue) FROM health_sample WHERE deviceMac = :mac AND timestamp >= :from AND timestamp <= :to")
|
Integer sumStepsTo(String mac, long from, long to);
|
|
@Query("SELECT * FROM health_sample WHERE uploaded = 0 ORDER BY timestamp ASC LIMIT 80")
|
List<HealthSample> pendingUpload();
|
|
@Query("UPDATE health_sample SET uploaded = 1 WHERE timestamp = :ts AND deviceMac = :mac AND dataType = :dataType")
|
void markUploaded(long ts, String mac, String dataType);
|
|
@Query("SELECT * FROM sleep_session WHERE deviceMac = :mac AND date = :date LIMIT 1")
|
SleepSession sleepOf(String mac, String date);
|
|
@Query("SELECT lastPosition FROM sync_cursor WHERE deviceMac = :mac AND dayDate = :dayDate")
|
Integer cursorOf(String mac, String dayDate);
|
}
|