Skip to content

Commit

Permalink
Done Changes for max speed calculation for a season and longest run f… (
Browse files Browse the repository at this point in the history
#158)

Issue:-
#105
Done Changes for max speed calculation for a season and longest run


![image](https://github.com/rilling/OpenTracks-Winter-SOEN-6431_2024/assets/157931131/9c0660dd-30d2-4e59-a5a9-6037dd8cec6e)

…or  a season

# Thanks for your contribution.

## PLEASE REMOVE
To support us in providing a nice (and fast) open-source experience:
1. Verify that the tests are passing
2. Check that the code is properly formatted (using AndroidStudio's
autoformatter)
3. Provide write access to the
[branch](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork)
4. If the PR is not ready for review, please submit it as a
[draft](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests#draft-pull-requests)
## PLEASE REMOVE

**Describe the pull request**
A clear and concise description of what the pull request changes/adds.

**Link to the the issue**
(If available): The link to the issue that this pull request solves.

**License agreement**
By opening this pull request, you are providing your contribution under
the _Apache License 2.0_ (see [LICENSE.md](LICENSE.md)).

**Note: new dependencies/libraries**
Please refrain from introducing new libraries without consulting the
team.
  • Loading branch information
apoorva2404 authored Apr 8, 2024
2 parents f826df8 + d3a9951 commit 012793e
Showing 1 changed file with 81 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import android.content.Intent;
import android.os.Bundle;
import android.renderscript.ScriptGroup;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
Expand All @@ -23,6 +21,42 @@ public class SeasonStatActivity extends AppCompatActivity {

ActivitySeasonStatBinding binding;


public int calculateSum(ArrayList<Integer> list) {
int sum = 0;
for (int num : list) {
sum += num;
}
return sum;
}

public static int findMax(ArrayList<Integer> list) {
if (list == null || list.isEmpty()) {
throw new IllegalArgumentException("ArrayList is empty or null");
}

int max = list.get(0);

for (int i = 1; i < list.size(); i++) {
int current = list.get(i);
if (current > max) {
max = current;
}
}
return max;
}

public static int maxSpeed(ArrayList<Integer> dist, ArrayList<Integer> time){
int max = (int)(dist.get(0)/time.get(0));
for (int i = 1; i < dist.size(); i++) {
int current = (int)(dist.get(i)/time.get(i));
if (current > max) {
max = current;
}
}
return max;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -48,21 +82,59 @@ protected void onCreate(Bundle savedInstanceState) {
int[] TallestRun = new int[4];
double[] LongestRun = new double[4];


int n = 10;
ArrayList<Integer>[] VerticalMList = new ArrayList[n];
int size = 10;

for (int i = 0; i < n; i++) {
VerticalMList[i] = new ArrayList<>();

for (int j = 0; j < size; j++) {
VerticalMList[i].add(random.nextInt(1000)); // Generating random integers between 0 and 999
}
}

ArrayList<Integer>[] DistanceKMs = new ArrayList[n];

for (int i = 0; i < n; i++) {
DistanceKMs[i] = new ArrayList<>();
for (int j = 0; j < size; j++) {
DistanceKMs[i].add((int) (random.nextDouble() * 20)); // Generating random integers between 0 and 999
}
}

ArrayList<Integer>[] Hours = new ArrayList[n];
ArrayList<Integer>[] Minutes = new ArrayList[n];
ArrayList<Integer>[] Seconds = new ArrayList[n];

for (int i = 0; i < n; i++) {
Hours[i] = new ArrayList<>();
Minutes[i] = new ArrayList<>();
Seconds[i] = new ArrayList<>();
for (int j = 0; j < size; j++) {
Hours[i].add((int) (1 + random.nextInt(23)));
Minutes[i].add((int) (random.nextInt(60)));
Seconds[i].add((int) (random.nextInt(60)));
}
}


ArrayList<DummySeason> seasonArrayList = new ArrayList<>();
for (int i = 0; i < 4; i++) {
Days[i] = Integer.toString(random.nextInt(1001));
VerticalM[i] = random.nextInt(1000);
VerticalM[i] = calculateSum(VerticalMList[i]);
Runs[i] = random.nextInt(20);
DistanceKM[i] = random.nextDouble() * 20;
DistanceKM[i] = calculateSum(DistanceKMs[i]);
Resort[i] = random.nextInt(10) + 1;
int hours = random.nextInt(24);
int minutes = random.nextInt(60);
int seconds = random.nextInt(60);
int hours = calculateSum(Hours[i]);
int minutes = calculateSum(Minutes[i]);
int seconds = calculateSum(Seconds[i]);
String activeTime = String.format("%02d:%02d:%02d", hours, minutes, seconds);
Active[i] = activeTime;
MaxSpeed[i] = random.nextDouble() * 100;
MaxSpeed[i] = maxSpeed(DistanceKMs[i],Hours[i]);
TallestRun[i] = (int) (random.nextDouble() * 100);
MaxAltitude[i] = (int) (random.nextDouble() * 5000);
MaxAltitude[i] = findMax(VerticalMList[i]);
LongestRun[i] = random.nextDouble() * 10;

seasonArrayList.add(new DummySeason(seasonNames[i], Integer.parseInt(Days[i]), Runs[i], Resort[i], VerticalM[i], DistanceKM[i], Active[i], MaxSpeed[i], MaxAltitude[i], TallestRun[i], LongestRun[i]));
Expand Down

0 comments on commit 012793e

Please sign in to comment.