Skip to content

Commit

Permalink
fix: unset block when manual assigned
Browse files Browse the repository at this point in the history
  • Loading branch information
TsimurSh committed May 27, 2024
1 parent 0ba2bd5 commit a2e0aba
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions core/src/main/java/org/transitclock/core/AvlProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,37 @@ public void matchNewFixForPredictableVehicle(VehicleState vehicleState) {
boolean notMakingProgress = handleIfVehicleNotMakingProgress(bestTemporalMatch, vehicleState);
if (notMakingProgress) return;

if (BlockAssignerConfig.isManualAssignmentEnabled() && bestTemporalMatch != null &&
vehicleState.getAvlReport().getAssignmentId() != null &&
bestTemporalMatch.getBlock().getBlockId().equals(vehicleState.getAvlReport().getAssignmentId()) &&
vehicleState.getBlock().getBlockId().equals(vehicleState.getAvlReport().getAssignmentId()))
{
vehicleState.setMatch(bestTemporalMatch);
logger.info(
"The manual assignment is enabled then vehicleId={} must assign to blockId={}.",
vehicleState.getVehicleId(),
bestTemporalMatch.getBlock().getBlockId());
}
// Record this match unless the match was null and haven't
// reached number of bad matches.
if (bestTemporalMatch != null || vehicleState.overLimitOfBadMatches()) {
else if (bestTemporalMatch != null || vehicleState.overLimitOfBadMatches()) {
// If not over the limit of bad matches then handle normally
if (bestTemporalMatch != null || !vehicleState.overLimitOfBadMatches()) {
// Set the match of the vehicle.
vehicleState.setMatch(bestTemporalMatch);
} else {
if (BlockAssignerConfig.isManualAssignmentEnabled() && vehicleState.getBlock() != null &&
vehicleState.getAvlReport().getAssignmentId() != null && vehicleState.getPreviousMatch() != null &&
vehicleState.getBlock().getBlockId().equals(vehicleState.getAvlReport().getAssignmentId())) {
// Set the previous match if match is null.
vehicleState.setMatch(vehicleState.getPreviousMatch());

logger.info(
"Got another bad match, but the manual assignment is enabled then vehicleId={} mustn't unset blockId={}.",
vehicleState.getVehicleId(),
vehicleState.getBlock().getBlockId());
return;
}
// Exceeded allowable number of bad matches so make vehicle
// unpredictable due to bad matches log that info.
// Log that vehicle is being made unpredictable as a
Expand All @@ -337,14 +360,11 @@ public void matchNewFixForPredictableVehicle(VehicleState vehicleState) {

logger.warn("For vehicleId={} {}", vehicleState.getVehicleId(), eventDescription);

if (!BlockAssignerConfig.isManualAssignmentEnabled() && !vehicleState.getAvlReport().getAssignmentId()
.equals(bestTemporalMatch.getBlock().getId())) {
// Remove the predictions for the vehicle
makeVehicleUnpredictable(vehicleState.getVehicleId(), eventDescription, VehicleEvent.NO_MATCH);
// Remove the predictions for the vehicle
makeVehicleUnpredictable(vehicleState.getVehicleId(), eventDescription, VehicleEvent.NO_MATCH);

// Remove block assignment from vehicle
vehicleState.unsetBlock(BlockAssignmentMethod.COULD_NOT_MATCH);
}
// Remove block assignment from vehicle
vehicleState.unsetBlock(BlockAssignmentMethod.COULD_NOT_MATCH);
}
} else {
logger.info(
Expand Down

0 comments on commit a2e0aba

Please sign in to comment.