Skip to content

Commit

Permalink
Story/comp354 1 all time ski statistics (#119)
Browse files Browse the repository at this point in the history
---
## Context
- Seeking to add in some implementations for generating reports of
All-Time overall ski stats
- A new page has been added, accessible through the aggregated stats
page
- A new class has been added in using a singleton pattern to encapsulate
all-time overall ski stats
- An OSM dashboard integration has been added, accessible from the new
page to push these stats

## Issue Links
- #85 
- #86 
- #87 
- #88 
- #89 
---
  • Loading branch information
Trim0500 authored Mar 25, 2024
2 parents d547121 + 37f4cfe commit 9e43929
Show file tree
Hide file tree
Showing 12 changed files with 913 additions and 5 deletions.
17 changes: 17 additions & 0 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ limitations under the License.
android:supportsRtl="true"
android:theme="@style/OpenTracksTheme">

<activity android:name=".ui.aggregatedStatistics.Stats"
android:exported="true">
<!-- If you want this to be the start activity, add the following intent-filter -->
</activity>



<activity
android:name=".publicapi.StartRecording"
android:exported="true"
Expand Down Expand Up @@ -368,6 +375,14 @@ limitations under the License.
<activity android:name=".settings.SettingsActivity" />
<activity android:name=".settings.SettingsCustomLayoutListActivity" />
<activity android:name=".settings.SettingsCustomLayoutEditActivity" />
<activity android:name=".ui.aggregatedStatistics.StatisticsActivity"
android:exported="true">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->

<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
</activity>

<activity
android:name=".ShowErrorActivity"
Expand Down Expand Up @@ -415,8 +430,10 @@ limitations under the License.
android:name=".services.TrackDeleteService"
android:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE"/>

</application>


<queries>
<intent>
<action android:name="android.intent.action.TTS_SERVICE" />
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/de/dennisguse/opentracks/stats/MockupData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package de.dennisguse.opentracks.stats;

import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;

import de.dennisguse.opentracks.data.models.*;

public class MockupData {

public List<TrackStatistics> getTrackStatistics() {
List<TrackStatistics> trackStatisticsArray = new ArrayList<>();
trackStatisticsArray.add(createTrackStatistics(1000, 100, 10, 100, 10, 10, 100, 100, 10, 10, 100, 10, 100, 10, 10, false));
trackStatisticsArray.add(createTrackStatistics(2000, 200, 20, 200, 20, 20, 200, 200, 20, 20, 200, 20, 200, 20, 20, true));

return trackStatisticsArray;
}

private TrackStatistics createTrackStatistics(
double totalDistanceValue,long totalTime,double maxSpeedValue,double maxAltitudeValue,float totalAltLossValue,
float totalAltGainValue,long totalMovingTimeValue, int heartRate, long avgSpeedSeason, double slopePercentageSeason,
double totalVerticalDescentSeasonValue,int totalRunsSeasonValue, int totalSkiDaysSeasonValue,
double totalTrackingDistance,double minAltitude,boolean isIdle) {

TrackStatistics trackStatistics = new TrackStatistics();
trackStatistics.setTotalDistance(Distance.of(totalDistanceValue));
trackStatistics.setTotalTime(Duration.ofSeconds(totalTime));
trackStatistics.setMaxSpeed(new Speed(maxSpeedValue));
trackStatistics.setMaxAltitude(maxAltitudeValue);
trackStatistics.setTotalAltitudeLoss(totalAltLossValue);
trackStatistics.setTotalAltitudeGain(totalAltGainValue);
trackStatistics.setMovingTime(Duration.ofSeconds(totalMovingTimeValue));
trackStatistics.setAverageHeartRate(new HeartRate(heartRate));
trackStatistics.setAvgSpeedSeason(new Speed(avgSpeedSeason));
trackStatistics.setSlopePercentageSeason(slopePercentageSeason);
trackStatistics.setStartTime(Instant.now());
trackStatistics.setStopTime(Instant.now());
trackStatistics.setTotalVerticalDescentSeason(Distance.of(totalVerticalDescentSeasonValue));
trackStatistics.setTotalRunsSeason(totalRunsSeasonValue);
trackStatistics.setTotalSkiDaysSeason(totalSkiDaysSeasonValue);
trackStatistics.setTotalTrackDistanceSeason(Distance.of(totalTrackingDistance));
trackStatistics.setMinAltitude(minAltitude);
trackStatistics.setIdle(isIdle);

return trackStatistics;
}
}
180 changes: 180 additions & 0 deletions src/main/java/de/dennisguse/opentracks/stats/OverallStatistics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/*
* Copyright 2010 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package de.dennisguse.opentracks.stats;


import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.stats.TrackStatistics;


public class OverallStatistics {

// Static field that stores singleton instance
private static OverallStatistics instance;

protected OverallStatistics() {
this.totalRunsOverall = 50;
this.totalSkiDaysOverall = 25;
this.totalTrackDistanceOverall = Distance.ofKilometer(500);
this.totalVerticalDescentOverall = Distance.ofMM(100);
this.avgSpeedOverall = Speed.ofKMH(40);
this.slopePercentageOverall = .66;
}

protected OverallStatistics(int totalRunsOverall,
int totalSkiDaysOverall,
Distance totalTrackDistanceOverall,
Distance totalVerticalDescentOverall,
Speed avgSpeedOverall,
double slopePercentageOverall) {
this.totalRunsOverall = totalRunsOverall;
this.totalSkiDaysOverall = totalSkiDaysOverall;
this.totalTrackDistanceOverall = totalTrackDistanceOverall;
this.totalVerticalDescentOverall = totalVerticalDescentOverall;
this.avgSpeedOverall = avgSpeedOverall;
this.slopePercentageOverall = slopePercentageOverall;
}

// Static method that controls access to singleton instance
public static OverallStatistics getInstance(){
if (instance == null){
instance = new OverallStatistics();
}
return instance;
}

// Static method that controls access to singleton instance with parameters
public static OverallStatistics getInstance(int totalRunsOverall, int totalSkiDaysOverall, Distance totalTrackDistanceOverall, Distance totalVerticalDescentOverall, Speed avgSpeedOverall, double slopePercentageOverall){
if (instance == null){
instance = new OverallStatistics(totalRunsOverall, totalSkiDaysOverall, totalTrackDistanceOverall, totalVerticalDescentOverall, avgSpeedOverall, slopePercentageOverall);
}
return instance;
}

// The total number of all-time runs.
private int totalRunsOverall;

// The total number of all-time days skied.
private int totalSkiDaysOverall;

// The total all-time distance skied (consider all tracks).
private Distance totalTrackDistanceOverall;

// The total all-time distance covered while in vertical descents.
private Distance totalVerticalDescentOverall;

// The average all-time speed.
private Speed avgSpeedOverall;

// The all-time slope percentage.
private double slopePercentageOverall;



public int getTotalRunsOverall(){
return this.totalRunsOverall;
}

public void setTotalRunsOverall(int totalRunsOverall){
this.totalRunsOverall = totalRunsOverall;
}


public int getTotalSkiDaysOverall(){
return this.totalSkiDaysOverall;
}

public void setTotalSkiDaysOverall(int totalSkiDaysOverall){
this.totalSkiDaysOverall = totalSkiDaysOverall;
}


public Distance getTotalTrackDistanceOverall(){
return this.totalTrackDistanceOverall;
}

public void setTotalTrackDistanceOverall(Distance totalTrackDistanceOverall){
this.totalTrackDistanceOverall = totalTrackDistanceOverall;
}


public Distance getTotalVerticalDescentOverall(){
return this.totalVerticalDescentOverall;
}

public void setTotalVerticalDescentOverall(Distance totalVerticalDescentOverall){
this.totalVerticalDescentOverall = totalVerticalDescentOverall;
}


public Speed getAvgSpeedOverall(){
return this.avgSpeedOverall;
}

public void setAvgSpeedOverall(Speed avgSpeedOverall){
this.avgSpeedOverall = avgSpeedOverall;
}


public double getSlopePercentageOverall(){
return this.slopePercentageOverall;
}

public void setSlopePercentageOverall(double slopePercentageOverall){
this.slopePercentageOverall = slopePercentageOverall;
}


//The addToOverallStatistics() method is called whenever updating the overall
//statistics of a user.
public void addToOverallStatistics(TrackStatistics trackStatistics){
calculateTotalRunsOverall(trackStatistics);
calculateTotalSkiDaysOverall(trackStatistics);
calculateTotalTrackDistanceOverall(trackStatistics);
calculateTotalVerticalDescentOverall(trackStatistics);
calculateAvgSpeedOverall(trackStatistics);
calculateSlopePercentageOverall(trackStatistics);

}
private void calculateTotalRunsOverall(TrackStatistics trackStatistics){
totalRunsOverall += trackStatistics.getTotalRunsSeason();
}

private void calculateTotalSkiDaysOverall(TrackStatistics trackStatistics){
totalSkiDaysOverall += trackStatistics.getTotalSkiDaysSeason();
}

private void calculateTotalTrackDistanceOverall(TrackStatistics trackStatistics){
totalTrackDistanceOverall.plus(trackStatistics.getTotalTrackDistanceSeason());
}

private void calculateTotalVerticalDescentOverall(TrackStatistics trackStatistics){
totalVerticalDescentOverall.plus(trackStatistics.getTotalVerticalDescentSeasonSeason());
}

private void calculateAvgSpeedOverall(TrackStatistics trackStatistics){
double tempAvgOverall = (Double.parseDouble(String.valueOf(avgSpeedOverall)) + Double.parseDouble(String.valueOf(trackStatistics.getAvgSpeedSeason())))/2;
avgSpeedOverall = new Speed(tempAvgOverall);
}

private void calculateSlopePercentageOverall(TrackStatistics trackStatistics){
slopePercentageOverall = (slopePercentageOverall + trackStatistics.getSlopePercentageSeason())/2;

}
}
Loading

0 comments on commit 9e43929

Please sign in to comment.