aboutsummaryrefslogtreecommitdiff
path: root/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models
diff options
context:
space:
mode:
Diffstat (limited to 'shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models')
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/EventInformation.kt17
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/MapLayer.kt17
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Marker.kt102
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/UnitInformation.kt54
4 files changed, 189 insertions, 1 deletions
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/EventInformation.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/EventInformation.kt
index a008fa8..17682b8 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/EventInformation.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/EventInformation.kt
@@ -1,3 +1,20 @@
+/**
+ * TrackerMap
+ * Copyright (C) 2021-2022 Iván Ávalos <avalos@disroot.org>, Henoch Ojeda <imhenoch@protonmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
package mx.trackermap.TrackerMap.client.models
import kotlinx.serialization.Serializable
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/MapLayer.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/MapLayer.kt
index 4a48952..7bb41ae 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/MapLayer.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/MapLayer.kt
@@ -1,3 +1,20 @@
+/**
+ * TrackerMap
+ * Copyright (C) 2021-2022 Iván Ávalos <avalos@disroot.org>, Henoch Ojeda <imhenoch@protonmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
package mx.trackermap.TrackerMap.client.models
data class MapLayer(
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Marker.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Marker.kt
new file mode 100644
index 0000000..ff3fb29
--- /dev/null
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Marker.kt
@@ -0,0 +1,102 @@
+/**
+ * TrackerMap
+ * Copyright (C) 2021-2022 Iván Ávalos <avalos@disroot.org>, Henoch Ojeda <imhenoch@protonmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package mx.trackermap.TrackerMap.client.models
+
+
+data class Marker(
+ val id: Int,
+ val name: String,
+ val latitude: Double,
+ val longitude: Double,
+ val type: Type = Type.DEFAULT
+) {
+ enum class Type {
+ ANIMAL, BICYCLE, BOAT, BUS, CAR, CRANE, DEFAULT, HELICOPTER, MOTORCYCLE, OFFROAD, PERSON,
+ PICKUP, PLANE, SCOOTER, SHIP, TRACTOR, TRAIN, TRAM, TROLLEYBUS, TRUCK, VAN,
+
+ REPORT_POSITION, REPORT_START, REPORT_END
+ }
+
+ companion object {
+ fun fromUnit(unit: UnitInformation): Marker? {
+ if (unit.position?.latitude == null || unit.position.longitude == null) {
+ return null
+ }
+
+ return Marker(
+ unit.position.id!!,
+ unit.device.name,
+ unit.position.latitude,
+ unit.position.longitude,
+ categoryToMarkerType(unit.device.category ?: "")
+ )
+ }
+
+ fun fromPosition(position: Position): Marker? {
+ if (position.latitude == null || position.longitude == null) {
+ return null
+ }
+
+ return Marker(
+ position.id!!,
+ "",
+ position.latitude,
+ position.longitude
+ )
+ }
+
+ fun fromStop(stop: Stop): Marker? {
+ if (stop.latitude == null || stop.longitude == null) {
+ return null
+ }
+
+ return Marker(
+ stop.deviceId!!,
+ stop.deviceName!!,
+ stop.latitude,
+ stop.longitude
+ )
+ }
+
+ fun categoryToMarkerType(category: String?): Type {
+ return when (category?.lowercase()) {
+ "animal" -> Type.ANIMAL
+ "bicycle" -> Type.BICYCLE
+ "boat" -> Type.BOAT
+ "bus" -> Type.BUS
+ "car" -> Type.CAR
+ "crane" -> Type.CRANE
+ "helicopter" -> Type.HELICOPTER
+ "motorcycle" -> Type.MOTORCYCLE
+ "offroad" -> Type.OFFROAD
+ "person" -> Type.PERSON
+ "pickup" -> Type.PICKUP
+ "plane" -> Type.PLANE
+ "scooter" -> Type.SCOOTER
+ "ship" -> Type.SHIP
+ "tractor" -> Type.TRACTOR
+ "train" -> Type.TRAIN
+ "tram" -> Type.TRAM
+ "trolleybus" -> Type.TROLLEYBUS
+ "truck" -> Type.TRUCK
+ "van" -> Type.VAN
+ else -> Type.DEFAULT
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/UnitInformation.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/UnitInformation.kt
index edebff0..1e23396 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/UnitInformation.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/UnitInformation.kt
@@ -1,6 +1,58 @@
+/**
+ * TrackerMap
+ * Copyright (C) 2021-2022 Iván Ávalos <avalos@disroot.org>, Henoch Ojeda <imhenoch@protonmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
package mx.trackermap.TrackerMap.client.models
+import kotlinx.serialization.json.longOrNull
+
data class UnitInformation(
val device: Device,
val position: Position?
-) \ No newline at end of file
+) {
+ enum class Status {
+ ONLINE, OFFLINE, UNKNOWN
+ }
+
+ enum class EngineStop {
+ ON, OFF, UNKNOWN
+ }
+
+ /**
+ * Status is calculated from speed, because status based on
+ * the actual connection to the server is useless for our clients.
+ */
+ fun getStatus() = position?.speed?.let {
+ if (it >= 2) {
+ Status.ONLINE
+ } else {
+ Status.OFFLINE
+ }
+ } ?: Status.UNKNOWN
+
+ /* Many GPS devices reserve pin 1 for engine stop */
+ fun getEngineStop() = if (position?.attributes?.containsKey("out1") == true) {
+ position.attributes["out1"]?.toString()?.let {
+ when (it) {
+ "true" -> EngineStop.ON
+ "false" -> EngineStop.OFF
+ else -> EngineStop.UNKNOWN
+ }
+ } ?: EngineStop.UNKNOWN
+ } else EngineStop.UNKNOWN
+
+ fun getHourmeter() = position?.attributes?.get("hours")?.longOrNull
+} \ No newline at end of file