Skip to content

Commit

Permalink
Merge pull request #104 from 12urenloop/stationEndpointChangeKeyToName
Browse files Browse the repository at this point in the history
  • Loading branch information
NuttyShrimp authored Mar 8, 2023
2 parents d28bbc0 + 818f818 commit f8ea463
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/main/java/telraam/api/MonitoringResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public Map<Integer, List<BatonDetection>> getTeamDetectionTimes() {

@GET
@Path("/stations-latest-detection-time")
@ApiOperation(value = "Get the map of all station ID's to time since last detection")
public Map<Integer, Long> getStationIDToLatestDetectionTimeMap() {
@ApiOperation(value = "Get the map of all station name to time since last detection")
public Map<String, Long> getStationIDToLatestDetectionTimeMap() {
return stationDetectionManager.timeSinceLastDetectionPerStation();
}

Expand Down
12 changes: 5 additions & 7 deletions src/main/java/telraam/monitoring/StationDetectionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ public StationDetectionManager(DetectionDAO detectionDAO, StationDAO stationDAO)
this.stationDAO = stationDAO;
}

public Map<Integer, Long> timeSinceLastDetectionPerStation() {
public Map<String, Long> timeSinceLastDetectionPerStation() {
List<Integer> stationIdList = stationDAO.getAll().stream().map(Station::getId).toList();
Map<Integer, Long> stationIdToTimeSinceLatestDetection = new HashMap<>();
Map<String, Long> stationIdToTimeSinceLatestDetection = new HashMap<>();
for (Integer stationId : stationIdList) {
Optional<Detection> maybeDetection = this.detectionDAO.latestDetectionByStationId(stationId);

if (maybeDetection.isPresent()) {
Optional<Station> maybeStation = this.stationDAO.getById(stationId);
if (maybeDetection.isPresent() && maybeStation.isPresent()) {
Long time = maybeDetection.get().getTimestamp().getTime();
stationIdToTimeSinceLatestDetection.put(stationId, (System.currentTimeMillis() - time)/1000);
} else {
stationIdToTimeSinceLatestDetection.put(stationId, null);
stationIdToTimeSinceLatestDetection.put(maybeStation.get().getName(), (System.currentTimeMillis() - time)/1000);
}
}
return stationIdToTimeSinceLatestDetection;
Expand Down

0 comments on commit f8ea463

Please sign in to comment.