mirror of
https://github.com/ev-map/EVMap.git
synced 2026-04-23 23:57:08 -04:00
WIP: clustering in DB
This commit is contained in:
@@ -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<ChargeLocation>? = null
|
||||
) : ChargepointListItem()
|
||||
|
||||
|
||||
@@ -100,6 +100,18 @@ abstract class ChargeLocationsDao {
|
||||
@RawQuery(observedEntities = [ChargeLocation::class])
|
||||
abstract fun getChargeLocationsCustom(query: SupportSQLiteQuery): LiveData<List<ChargeLocation>>
|
||||
|
||||
@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<List<ChargeLocationClusterSimple>>
|
||||
|
||||
@Query("SELECT COUNT(*) FROM chargelocation")
|
||||
abstract fun getCount(): LiveData<Long>
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user