From 243e7951021d9732b85cb36109bfe3bb7548688c Mon Sep 17 00:00:00 2001 From: SraddhaBhattacharjee Date: Sun, 7 Apr 2024 20:07:14 -0400 Subject: [PATCH] Added speed of chairlift functionality for Chairlift Statistics --- .../opentracks/data/models/Chairlift.java | 34 ++++++++++++------- .../opentracks/stats/ChairliftStatistics.java | 14 ++++++++ 2 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 src/main/java/de/dennisguse/opentracks/stats/ChairliftStatistics.java diff --git a/src/main/java/de/dennisguse/opentracks/data/models/Chairlift.java b/src/main/java/de/dennisguse/opentracks/data/models/Chairlift.java index 09c08acdf..062487809 100644 --- a/src/main/java/de/dennisguse/opentracks/data/models/Chairlift.java +++ b/src/main/java/de/dennisguse/opentracks/data/models/Chairlift.java @@ -10,7 +10,7 @@ public class Chairlift { // Fields private String name; private int number; - private double averageSpeed; + private double chairliftSpeed; private String liftType; private int id; @@ -19,10 +19,10 @@ public class Chairlift { private static final Map validChairlifts = new HashMap<>(); // Constructors - public Chairlift(String name, int number, double averageSpeed, String liftType) { + public Chairlift(String name, int number, double chairliftSpeed, String liftType) { this.name = name; this.number = number; - this.averageSpeed = averageSpeed; + this.chairliftSpeed = chairliftSpeed; this.liftType = liftType; this.id = nextId++; } @@ -44,12 +44,12 @@ public void setNumber(int number) { this.number = number; } - public double getAverageSpeed() { - return averageSpeed; + public double getchairliftSpeed() { + return chairliftSpeed; } - public void setAverageSpeed(double averageSpeed) { - this.averageSpeed = averageSpeed; + public void setchairliftSpeed(double chairliftSpeed) { + this.chairliftSpeed = chairliftSpeed; } public String getLiftType() { @@ -86,21 +86,20 @@ public boolean isUserRidingChairlift(List trackPoints) { return false; // Likely not on chairlift } - // Calculate total distance and time - double totalDistance = calculateTotalDistance(trackPoints); + // Calculate total time double totalTime = calculateTotalTime(trackPoints); // Calculate average speed - double averageSpeed = totalDistance / totalTime; + double chairliftSpeed = calculateChairliftSpeed(trackPoints); // Check average speed and total time - if ((averageSpeed < speedThreshold || averageSpeed > 6) || + if ((chairliftSpeed < speedThreshold || chairliftSpeed > 6) || (totalTime > timeThreshold && totalTime < 7.7)) { return false; } // Add chairlift to valid chairlifts and mark track points as chairlift segment - Chairlift validChairlift = new Chairlift(name, number, averageSpeed, liftType); + Chairlift validChairlift = new Chairlift(name, number, chairliftSpeed, liftType); validChairlifts.put(validChairlift.getId(), validChairlift); trackPoints.forEach(trackPoint -> trackPoint.setChairliftSegment(true)); @@ -129,6 +128,17 @@ private double calculateTotalTime(List trackPoints) { return totalTime.toMinutes(); } + private double calculateChairliftSpeed(List trackPoints){ + // Calculate total distance and time + double totalDistance = calculateTotalDistance(trackPoints); + double totalTime = calculateTotalTime(trackPoints); + + // Calculate average speed + return totalDistance / totalTime; + } + + + public static List getValidChairlifts() { return new ArrayList<>(validChairlifts.values()); } diff --git a/src/main/java/de/dennisguse/opentracks/stats/ChairliftStatistics.java b/src/main/java/de/dennisguse/opentracks/stats/ChairliftStatistics.java new file mode 100644 index 000000000..cb9d87756 --- /dev/null +++ b/src/main/java/de/dennisguse/opentracks/stats/ChairliftStatistics.java @@ -0,0 +1,14 @@ +package de.dennisguse.opentracks.stats; + +import de.dennisguse.opentracks.data.models.Chairlift; + +public class ChairliftStatistics extends Chairlift{ + + public ChairliftStatistics(String name, int number, double averageSpeed, String liftType) { + super(name, number, averageSpeed, liftType); + } + + public double getChairliftSpeed(){ + return super.getchairliftSpeed(); + } +}