IMS SDK Product Document
  • Getting Started
    • iOS
      • Requirements
      • Importing the SDK
      • Permissions
      • Initializing the SDK
      • Using the SDK
        • Using Push Notifications
          • Push notification certificate and profile creation guide
    • Android
      • Requirements
      • Import the SDK
      • Permissions
      • Obfuscation
      • Initialize the SDK
      • Using the SDK
        • Trip Detection and Recording
          • Trip Manager Configuration
            • Using TripDetector.AWARENESS
            • Trip Manager Device Support
          • Trip Manager Control
          • Trip Manager Status
        • Bluetooth and Other Devices
    • React Native
      • Requirements
      • Import the SDK
      • Permissions
      • Initialize the SDK
        • Android
        • iOS
      • Using the SDK
        • Trip Manager
        • Device service
    • Flutter
      • Requirements
      • Import the SDK
      • Permissions
      • Initialize the SDK
      • Using the SDK
  • Security
  • App misuse
  • Time Driven Without Phone
  • DriveSync Portal
    • Requirement
    • User
    • Device
    • Driving Alert
    • Push Notification
    • Invitations
    • Subscription
    • Trip
    • Location
    • Driving Summary
    • Discount
    • Scoring
    • Vehicle
    • Leaderboard
    • Rewards
    • Submit consent to EULA
    • Legal documents and FAQ
    • Named Driver
    • Wedge
  • Known Issues
    • iOS
    • Android
      • 1.17.0
      • 1.18.0
      • 1.22.0
  • Releases
    • 1.13.0
      • iOS
      • Android
    • 1.14.0
      • Android
    • 1.15.0
      • iOS
      • Android
    • 1.15.1
    • 1.16.0
      • iOS
      • Android
    • 1.17.0
      • iOS
      • Android
    • 1.18
      • iOS
      • Android
    • 1.18.1
    • 1.19.0
      • iOS
      • Android
    • 1.20.0
      • Android
      • iOS
    • 1.21.0
      • Android
      • iOS
    • 1.22.0
      • Android
      • iOS
    • 1.23.0
      • Android
      • iOS
    • 1.24.0
      • Android
      • iOS
    • 1.24.1
      • iOS
  • Migration
    • iOS
      • 1.15.x -> 1.16.0
      • 1.16.0 -> 1.17.0
      • 1.17.0 -> 1.18.0
      • 1.18.0 -> 1.19.0
      • 1.19.0 -> 1.20.0
      • 1.20.0 -> 1.21.0
      • 1.21.0 -> 1.22.0
      • 1.22.0 -> 1.23.0
      • 1.23.0 -> 1.24.0
      • 1.24.0 -> 1.24.1
    • Android
      • 1.15.x -> 1.16
      • 1.16 -> 1.17
      • 1.17 -> 1.18
      • 1.18 -> 1.19
      • 1.19 -> 1.20
      • 1.20 -> 1.21
      • 1.21 -> 1.22
      • 1.22 -> 1.23
      • 1.23 -> 1.24
  • Support
Powered by GitBook
On this page
  • Scoring
  • Scoring Aggregate
  • ScoringAggregate model
  • Pre-made date ranges
  • Custom date range
  • Vehicle
  • Scoring average
  • ScoringAverage model
  • Weekly average
  • Vehicle
  1. DriveSync Portal

Scoring

Handles ScoringAggregate and ScoringAverage related requests with IMS web services.

Scoring

You can get the average and maximum aggregate scores for previous trips taken by using the ScoringAggregateService. Functions have been added to query the scores over various different time periods. The time periods available are:

  • today

  • the last 7 days / last week

  • the last 30 days / last month

  • the last 90 days

  • the last 365 days

  • the last N days

  • custom date range

The definition of a day is based on the user's current timezone.

For the following, the example timezone should be considered to be UTC-0400 (i.e Toronto). If a request for today's data is made at on the 2nd day of the month, at 23:00 (11PM) UTC-0400, the result should be based on that specific day, even though the current date according to the UTC would be the 3rd day of the month. (11:00PM UTC-0400 corresponds to 03:00AM the next day on UTC-0000 time).

Some other examples: User's time: 2020-01-01 - 00:01AM UTC-0400 (04:01AM UTC-0000) Results: 2020-01-01

User's time: 2020-01-01 - 12:01PM UTC-0400 (04:01PM UTC-0000) Results: 2020-01-01

