Fleet Tracking Dashboard KPIs
Overview
This module provides real-time fleet monitoring metrics using ERPNext Number Cards. These KPIs display vehicle tracking insights such as:
- Live Vehicle Count
- Total Vehicle Count
- Vehicle Idling Time
- Daily Idling Metrics
- Plant Count
These metrics are calculated using backend Python APIs and displayed in the dashboard through the ERPNext Number Card framework.
1. Average Idling Time Calculation
API Method
lnder_logistics.custom_kpi.vehicle_tracking.get_total_idling_time
Purpose
Calculates the average idling time per live vehicle based on vehicle alert logs.
Data Source
- Vehicle Alert Log
- Live Vehicle Count API
Logic Flow
- Retrieve filters from dashboard input
- Fetch records from Vehicle Alert Log where:
- type = "idling"
- timestamp between selected datetime range
- Extract the affected_unit values
- Calculate total idling duration
- Fetch total live vehicles
- Calculate average idling per vehicle
Formula
Average Idling Time = Total Idling Duration / Live Vehicle Count
The result is converted to minutes before returning.
API Response
{
"value": 12.5,
"fieldtype": "Float"
}
2. Total Idling Today KPI
Number Card
Total Idling Today
Filters
From Datetime To Datetime
Default Values
From: Today 00:00:00 To: Today 23:59:59
Purpose
Displays the total idling time for the current day.
3. Live Vehicle Count
API Method
live_vehicle_count()
Purpose
Returns the total number of vehicles currently in:
- Live
- Idling
Data Source
get_all_vehicle_locations()
This function retrieves the latest GPS telemetry data for vehicles.
Status Conditions
vehicle_status in ["Live", "Idling"]
Role-Based Route Control
Depending on the user's role, the navigation route changes.
| User Role | Redirect Route |
|---|---|
| Administrator | fleet-tracker |
| Block Fleet Manager | block-fleet-tracker |
| AAC Fleet Manager | block-fleet-tracker |
| RMC Fleet Manager | block-fleet-tracker |
API Response
{
"value": 45,
"fieldtype": "Float",
"route": "fleet-tracker"
}
4. Live Block Vehicle Count
Purpose
Displays the number of block vehicles that are currently live or idling.
Logic
vehicle_status in ["Live", "Idling"]
Navigation Route
block-fleet-tracker
Number Card Filter
Vehicle.intangles_vehicle_id = set Vehicle.custom_disabled = 0
5. Sun-X Plants Count
Document Type
Address
Filters
address_type = Plant is_your_company_address = 1 disabled = 0
Purpose
Displays the number of active Sun-X plant locations configured in the system.
6. Total Vehicle Count
API Method
get_total_vehicle_count()
Purpose
Returns the total number of vehicles available for the logged-in user based on role-based access.
Role-Based Vehicle Filtering
Vehicle visibility is restricted based on fleet manager roles.
Vehicle Type Mapping
| Role | Vehicle Type |
|---|---|
| Block Fleet Manager | Block |
| AAC Fleet Manager | AAC |
| RMC Fleet Manager | RMC |
Filtering Logic
vehicles = frappe.get_all(
"Vehicle",
filters={
"custom_disabled": 0,
"custom_vehicle_type": ["in", user_vehicle_types]
}
)
Result
Users can only see vehicles that belong to their assigned fleet type.
Dashboard KPI Summary
| KPI | Description |
|---|---|
| Total Vehicle Count | Total vehicles accessible based on role |
| Live Vehicle Count | Vehicles currently active or idling |
| Live Block Vehicle Count | Live vehicles of Block fleet type |
| Total Idling Time | Average idling time across live vehicles |
| Total Idling Today | Daily idling time calculation |
| Sun-X Plants | Total configured plant addresses |
Technical Benefits
- Real-time fleet monitoring
- Role-based vehicle visibility
- Operational KPI dashboards
- Dynamic routing based on user roles
- Vehicle performance analytics
Conclusion
This module provides critical fleet monitoring KPIs for logistics operations, enabling fleet managers to track live vehicles, monitor idling behavior, and analyze operational efficiency through a role-aware dashboard system.