diff --git a/app/src/main/java/net/vonforst/evmap/model/ChargersModel.kt b/app/src/main/java/net/vonforst/evmap/model/ChargersModel.kt index ede85909..7b26957f 100644 --- a/app/src/main/java/net/vonforst/evmap/model/ChargersModel.kt +++ b/app/src/main/java/net/vonforst/evmap/model/ChargersModel.kt @@ -3,6 +3,7 @@ package net.vonforst.evmap.model import android.content.Context import android.os.Parcelable import androidx.core.text.HtmlCompat +import androidx.room.ColumnInfo import androidx.room.Embedded import androidx.room.Entity import androidx.room.PrimaryKey @@ -356,8 +357,8 @@ abstract class ChargerPhoto(open val id: String) : Parcelable { } data class ChargeLocationCluster( - val clusterCount: Int, - val coordinates: Coordinate, + @ColumnInfo("clusterCount") val clusterCount: Int, + @ColumnInfo("coordinates") val coordinates: Coordinate, val items: List? = null ) : ChargepointListItem() diff --git a/app/src/main/java/net/vonforst/evmap/storage/ChargeLocationsDao.kt b/app/src/main/java/net/vonforst/evmap/storage/ChargeLocationsDao.kt index a8614776..07bfd45e 100644 --- a/app/src/main/java/net/vonforst/evmap/storage/ChargeLocationsDao.kt +++ b/app/src/main/java/net/vonforst/evmap/storage/ChargeLocationsDao.kt @@ -100,6 +100,18 @@ abstract class ChargeLocationsDao { @RawQuery(observedEntities = [ChargeLocation::class]) abstract fun getChargeLocationsCustom(query: SupportSQLiteQuery): LiveData> + @SkipQueryVerification + @Query("SELECT SUM(1) AS clusterCount, MakePoint(AVG(X(coordinates)), AVG(Y(coordinates)), 4326) as center, SnapToGrid(coordinates, :precision) AS snapped FROM chargelocation WHERE dataSource == :dataSource AND Within(coordinates, BuildMbr(:lng1, :lat1, :lng2, :lat2)) AND timeRetrieved > :after GROUP BY snapped") + abstract fun getChargeLocationClusters( + lat1: Double, + lat2: Double, + lng1: Double, + lng2: Double, + dataSource: String, + after: Long, + precision: Double + ): LiveData> + @Query("SELECT COUNT(*) FROM chargelocation") abstract fun getCount(): LiveData @@ -111,6 +123,12 @@ abstract class ChargeLocationsDao { abstract suspend fun getSize(): Long } +data class ChargeLocationClusterSimple( + @ColumnInfo("clusterCount") val clusterCount: Int, + @ColumnInfo("center") val center: Coordinate, + @ColumnInfo("snapped") val snapped: Coordinate, +) + /** * The ChargeLocationsRepository wraps the ChargepointApi and the DB to provide caching * and clustering functionality.