Skip to content

Commit

Permalink
Merge pull request rilling#35 from OmniaAlam/Sraddha/chairliftSpeedFu…
Browse files Browse the repository at this point in the history
…nctionality

Added speed of chairlift functionality for Chairlift Statistics
  • Loading branch information
SraddhaBhattacharjee authored Apr 8, 2024
2 parents e8b1b78 + 1240d2e commit ed71969
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/main/java/de/dennisguse/opentracks/data/models/Chairlift.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -19,10 +19,10 @@ public class Chairlift {
private static final Map<Integer, Chairlift> 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++;
}
Expand All @@ -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() {
Expand Down Expand Up @@ -86,21 +86,20 @@ public boolean isUserRidingChairlift(List<TrackPoint> 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));

Expand Down Expand Up @@ -129,6 +128,17 @@ private double calculateTotalTime(List<TrackPoint> trackPoints) {
return totalTime.toMinutes();
}

private double calculateChairliftSpeed(List<TrackPoint> trackPoints){
// Calculate total distance and time
double totalDistance = calculateTotalDistance(trackPoints);
double totalTime = calculateTotalTime(trackPoints);

// Calculate average speed
return totalDistance / totalTime;
}



public static List<Chairlift> getValidChairlifts() {
return new ArrayList<>(validChairlifts.values());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit ed71969

Please sign in to comment.