User's time: 2020-01-01 - 10:01PM UTC-0400 (2020-01-02 02:01AM UTC-0000) Results: 2020-01-01

Scoring Aggregate

An aggregate of scoring averages and sub scoring (braking, cornering, acceleration and speed).

ScoringAggregate model

ScoringAggregate model includes scores data along with the events captured in ScoringAggregate.tripScoringDailyAggregate.componentScores.

The host app can access the events through componentScores which have score types:

  • speeding

  • milage

  • braking

  • cornering

  • payd

  • overSpeeding

  • acceleration

  • distractedDriving

The otherSubScores is type of Dictionary for which the key is a custom event that is not in the above list.

Pre-made date ranges

There are some Pre-made requests for easy access to some commonly used date ranges, as they are commonly used for other scoring components.

The current list includes:

  • Today

  • Last 7 days

  • Last 30 days

  • Last 90 days

  • Last 365 days

Today

To fetch the ScoringAggregate for the user for the today, the following API can be used.

Concrete example

let service = ScoringService()
service.today(then: { result in
    guard !result.value.isEmpty else {
        // failure
        return
    }
    completionHandler(.success(result.value))
})
val service = ScoringService()
service.fetchTodaysDailyScores() { result: Result<Content?>? ->
    if (result?.value == null || result.throwable != null) {
        // failure
    } else {
        // Success
        val content = result.value
        completionHandler(content)
    }
})

Last 7 days

Fetch the ScoringAggregate for the user for the last 7 days, the following API can be used.

Concrete example

let service = ScoringService()
service.last7Days(then: { result in
    guard !result.value.isEmpty else {
        // failure
        return
    }
    completionHandler(.success(result.value))
})
val service = ScoringService()
service.fetchLast7DaysDailyScores() { result: Result<Content?>? ->
        if (result?.value == null || result.throwable != null) {
            // failure
        } else {
            // Success
            val content = result.value
            completionHandler(content)
        }
})

Other values

In order to get last 30, 90, and 365 days simply replace number "7" with the desired value respectively.

Custom date range

Fetching data for the scoring aggregate requires a start and end date (range).

The date is assumed to be based on the user's current timezone. As an example, if the current user's timezone is set to UTC-5:00, the long 1603416046000 corresponds to 2020-10-22 (even though it corresponds to 2020-10-23 1:20AM UTC).

To fetch the ScoringAggregate for the user over a period of time with a start and end date(range), the following API can be used.

Concrete example

let service = ScoringService()
service.dateRange(from: Date(), to: Date(), then: { result in
    guard !result.value.isEmpty else {
        // failure
        return
    }
    completionHandler(.success(result.value))
})
val service = ScoringService()
service.fetchDaily(from, to) { result: Result<Content?>? ->
    if (result?.value == null || result.throwable != null) {
        // failure
    } else {
        // Success
        val content = result.value
        completionHandler(content)
    }
})

Vehicle

Fetching data for the scoring aggregate requires a start and end date (range).

Required information

*vehicle ID: In order to fetch scoring data for a vehicle, the application must have a valid vehicle associated with the identity.

To fetch the ScoringAggregate for a vehicle of the user over a period of time with a start and end date(range), the following API can be used.

Concrete example

service.fetchAggregateScoresByVehicle(vehicleId: vehicleId, from: Date(), to: Date(), then: { result in
    guard !result.value.isEmpty else {
        // failure
        return
    }
    completionHandler(.success(result.value))
})
val service = ScoringService()
service.fetchAggregateScoresByVehicle(vehicleID, from, to) {
     result: Result<Content?>? ->
        if (result?.value == null || result.throwable != null) {
            // failure
        } else {
            // Success
            val content = result.value
            completionHandler(content)
        }
})

To fetch the ScoringAggregate for a vehicle of the user for the past N days, the following API can be used.

service.fetchLastNDaysAggregateScoresByVehicle(vehicleId: vehicleId, days: days, then: { result in
    guard !result.value.isEmpty else {
        // failure
        return
    }
    completionHandler(.success(result.value))
})
val service = ScoringService()
service.fetchLastNDaysAggregateScoresByVehicle(vehicleID, days) {
     result: Result<Content?>? ->
        if (result?.value == null || result.throwable != null) {
            // failure
        } else {
            // Success
            val content = result.value
            completionHandler(content)
        }
})

