diff --git a/src/main/java/telraam/logic/positioner/Position.java b/src/main/java/telraam/logic/positioner/Position.java index 1a0e002..5914a97 100644 --- a/src/main/java/telraam/logic/positioner/Position.java +++ b/src/main/java/telraam/logic/positioner/Position.java @@ -23,5 +23,6 @@ public void update(double progress, double speed) { this.progress = progress; this.speed = speed; this.timestamp = System.currentTimeMillis(); + System.out.println("Progress: " + progress + " | Speed: " + speed + " | Timestamp: " + timestamp); } } diff --git a/src/main/java/telraam/logic/positioner/nostradamus/TeamData.java b/src/main/java/telraam/logic/positioner/nostradamus/TeamData.java index ba5f047..cdf9830 100644 --- a/src/main/java/telraam/logic/positioner/nostradamus/TeamData.java +++ b/src/main/java/telraam/logic/positioner/nostradamus/TeamData.java @@ -17,7 +17,7 @@ public class TeamData { private final int totalDistance; // Total distance of the track @Getter private final Position position; // Data to send to the websocket - private final int maxDeviance; // Maximum deviance the animation can have from the reality + private final double maxDeviance; // Maximum deviance the animation can have from the reality public TeamData(int teamId, int interval, List stations, int averageAmount, double sprintingSpeed, int finishOffset) { @@ -40,7 +40,7 @@ public TeamData(int teamId, int interval, List stations, int averageAmo this.previousStationArrival = System.currentTimeMillis(); this.currentStation = new StationData(new Station(-10), new Station(-9), new CircularQueue<>(0), -10, -10, -10); // Will never trigger `isNextStation` for the first station this.position = new Position(teamId); - this.maxDeviance = 1 / stations.size(); + this.maxDeviance = (double) 1 / stations.size(); } // Add a new detection @@ -52,11 +52,13 @@ public boolean addDetection(Detection e) { // Is at a new station that is in front of the previous one. previousStation = currentStation; currentStation = stations.get(e.getStationId()); + System.out.println("Station: " + currentStation.index()); + long now = System.currentTimeMillis(); if (isNextStation()) { // Only add the time if it goes forward by exactly one station - previousStation.averageTimes().add(System.currentTimeMillis() - previousStationArrival); + previousStation.averageTimes().add(now - previousStationArrival); } - previousStationArrival = System.currentTimeMillis(); + previousStationArrival = now; return true; } @@ -87,13 +89,20 @@ public void updatePosition() { double speed, progress; // Determine whether to speed up / slow down the animation or teleport it - double difference = (goalProgress - theoreticalProgress + 1) % 1; - if ((difference >= maxDeviance && difference <= 1 - maxDeviance) || previousStation.averageTimes().size() < 5) { + double difference = (currentStation.currentProgress() - theoreticalProgress + 1) % 1; + if ((difference >= maxDeviance && difference <= 1 - maxDeviance) || currentStation.averageTimes().size() < 3) { + System.out.println("Too fast"); + System.out.println("Size: " + currentStation.averageTimes().size()); + System.out.print("Average times: "); + currentStation.averageTimes().forEach(time -> System.out.print(" | " + time)); + System.out.println(""); + System.out.println("Goal: " + currentStation.currentProgress() + " Theoretical: " + theoreticalProgress + " Difference: " + (currentStation.currentProgress() - theoreticalProgress + 1) % 1); // Animation was too far behind or ahead so teleport progress = currentStation.currentProgress(); speed = ((currentStation.nextProgress() - progress + 1) % 1) / getMedian(); } else { // Animation is close enough, adjust so that we're synced at the next station + System.out.println("Good"); progress = theoreticalProgress; speed = ((goalProgress - theoreticalProgress + 1) % 1) / (nextStationArrival - currentTime); } diff --git a/src/main/java/telraam/station/websocket/WebsocketFetcher.java b/src/main/java/telraam/station/websocket/WebsocketFetcher.java index 88e4f77..3d49016 100644 --- a/src/main/java/telraam/station/websocket/WebsocketFetcher.java +++ b/src/main/java/telraam/station/websocket/WebsocketFetcher.java @@ -90,7 +90,6 @@ public void fetch() { return; } - WebsocketClient websocketClient = new WebsocketClient(url); websocketClient.addOnOpenHandler(() -> { websocketClient.sendMessage(wsMessageEncoded); @@ -122,7 +121,7 @@ public void fetch() { new Timestamp((long) (detection.detectionTimestamp * 1000)), new Timestamp(System.currentTimeMillis()) )); - detection_mac_addresses.add(detection.mac); + detection_mac_addresses.add(detection.mac.toUpperCase()); } if (!new_detections.isEmpty()) { List db_detections = detectionDAO.insertAllWithoutBaton(new_detections, detection_mac_addresses);