Repository navigation
Android PortalApiBase framework
This document describes how ScopeTechnology framework "PortalApiBase" works and how to integrate into your application. While the target audience is coders/developers, it brings better understanding for those who are not too tech-savvy as well.
PortalApiBase framework main functionality is to provide an interface to backend wrapping up all necessary APIs.
It's possible to filter the following events: acceleration, breaking and cornering. It means that all the events whose have gforce value lower than defined in Tenant Settings (see Connected Cars Portal -> Tenant Settings > Group 16: Driver Behaviour) are filtered out.
Using
BasePortalApi.getTrips(from: DateTime, to: DateTime, withEvents: Bool)events are already filtered out.
To use the same thresholds as ConnectedCar portal does first you need to request it and cache. Using
BasePortalApi.getTenantSettingValues(ExceptionThresholdsTenantSettings.getTenantSettingsKeys()).let { thresholdResponse ->
if (thresholdResponse.isSuccessful) {
thresholdResponse.result?.let { result ->
val thresholds = ExceptionThresholdsTenantSettings.getExceptionThresholds(result)
thresholds.storeExceptionThresholdsTenantSettings()
}
}
}Using
BasePortalApi.getMZoneEvents(startDate: String, endDate: String, vehicleId: String)filtering is handled by the app using the following functions:
private fun getMZoneEvents() {
val endDate = DateTime.now()
val startDate = endDate.minusDays(1).withTimeAtStartOfDay()
lifecycleScope.launch {
val mZoneVehicleId = BasePortalApi.getLiveSelectedVehicle().value?.mZoneVehicleId ?: ""
val tripStartTime = startDate.toString(Constants.ISO_8601_DATE_FORMAT)
val tripEndTime = endDate.toString(Constants.ISO_8601_DATE_FORMAT)
BasePortalApi.getMZoneEvents(tripStartTime, tripEndTime, mZoneVehicleId).result?.let {
val filteredEvents = filterEventsByThreshold(it.value)
}
}
}
private fun filterEventsByThreshold(events: List<MZoneDetailedTrip>): List<MZoneDetailedTrip> {
val result = arrayListOf<MZoneDetailedTrip>()
if (events.isNotEmpty()) {
val thresholds = ExceptionThresholdsTenantSettings.fromPrefUtil()
events.forEach { mZoneDetailedTrip ->
when (mZoneDetailedTrip.eventTypeDescription) {
EventType.DriverBehaviourAcceleration.eventName -> {
if (mZoneDetailedTrip.getExceptionGForce() >= (thresholds?.accelerationThreshold ?: 0.0f)) {
result.add(mZoneDetailedTrip)
} else {
Timber.i("Filtered low GForce Acceleration event: ${mZoneDetailedTrip.getExceptionGForce()}")
}
}
EventType.DriverBehaviourExcessiveBraking.eventName -> {
if (mZoneDetailedTrip.getExceptionGForce() >= (thresholds?.brakingThreshold ?: 0.0f)) {
result.add(mZoneDetailedTrip)
} else {
Timber.i("Filtered low GForce Braking event: ${mZoneDetailedTrip.getExceptionGForce()}")
}
}
EventType.DriverBehaviourCornering.eventName -> {
if (mZoneDetailedTrip.getExceptionGForce() >= (thresholds?.corneringThreshold ?: 0.0f)) {
result.add(mZoneDetailedTrip)
} else {
Timber.i("Filtered low GForce Cornering event: ${mZoneDetailedTrip.getExceptionGForce()}")
}
}
else -> {
result.add(mZoneDetailedTrip)
}
}
}
}
return result
}Consolidated SDK
SmartDrive
PortalApiBase
PortalApiClient
Wellness
SBeacon
- Overview
- Installation
- Initialization
- Beacon Scanning
- Beacon Pairing
- Trip Management
- Driving Behavior
- Calibration
- Event Handling
- Data Models
- API Reference
Consolidated SPM
SDApiManager
CCFrameworkOpen
SmartDrive
SBeacon