diff options
Diffstat (limited to 'shared/src/commonMain')
5 files changed, 100 insertions, 9 deletions
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/ReportsApi.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/ReportsApi.kt index b4d6f74..3765207 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/ReportsApi.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/ReportsApi.kt @@ -36,12 +36,14 @@ class ReportsApi(basePath: String = "https://demo.traccar.org/api") : ApiClient( from: String, to: String, deviceId: Int, + type: String = "%", xlsx: Boolean = false ): Any { val localVariableQuery: MultiValueMap = mapOf( "deviceId" to toMultiValue(listOf(deviceId), "multi"), "from" to listOf(from), - "to" to listOf(to) + "to" to listOf(to), + "type" to listOf(type) ) val localVariableHeaders = mutableMapOf<String, String>() if (xlsx) { @@ -79,18 +81,20 @@ class ReportsApi(basePath: String = "https://demo.traccar.org/api") : ApiClient( suspend fun reportsEventsGet( from: String, to: String, + type: String = "%", deviceId: Int, ): Array<Event> { - return reportsEventsGetBase(from, to, deviceId, false) as Array<Event> + return reportsEventsGetBase(from, to, deviceId, type, false) as Array<Event> } @Suppress("UNCHECKED_CAST") suspend fun reportsEventsGetXlsx( from: String, to: String, + type: String = "%", deviceId: Int, ): ByteArray { - return reportsEventsGetBase(from, to, deviceId, true) as ByteArray + return reportsEventsGetBase(from, to, deviceId, type, true) as ByteArray } /** 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 c4f91fe..befd8f1 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 @@ -4,4 +4,81 @@ data class EventInformation( val event: Event, val position: Position?, val geofence: Geofence? -) +) { + enum class Type { + ALL, + DEVICE_ONLINE, + DEVICE_UNKNOWN, + DEVICE_OFFLINE, + DEVICE_INACTIVE, + DEVICE_MOVING, + DEVICE_STOPPED, + DEVICE_OVERSPEED, + DEVICE_FUEL_DROP, + COMMAND_RESULT, + GEOFENCE_ENTER, + GEOFENCE_EXIT, + ALARM, + IGNITION_ON, + IGNITION_OFF, + MAINTENANCE, + TEXT_MESSAGE, + DRIVER_CHANGED, + UNKNOWN + } + + companion object { + fun reportTypeToString(t: Type) = + when (t) { + Type.ALL -> "%" + Type.DEVICE_ONLINE -> "deviceOnline" + Type.DEVICE_UNKNOWN -> "deviceUnknown" + Type.DEVICE_OFFLINE -> "deviceOffline" + Type.DEVICE_INACTIVE -> "deviceInactive" + Type.DEVICE_MOVING -> "deviceMoving" + Type.DEVICE_STOPPED -> "deviceStopped" + Type.DEVICE_OVERSPEED -> "deviceOverspeed" + Type.DEVICE_FUEL_DROP -> "deviceFuelDrop" + Type.COMMAND_RESULT -> "commandResult" + Type.GEOFENCE_ENTER -> "geofenceEnter" + Type.GEOFENCE_EXIT -> "geofenceExit" + Type.ALARM -> "alarm" + Type.IGNITION_ON -> "ignitionOn" + Type.IGNITION_OFF -> "ignitionOff" + Type.MAINTENANCE -> "maintenance" + Type.TEXT_MESSAGE -> "textMessage" + Type.DRIVER_CHANGED -> "driverChanged" + Type.UNKNOWN -> "unknown" + } + + fun reportTypesToString(t: Array<Type>) = + if (t.isEmpty() || t.contains(Type.ALL)) { + reportTypeToString(Type.ALL) + } else { + t.joinToString(",", transform = this::reportTypeToString) + } + + fun stringToReportType(s: String) = + when (s) { + "deviceOnline" -> Type.DEVICE_ONLINE + "deviceUnknown" -> Type.DEVICE_UNKNOWN + "deviceOffline" -> Type.DEVICE_OFFLINE + "deviceInactive" -> Type.DEVICE_INACTIVE + "deviceMoving" -> Type.DEVICE_MOVING + "deviceStopped" -> Type.DEVICE_STOPPED + "deviceOverspeed" -> Type.DEVICE_OVERSPEED + "deviceFuelDrop" -> Type.DEVICE_FUEL_DROP + "commandResult" -> Type.COMMAND_RESULT + "geofenceEnter" -> Type.GEOFENCE_ENTER + "geofenceExit" -> Type.GEOFENCE_EXIT + "alarm" -> Type.ALARM + "ignitionOn" -> Type.IGNITION_ON + "ignitionOff" -> Type.IGNITION_OFF + "maintenance" -> Type.MAINTENANCE + "textMessage" -> Type.TEXT_MESSAGE + "driverChanged" -> Type.DRIVER_CHANGED + "unknown" -> Type.UNKNOWN + else -> Type.UNKNOWN + } + } +} diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/ReportController.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/ReportController.kt index 2151331..8a7f527 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/ReportController.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/ReportController.kt @@ -36,7 +36,8 @@ class ReportController( deviceId: Int, reportType: ReportType?, reportPeriod: ReportDates.ReportPeriod?, - xlsx: Boolean = false + xlsx: Boolean = false, + eventTypes: Array<EventInformation.Type> = arrayOf() ) { if (reportType == null || reportPeriod == null) { return @@ -54,7 +55,7 @@ class ReportController( GlobalScope.launch { when (reportType) { ReportType.POSITIONS -> fetchPositions(deviceId, previousDate, currentDate, xlsx) - ReportType.EVENTS -> fetchEvents(deviceId, previousDate, currentDate, xlsx) + ReportType.EVENTS -> fetchEvents(deviceId, previousDate, currentDate, eventTypes, xlsx) ReportType.STOPS -> fetchStops(deviceId, previousDate, currentDate, xlsx) } } @@ -84,13 +85,16 @@ class ReportController( deviceId: Int, from: String, to: String, + types: Array<EventInformation.Type>, xlsx: Boolean ) { Log.d("UnitReportsVM", "Fetching events") if (!xlsx) { val positionsResult = reportsApi.reportsRouteGet(from, to, deviceId) - val eventsResult = reportsApi.reportsEventsGet(from, to, deviceId) + val eventsResult = reportsApi.reportsEventsGet( + from, to, EventInformation.reportTypesToString(types), deviceId + ) val geofencesResult = geofencesApi.geofencesGet(all = true) val result = mutableListOf<EventInformation>() @@ -105,7 +109,9 @@ class ReportController( Log.d("UnitReportsVM", "Events report: $result") reportFlow.value = Report.EventsReport(result.toTypedArray()) } else { - val result = reportsApi.reportsEventsGetXlsx(from, to, deviceId) + val result = reportsApi.reportsEventsGetXlsx( + from, to, EventInformation.reportTypesToString(types), deviceId + ) Log.d("UnitReportsVM", "Events report: $result") reportFlow.value = Report.XlsxReport(result) diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt index 878418e..c113bef 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt @@ -1,7 +1,6 @@ package mx.trackermap.TrackerMap.utils import kotlinx.datetime.* -import kotlin.math.round class Formatter { companion object { @@ -25,5 +24,9 @@ class Formatter { } } } + + fun formatHours(millis: Long): String { + return "${millis / (1000 * 60 * 60)} hr" + } } }
\ No newline at end of file diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MapCalculus.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MapCalculus.kt index 118c117..b1a6444 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MapCalculus.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MapCalculus.kt @@ -31,6 +31,7 @@ class MapCalculus { 19 -> 1066.36479193 20 -> 533.182395965 21 -> 266.5911979825 + 22 -> 133.29559899125 else -> null } } |