Skip to content

Commit

Permalink
fix statues
Browse files Browse the repository at this point in the history
  • Loading branch information
OSousa117 committed Oct 30, 2023
1 parent 049dac2 commit 0ad17f9
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,39 @@ private Pair<Integer, Integer> processCapacityGroup(String userID, CapacityGroup
int weeklyImprovements = 0;
int weeklyDegradations = 0;

boolean hasDegradation = false;

for (LinkedCapacityGroupMaterialDemandEntity entity : matchedEntities) {
Optional<MaterialDemandEntity> materialDemand = materialDemandRepository.findById(entity.getMaterialDemandID());
if (materialDemand.isPresent()) {
Map<LocalDate, Double> weeklyDemands = getWeeklyDemands(materialDemand.get().getDemandSeries());
for (Map.Entry<LocalDate, Double> entry : weeklyDemands.entrySet()) {
EventType eventType = determineEventType(cgs, entry.getValue());
if (eventType == EventType.STATUS_IMPROVEMENT) weeklyImprovements++;
else if (eventType == EventType.STATUS_REDUCTION) weeklyDegradations++;

// Update status of capacity group based on each week's evaluation
cgs.setLinkStatus(eventType);
capacityGroupRepository.save(cgs);
logEvent(eventType, userID, postLog, null, cgs.getId());
if (eventType == EventType.STATUS_REDUCTION) {
hasDegradation = true; // Flag if there's a degradation
weeklyDegradations++;
} else if (eventType == EventType.STATUS_IMPROVEMENT) {
weeklyImprovements++;
}

logEvent(eventType, userID, postLog, null, cgs.getId()); // Log each week's event
}
}
}

// Set the Capacity Group's status
if (hasDegradation) {
cgs.setLinkStatus(EventType.STATUS_REDUCTION);
} else {
cgs.setLinkStatus(EventType.STATUS_IMPROVEMENT);
}
capacityGroupRepository.save(cgs);

return Pair.of(weeklyImprovements, weeklyDegradations);
}


private Map<LocalDate, Double> getWeeklyDemands(List<DemandSeries> matchedDemandSeries) {
return matchedDemandSeries.stream()
.flatMap(demand -> demand.getDemandSeriesValues().stream())
Expand Down

0 comments on commit 0ad17f9

Please sign in to comment.