Definitions

Driving Insights

declare module "@sentiance-react-native/driving-insights" {
  import {EmitterSubscription} from "react-native";

  export interface DrivingInsights {
    transportEvent: TransportEvent,
    safetyScores: SafetyScores
  }

  export interface SafetyScores {
    /**
     * Smooth driving score, between 0 and 1, where 1 is the perfect score.
     */
    smoothScore?: number;
    
    /**
     * Focused driving score, between 0 and 1, where 1 is the perfect score.
     */
    focusScore?: number;
    
   /**
     * Legal driving score, between 0 and 1, where 1 is the perfect score.
     */
    legalScore?: number;
    
    /**
     * Call while moving score, between 0 and 1, where 1 is the perfect score.
     */
    callWhileMovingScore?: number;
    
    /**
     * Overall driving score, between 0 and 1, where 1 is the perfect score.
     */
    overallScore?: number;
  }

  export interface DrivingEvent {
    startTime: string;
    startTimeEpoch: number; // in milliseconds
    endTime: string;
    endTimeEpoch: number;   // in milliseconds
  }

  export interface HarshDrivingEvent extends DrivingEvent {
    magnitude: number
  }

  export interface PhoneUsageEvent extends DrivingEvent {
  }
  
 export interface CallWhileMovingEvent extends DrivingEvent {
    maxTravelledSpeedInMps?: number;
    minTravelledSpeedInMps?: number;
  }

 /**
  * An event that represents a period of time where speeding was observed.
  *
  * A speeding event is based on the speed and speed limit information of individual 
  * waypoints.These waypoints are accessible from this speeding event.
  */
  export interface SpeedingEvent extends DrivingEvent {
    /**
     * The transport waypoints that capture the speeding, where each waypoint 
     * contains the transport speed and speed limit information at the given 
     * waypoint location.
     */
    waypoints: Waypoint[];
  }

  export interface TransportEvent {
    id: string;
    startTime: string;
    startTimeEpoch: number; // in milliseconds
    endTime: string | null;
    endTimeEpoch: number | null; // in milliseconds
    durationInSeconds: number | null;
    type: string;
    transportMode: TransportMode | null;
    waypoints: Waypoint[];
    distance?: number; // in meters
  }

  export type TransportMode =
    | "UNKNOWN"
    | "BICYCLE"
    | "WALKING"
    | "RUNNING"
    | "TRAM"
    | "TRAIN"
    | "CAR"
    | "BUS"
    | "MOTORCYCLE";

  export interface Waypoint {
    latitude: number;
    longitude: number;
    accuracy: number;   // in meters
    timestamp: number;  // UTC epoch time in milliseconds
    speedInMps?: number;  // in meters per second
    speedLimitInMps?: number;  // in meters per second
    hasUnlimitedSpeedLimit: boolean;
  }

  export interface SentianceDrivingInsights {
    addDrivingInsightsReadyListener(onDrivingInsightsReady: (drivingInsights: DrivingInsights) => void): Promise<EmitterSubscription>;

    getDrivingInsights(transportId: string): Promise<DrivingInsights>;

    getHarshDrivingEvents(transportId: string): Promise<HarshDrivingEvent[]>;
    
    getPhoneUsageEvents(transportId: string): Promise<PhoneUsageEvent[]>;
        
    getCallWhileMovingEvents(transportId: string): Promise<CallWhileMovingEvent[]>;

    getSpeedingEvents(transportId: string): Promise<SpeedingEvent[]>;
  }

  const SentianceDrivingInsights: SentianceDrivingInsights;
  export default SentianceDrivingInsights;
}

Last updated