10. Penalty Point Calculation
Driver penalty points are recalculated only for the drivers queued in the penalty points calculation queue. This ensures that any changes to penalties—such as newly added penalties or expired penalties—are updated accurately in the driver's record.
Scheduler name: updateDriverPenaltyPoints
Overview
The penalty points calculation process ensures drivers' records are accurate by processing entries from the penalty points calculation queue. This queue contains records for specific drivers whose penalty points need to be recalculated based on two primary triggers:
Successful DVLA Licence Check:
After a successful DVLA licence check, the driver's record is added to the queue for the current date.Penalty End Date:
For each penalty associated with the driver, an entry is added to the queue for the day the penalty ends.
Penalty Points Calculation Logic
When processing a driver's penalty points, the following logic determines which penalties are considered:
Considered Penalties:
- Penalties with no
endDate
(indicating an indefinite penalty). - Penalties with an
endDate
in the future. - Penalties whose
endDate
is today.
- Penalties with no
Ignored Penalties:
- Penalties with an
endDate
in the past (before today's date).
- Penalties with an
Calculation Method:
- Each valid penalty contributes to the total penalty points based on its
penaltyPoints
value. - The value is summed up only if:
- It is a valid number (
isNumber
). - It is not
NaN
.
- It is a valid number (
- Invalid values are ignored during the summation process.
- Each valid penalty contributes to the total penalty points based on its
Example
Considering today's date is 2025-01-15 and the driver has the following penalties:
Penalties Data:
Penalty ID | Penalty Points | End Date | Considered? |
---|---|---|---|
1 | 3 | None | Yes |
2 | 2 | 2025-01-16 | Yes |
3 | 5 | 2025-01-15 | Yes (today) |
4 | 4 | 2025-01-14 | No (expired) |
Total Penalty Points:
3 (Penalty 1) + 2 (Penalty 2) + 5 (Penalty 3) = 10
Updating Records
Once the penalty points are calculated, the following updates occur:
Driver Record:
ThepenaltyPoints
anddriverStat
fields in the driver's record are updated with the new values.License Record:
ThepenaltySeenByCustomer
field is set tofalse
, indicating that the customer has not yet reviewed the updated penalty information.
Status: Draft (Pending Review)
Category: Protected
Authored By: Sohan on Jan 15, 2025