Failures

ScoringService provides a [Throwable] in the results sent to the [ResultCallback].

The [Result] provided can be differentiated by checking the type of results, which is always [Result.Success] or [Result.Failure].

Alternatively, the [ResultCallback] can test for the presence of the throwable.

scoringService.fetchTodaysScores(result -> {
   ScoringAggregate aggregate = result.getValue();
   if (aggregate != null) {
       setScoreTextValue("Daily: ", result.getValue());
   } else {
       NetworkException exception = (NetworkException) result.getThrowable();
       if (exception.getReason() == NetworkException.Reason.SERVER_NOT_FOUND) {
           showError("Server not found");
       }
   }
});

Scoring average

ScoringAverage model

ScoringAverage model includes scores data along with the events captured in ScoringAverage.tripScoringAverage.componentScores.

The host app can access the events through componentScores which accepts custom scoring events with the sub component named otherSubScores.

The otherSubScores is type of Dictionary for which the key is a custom event required for host app.

In all the above API's "Daily" can replaced by "Average" to get the corresponding response.

Concrete example

For example to fetch the ScoringAverage for the user for the last 7 days, the following API can be used.

let service = ScoringService()
service.custom(from: fromDate, to: toDate, then: { result in
    guard !result.value.isEmpty else {
        // error
        return
    }
    completionHandler(.success(result.value))
}
val service = ScoringService()
service.fetchLast7DaysAverageScores() { result: Result<Content?>? ->
        if (result?.value == null || result.throwable != null) {
            // failure
        } else {
            // Success
            val content = result.value
            completionHandler(content)
        }
})

Weekly average

To receive week by week score data, call fetchWeek api to recieve the desired data. The number passed as argument is a UInt representing the number of weeks you want the data. For example, to retreive current week you'll pass 0 and for last week you need to pass 1.

For example to fetch the ScoringAverage for the user for the desired week, the following API can be used.

Concrete example

let service = ScoringService()
service.fetchWeek(weekNumber: weekNumber, then: { result in
    guard !result.value.isEmpty else {
        // error
        return
    }
    completionHandler(.success(result.value))
}
val service = ScoringService()
service.fetchWeek(weekNumber) { result: Result<Content?>? ->
        if (result?.value == null || result.throwable != null) {
            // failure
        } else {
            // Success
            val content = result.value
            completionHandler(content)
        }
})

Vehicle

Fetching data for the scoring average requires a start and end date (range).

Required information

*vehicle ID: In order to fetch scoring data for a vehicle, the application must have a valid vehicle associated with the identity.

To fetch the ScoringAverage for a vehicle of the user over a period of time with a start and end date(range), the following API can be used.

Concrete example

let service = ScoringService()
service.fetchAverageScoresByVehicle(vehicleId: vehicleId, from: fromDate, to: toDate, then: { result in
    guard !result.value.isEmpty else {
        // error
        return
    }
    completionHandler(.success(result.value))
}
val service = ScoringService()
service.fetchAverageScoresByVehicle(vehicleID, from, to) {
     result: Result<Content?>? ->
        if (result?.value == null || result.throwable != null) {
            // failure
        } else {
            // Success
            val content = result.value
            completionHandler(content)
        }
})

To fetch the ScoringAverage for a vehicle of the user for the past N days, the following can be used.

Note: In iOS (Swift) the method fetchLastNDaysAverageScores, has vehicle ID as optional. If it is NOT passed, the api returns user's last N days average scores.

let service = ScoringService()
service.fetchLastNDaysAverageScores(vehicleId: vehicleId, days: days, then: { result in
    guard !result.value.isEmpty else {
        // error
        return
    }
    completionHandler(.success(result.value))
}
val service = ScoringService()
service.fetchLastNDaysAverageScoresByVehicle(vehicleID, days) {
     result: Result<Content?>? ->
        if (result?.value == null || result.throwable != null) {
            // failure
        } else {
            // Success
            val content = result.value
            completionHandler(content)
        }
})
PreviousDiscountNextVehicle

Last updated 5 months ago

Any valid user on the DriveSync system (identified via the Identityset during ) should be able to know scoring aggregate.

Any valid user on the DriveSync system (identified via the Identity set during ) should be able to know scoring aggregate.

SDK initialization
SDK initialization