fix: keep flow topology independent from capacity
| | |
| | | Integer targetStationId = capacity.getStationId(); |
| | | Integer bufferCapacity = defaultInt(capacity.getBufferCapacity()); |
| | | List<Integer> adjacentStationIds = sortedList(adjacencyMap == null ? null : adjacencyMap.get(targetStationId)); |
| | | List<Integer> flowStationIds = buildFlowStationIds(targetStationId, adjacentStationIds, bufferCapacity); |
| | | List<Integer> flowStationIds = buildFlowStationIds(targetStationId, adjacentStationIds); |
| | | List<AutoTuneStationRuntimeItem> flowRuntimeItems = filterRuntimeByStationIds(stationRuntimeSnapshot, flowStationIds); |
| | | RuntimeCount runtimeCount = calculateRuntimeCount(flowRuntimeItems); |
| | | |
| | |
| | | } |
| | | |
| | | private List<Integer> buildFlowStationIds(Integer targetStationId, |
| | | List<Integer> adjacentStationIds, |
| | | Integer bufferCapacity) { |
| | | List<Integer> adjacentStationIds) { |
| | | LinkedHashSet<Integer> stationIds = new LinkedHashSet<>(); |
| | | if (targetStationId != null) { |
| | | stationIds.add(targetStationId); |
| | | } |
| | | stationIds.addAll(sortedList(adjacentStationIds)); |
| | | List<Integer> flowStationIds = new ArrayList<>(stationIds); |
| | | if (bufferCapacity == null || bufferCapacity <= 0 || flowStationIds.size() <= bufferCapacity) { |
| | | return flowStationIds; |
| | | } |
| | | return new ArrayList<>(flowStationIds.subList(0, bufferCapacity)); |
| | | return new ArrayList<>(stationIds); |
| | | } |
| | | |
| | | private List<AutoTuneStationRuntimeItem> filterRuntimeByStationIds(List<AutoTuneStationRuntimeItem> runtimeItems, |
| | |
| | | assertEquals("OUT", result.getDirectionCode()); |
| | | } |
| | | |
| | | @Test |
| | | void flowStationIdsAndCountsAreNotTruncatedByBufferCapacity() { |
| | | FlowTopologySnapshotServiceImpl service = new FlowTopologySnapshotServiceImpl(); |
| | | StationFlowCapacity capacity = capacity(101, "OUT", 1); |
| | | Map<Integer, List<Integer>> adjacency = new LinkedHashMap<>(); |
| | | adjacency.put(101, Arrays.asList(104, 102, 103)); |
| | | |
| | | AutoTuneFlowTopologyItem item = service.buildTopologyItem( |
| | | capacity, |
| | | adjacency, |
| | | Arrays.asList( |
| | | runtime(101, 1, 0, 0), |
| | | runtime(102, 1, 1, 0), |
| | | runtime(103, 1, 0, 9001), |
| | | runtime(104, 0, 0, 0) |
| | | ) |
| | | ); |
| | | |
| | | assertEquals(Arrays.asList(101, 102, 103, 104), item.getFlowStationIds()); |
| | | assertEquals(2, item.getOccupiedCount()); |
| | | assertEquals(1, item.getLoadingCount()); |
| | | assertEquals(1, item.getTaskHoldingCount()); |
| | | assertEquals(1, item.getNonAutoingCount()); |
| | | assertEquals(0, item.getFreeCount()); |
| | | } |
| | | |
| | | private StationFlowCapacity capacity(Integer stationId, String directionCode, Integer bufferCapacity) { |
| | | StationFlowCapacity capacity = new StationFlowCapacity(); |
| | | capacity.setStationId(stationId); |