-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CS2113-W13-2] FitTrack #22
base: master
Are you sure you want to change the base?
Changes from 129 commits
8f035e7
de93e86
b786d9a
c362a33
e1591c7
75d8979
b028922
a5c7bc6
93aeb62
29ca26a
b4d6db1
b746292
3f2cedc
bb19f78
e1f2ce6
3baea89
f6c3de1
11f8d5a
da7d9a1
ea1cbfd
52ba4bd
0971c49
da54dc1
e745817
6f3bc32
3d49df3
898ff87
cd70cea
57707f2
2ca9916
e8c9b61
d65536a
7d69e55
d627d89
ede10cb
27330af
e09602e
c3efc0e
9684552
54638bf
320e3d6
03e4bec
89fb56f
e54fb77
95bc537
57c7fa9
a538e8f
9678a96
aa10907
cc74aa9
4c9044f
ae72e9f
d82ad0d
62b13a5
0946bed
16d5a06
6664921
babdbd6
aea96dd
4d59274
5e75de1
cb10c4f
ca690bb
22ed9a7
9d92422
2aa142e
11ab74e
67e9341
5c3457c
fa27c4c
ab7b3c4
b86ec29
1599342
a9a67c1
bb8c893
cc38cf2
6a57017
1aa47aa
c97f175
88b4894
fba8cbf
8b27dfc
4965b96
0b87fd4
e484bf8
973345e
ef800fe
10f4d90
3b33856
641591f
813d0f7
e4328f4
72cd6a8
31c8369
fb73bc8
88c4713
dc00214
2e15f77
db03ae8
caa64a3
2f78230
fcd8367
25ab1f5
8baf003
a33037b
749f9ca
766fdb6
f11edb5
c4c99fc
2429460
3e31a69
c29b0d7
88e798c
faa6d9c
0407a5f
2d15dc2
be8af2f
caca0ab
d674f47
41dcdbc
307f08e
ff07edc
dddbd4d
7404bf1
0faf2c3
10f3da1
3520e35
759a24a
bda276f
5bcdb1d
816a175
4d2edef
0af1b32
226119e
303f7e7
2624865
45f75ca
717ce23
b6dec0d
1cee12d
d38f792
df27a80
a4f5fa8
493e2de
d0fbbce
226c6bc
9e2218a
fb6dd26
2687501
ce05b52
deefed1
04dfc5b
b771c61
5ffbdb9
617cc90
98438eb
160eb23
c1a0082
1f9058e
dee4581
b3631dd
e8cf557
93dc60c
c5070b9
d65e763
aab3c9e
66ae3a3
1ce5be8
ea3098a
e766127
c4e3e28
7178a5f
b28266f
0fd769c
2bf10e8
b781514
332830b
3a46c44
63078b5
6a95f27
59459f2
59d7e03
db6e070
41e9850
93d6150
7e069a0
66f6115
fc22211
77398ca
d64cd83
b359180
9f3a672
0075c64
89dd172
5001b50
ab0b8bf
6573bf7
f0a4f8e
dee71e9
94f900b
85051d5
4291b4d
c348ec9
e8a9471
a71af52
f41fff2
ea64fc1
dac86de
f6da4c4
e6338f4
ab26ad6
340f387
85678fb
5ef38a3
8ecfa09
d816cd6
f810785
8ff5da9
c835d14
acd1175
07b9755
c6b71c5
12aa540
5b2f65a
97682a8
bcc6982
5e2efc9
3679bc7
d5370c7
e9394fc
4717a5b
2769193
c3ee374
61d432e
3b8d23b
38e3631
24d05a7
43c9494
15c0e04
7746629
77c7e1a
3b34ba1
639c903
bfe6bf4
78479f9
06fe873
8da8723
e2aee92
97cd54f
5a63a3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Oct 15, 2024 9:11:30 PM fittrack.logger.FitTrackLogger setupLogger | ||
INFO: Logger successfully initialized | ||
Oct 15, 2024 9:11:30 PM fittrack.storage.Storage initialiseSaveFile | ||
INFO: Accessing existing save file... | ||
Oct 15, 2024 9:11:30 PM fittrack.storage.Storage loadSaveFile | ||
INFO: Save file successfully loaded. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,5 +42,6 @@ checkstyle { | |
} | ||
|
||
run{ | ||
enableAssertions = true | ||
standardInput = System.in | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
# About us | ||
|
||
Display | Name | Github Profile | Portfolio | ||
--------|:----:|:--------------:|:---------: | ||
![](https://via.placeholder.com/100.png?text=Photo) | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
Display | Name | Github Profile | Portfolio | ||
--------|:----------:|:----------------------------------:|:---------: | ||
![](https://via.placeholder.com/100.png?text=Photo) | Zackermax See Zheng Feng | [Github](https://github.com/Zackermax) | [Portfolio](docs/team/zackermaxsee.md) | ||
![](https://via.placeholder.com/100.png?text=Photo) | Ng Chee Kiang | [Github](https://github.com/CheeKiangg) | [Portfolio](docs/team/CheeKiang.md) | ||
![](https://via.placeholder.com/100.png?text=Photo) | Marcus Wong | [Github](https://github.com/TheDinos) | [Portfolio](docs/team/marcuswong.md) | ||
![](https://via.placeholder.com/100.png?text=Photo) | Avjay Bhar | [Github](https://github.com/Yvorm) | [Portfolio](docs/team/johndoe.md) | ||
![](https://via.placeholder.com/100.png?text=Photo) | Ayushi Yadav | [Github](https://github.com/ayushi0803) | [Portfolio](docs/team/ayushi.md) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Ng Chee Kiang - Project Portfolio Page | ||
|
||
## Overview | ||
|
||
|
||
### Summary of Contributions |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# John Doe - Project Portfolio Page | ||
# Marcus Wong - Project Portfolio Page | ||
|
||
## Overview | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Zackermax See - Project Portfolio Page | ||
|
||
## Overview | ||
I am a Year 2 CEG student taking CS2113 | ||
|
||
### Summary of Contributions |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package fittrack; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.util.ArrayList; | ||
import java.util.Scanner; | ||
|
||
import fittrack.parser.Parser; | ||
import fittrack.trainingsession.TrainingSession; | ||
import fittrack.user.User; | ||
|
||
import static fittrack.logger.FitTrackLogger.setupLogger; | ||
import static fittrack.messages.Messages.EXIT_COMMAND; | ||
import static fittrack.storage.Storage.initialiseSaveFile; | ||
import static fittrack.storage.Storage.loadSaveFile; | ||
import static fittrack.ui.Ui.printExitMessage; | ||
import static fittrack.ui.Ui.printGreeting; | ||
import static fittrack.ui.Ui.printUser; | ||
|
||
public class FitTrack { | ||
/** | ||
* Main entry-point for the FitTrack CLI application. | ||
*/ | ||
public static void main(String[] args) throws FileNotFoundException { | ||
setupLogger(); | ||
|
||
// Initialize scanner and session list | ||
Scanner scan = new Scanner(System.in); | ||
ArrayList<TrainingSession> sessionList = new ArrayList<>(); | ||
|
||
// Initialize and load the save file | ||
initialiseSaveFile(); | ||
loadSaveFile(sessionList); | ||
|
||
|
||
// Set user gender and age | ||
printGreeting(); | ||
String[] userInfo = scan.nextLine().split(" ", 2); | ||
|
||
// Assert user info is valid | ||
assert userInfo.length == 2 : "User info should contain both gender and age"; | ||
String gender = userInfo[0]; | ||
String age = userInfo[1]; | ||
|
||
// Assert that age is a valid integer | ||
assert isNumeric(age) : "Age should be a valid integer"; | ||
|
||
User user = new User(gender, age); | ||
printUser(user); | ||
|
||
String input = scan.nextLine(); | ||
|
||
// Until the exit command is entered, execute command then read user input | ||
while (!input.equals(EXIT_COMMAND)) { | ||
assert !input.trim().isEmpty() : "User input should not be null or empty"; | ||
Parser.parse(user, input, sessionList); | ||
input = scan.nextLine(); | ||
} | ||
|
||
printExitMessage(); | ||
} | ||
|
||
/** | ||
* Helper method to check if a string is numeric. | ||
* | ||
* @param str The string to check. | ||
* @return true if the string is numeric, false otherwise. | ||
*/ | ||
public static boolean isNumeric(String str) { | ||
try { | ||
Integer.parseInt(str); | ||
return true; | ||
} catch (NumberFormatException e) { | ||
return false; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package fittrack.calculator; | ||
|
||
import fittrack.enums.Gender; | ||
import fittrack.exception.InvalidAgeException; | ||
import fittrack.lookupkey.LookUpKey; | ||
|
||
import java.util.Comparator; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
public abstract class Calculator { | ||
|
||
protected static final int AGE_RANGE_LOWER_START = 12; | ||
protected static final int AGE_RANGE_LOWER_END = 19; | ||
protected static final int AGE_RANGE_UPPER_START = 20; | ||
protected static final int AGE_RANGE_UPPER_END = 24; | ||
|
||
// Utility method to find the points based on performance in the given table. | ||
protected static int getPointsFromTable(Map<LookUpKey, TreeMap<Integer, Integer>> pointsTable, | ||
Gender gender, int age, int performance, boolean reverseComparison) { | ||
|
||
try { | ||
LookUpKey key = new LookUpKey(gender, age); | ||
TreeMap<Integer, Integer> subTable = pointsTable.get(key); | ||
|
||
for (Map.Entry<Integer, Integer> entry : subTable.entrySet()) { | ||
if ((reverseComparison && performance <= entry.getKey()) || | ||
(!reverseComparison && performance >= entry.getKey())) { | ||
return entry.getValue(); | ||
} | ||
} | ||
return 0; // return 0 points as performance is below the minimum standard | ||
} catch (InvalidAgeException e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the variable name "e" informative enough? |
||
System.out.println(e.getMessage()); | ||
return 0; // return 0 points as invalid age is inputted | ||
} | ||
} | ||
|
||
// Utility method to add age sub-table for a specific gender | ||
protected static void addAgeSubTable(Map<LookUpKey, TreeMap<Integer, Integer>> pointsTable, | ||
Gender gender, int age, int[][] points, boolean reverseOrder) { | ||
assert age >= 12 && age <= 24 : "Age should be within 12 and 24 during table initialisation"; // | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accidental empty comment? |
||
TreeMap<Integer, Integer> ageSubTable; | ||
if (reverseOrder){ | ||
ageSubTable = new TreeMap<>(Comparator.reverseOrder()); | ||
} else{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Java reserved words should be followed by a white space |
||
ageSubTable = new TreeMap<>(); | ||
} | ||
|
||
for (int[] point : points) { | ||
assert point[0] >= 0 : "Performance metric cannot be negative"; | ||
assert point[1] >= 0 : "Points should never be negative"; | ||
ageSubTable.put(point[0], point[1]); | ||
} | ||
|
||
try { | ||
pointsTable.put(new LookUpKey(gender, age), ageSubTable); | ||
} catch (InvalidAgeException e) { | ||
System.out.println(e.getMessage());; | ||
} | ||
} | ||
|
||
protected static void addAllTables(Map<LookUpKey, TreeMap<Integer, Integer>> pullUpTable, | ||
Gender gender, int[][][] ageTables, boolean reverseOrder) { | ||
// Add data for lower ages | ||
for (int age = AGE_RANGE_LOWER_START; age <= AGE_RANGE_LOWER_END; age++) { | ||
addAgeSubTable(pullUpTable, gender, age, ageTables[age - AGE_RANGE_LOWER_START], reverseOrder); | ||
} | ||
|
||
// Add data for upper ages | ||
for (int age = AGE_RANGE_UPPER_START; age <= AGE_RANGE_UPPER_END; age++) { | ||
addAgeSubTable(pullUpTable, gender, age, ageTables[ageTables.length - 1], reverseOrder); // Age 20-24 table | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package fittrack.calculator; | ||
|
||
import fittrack.enums.Gender; | ||
import fittrack.lookupkey.LookUpKey; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
public class PullUpCalculator extends Calculator { | ||
private static final Map<LookUpKey, TreeMap<Integer, Integer>> pullUpTable = new HashMap<>(); | ||
private static final boolean reverseOrder = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Constant names must be all uppercase using underscore to separate words |
||
|
||
static { | ||
initialiseMaleData(); | ||
initialiseFemaleData(); | ||
} | ||
|
||
public static int calculatePoints(Gender gender, int age, int reps) { | ||
return getPointsFromTable(pullUpTable, gender, age, reps, false); | ||
} | ||
|
||
private static void initialiseMaleData() { | ||
// Age data arrays | ||
int[][][] ageTables = { | ||
{{25, 5}, {21, 4}, {16, 3}, {11, 2}, {5, 1}}, | ||
{{26, 5}, {22, 4}, {17, 3}, {12, 2}, {7, 1}}, | ||
{{27, 5}, {23, 4}, {18, 3}, {13, 2}, {8, 1}}, | ||
{{8, 5}, {6, 4}, {5, 3}, {3, 2}, {1, 1}}, | ||
{{9, 5}, {7, 4}, {5, 3}, {3, 2}, {1, 1}}, | ||
{{10, 5}, {8, 4}, {6, 3}, {4, 2}, {2, 1}}, | ||
{{11, 5}, {9, 4}, {7, 3}, {5, 2}, {3, 1}}, | ||
{{11, 5}, {9, 4}, {7, 3}, {5, 2}, {3, 1}}, | ||
{{11, 5}, {9, 4}, {7, 3}, {5, 2}, {3, 1}} | ||
}; | ||
addAllTables(pullUpTable, Gender.MALE, ageTables, reverseOrder); | ||
} | ||
|
||
private static void initialiseFemaleData() { | ||
int[][][] ageTables = { | ||
{{16, 5}, {13, 4}, {10, 3}, {7, 2}, {3, 1}}, | ||
{{17, 5}, {13, 4}, {10, 3}, {7, 2}, {3, 1}}, | ||
{{17, 5}, {14, 4}, {10, 3}, {7, 2}, {3, 1}}, | ||
{{17, 5}, {14, 4}, {10, 3}, {7, 2}, {3, 1}}, | ||
{{18, 5}, {14, 4}, {11, 3}, {7, 2}, {3, 1}}, | ||
{{18, 5}, {14, 4}, {11, 3}, {7, 2}, {3, 1}}, | ||
{{18, 5}, {15, 4}, {11, 3}, {8, 2}, {4, 1}}, | ||
{{18, 5}, {15, 4}, {11, 3}, {8, 2}, {5, 1}}, | ||
{{18, 5}, {15, 4}, {11, 3}, {8, 2}, {5, 1}} | ||
}; | ||
addAllTables(pullUpTable, Gender.FEMALE, ageTables, reverseOrder); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package fittrack.calculator; | ||
|
||
import fittrack.enums.Gender; | ||
import fittrack.lookupkey.LookUpKey; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
public class ShuttleRunCalculator extends Calculator { | ||
private static final Map<LookUpKey, TreeMap<Integer, Integer>> shuttleRunTable = new HashMap<>(); | ||
private static final boolean reverseOrder = false; | ||
|
||
static { | ||
initialiseMaleData(); | ||
initialiseFemaleData(); | ||
} | ||
|
||
public static int calculatePoints(Gender gender, int age, int reps) { | ||
assert ((age >= AGE_RANGE_LOWER_START) && (age <= AGE_RANGE_UPPER_END)); | ||
return getPointsFromTable(shuttleRunTable, gender, age, reps, true); | ||
} | ||
|
||
// Shuttle Run time (in hundredths of seconds) | ||
private static void initialiseMaleData() { | ||
// Age data arrays | ||
int[][][] ageTables = { | ||
{{103, 5}, {109, 4}, {113, 3}, {117, 2}, {122, 1}}, // Age 12 | ||
{{102, 5}, {107, 4}, {111, 3}, {115, 2}, {119, 1}}, // Age 13 | ||
{{101, 5}, {104, 4}, {108, 3}, {112, 2}, {116, 1}}, // Age 14 | ||
{{101, 5}, {103, 4}, {105, 3}, {109, 2}, {113, 1}}, // Age 15 | ||
{{101, 5}, {103, 4}, {105, 3}, {107, 2}, {111, 1}}, // Age 16 | ||
{{101, 5}, {103, 4}, {105, 3}, {107, 2}, {109, 1}}, // Age 17 | ||
{{101, 5}, {103, 4}, {105, 3}, {107, 2}, {109, 1}}, // Age 18 | ||
{{101, 5}, {103, 4}, {105, 3}, {107, 2}, {109, 1}}, // Age 19 | ||
{{103, 5}, {105, 4}, {107, 3}, {109, 2}, {111, 1}} // Age 20-24 | ||
}; | ||
addAllTables(shuttleRunTable, Gender.MALE, ageTables, reverseOrder); | ||
} | ||
|
||
private static void initialiseFemaleData() { | ||
|
||
// Age data arrays | ||
int[][][] ageTables = { | ||
{{114, 5}, {119, 4}, {123, 3}, {127, 2}, {132, 1}}, // Age 12 | ||
{{112, 5}, {117, 4}, {122, 3}, {127, 2}, {132, 1}}, // Age 13 | ||
{{114, 5}, {118, 4}, {122, 3}, {126, 2}, {130, 1}}, // Age 14 | ||
{{112, 5}, {116, 4}, {120, 3}, {124, 2}, {128, 1}}, // Age 15 | ||
{{112, 5}, {115, 4}, {118, 3}, {122, 2}, {126, 1}}, // Age 16 | ||
{{112, 5}, {115, 4}, {118, 3}, {121, 2}, {125, 1}}, // Age 17 | ||
{{112, 5}, {115, 4}, {118, 3}, {121, 2}, {124, 1}}, // Age 18 | ||
{{112, 5}, {115, 4}, {118, 3}, {121, 2}, {124, 1}}, // Age 19 | ||
{{115, 5}, {118, 4}, {121, 3}, {124, 2}, {127, 1}} // Age 20-24 | ||
}; | ||
addAllTables(shuttleRunTable, Gender.FEMALE, ageTables, reverseOrder); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package fittrack.calculator; | ||
|
||
import fittrack.enums.Gender; | ||
import fittrack.lookupkey.LookUpKey; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
public class SitAndReachCalculator extends Calculator { | ||
private static final Map<LookUpKey, TreeMap<Integer, Integer>> sitAndReachTable = new HashMap<>(); | ||
private static final boolean reverseOrder = true; | ||
|
||
static { | ||
initialiseMaleData(); | ||
initialiseFemaleData(); | ||
} | ||
|
||
public static int calculatePoints(Gender gender, int age, int length) { | ||
return getPointsFromTable(sitAndReachTable, gender, age, length, false); | ||
} | ||
|
||
private static void initialiseMaleData() { | ||
int[][][] ageTables = { | ||
{{40, 5}, {36, 4}, {32, 3}, {28, 2}, {23, 1}}, | ||
{{42, 5}, {38, 4}, {34, 3}, {30, 2}, {25, 1}}, | ||
{{44, 5}, {40, 4}, {36, 3}, {31, 2}, {27, 1}}, | ||
{{46, 5}, {42, 4}, {38, 3}, {33, 2}, {29, 1}}, | ||
{{48, 5}, {44, 4}, {40, 3}, {36, 2}, {31, 1}}, | ||
{{49, 5}, {45, 4}, {41, 3}, {36, 2}, {32, 1}}, | ||
{{49, 5}, {45, 4}, {41, 3}, {37, 2}, {32, 1}}, | ||
{{49, 5}, {45, 4}, {41, 3}, {37, 2}, {32, 1}}, | ||
{{48, 5}, {44, 4}, {40, 3}, {36, 2}, {32, 1}} | ||
}; | ||
addAllTables(sitAndReachTable, Gender.MALE, ageTables, reverseOrder); | ||
} | ||
|
||
private static void initialiseFemaleData() { | ||
int[][][] ageTables = { | ||
{{40, 5}, {37, 4}, {34, 3}, {30, 2}, {25, 1}}, | ||
{{42, 5}, {38, 4}, {36, 3}, {32, 2}, {27, 1}}, | ||
{{44, 5}, {41, 4}, {38, 3}, {33, 2}, {29, 1}}, | ||
{{46, 5}, {43, 4}, {39, 3}, {35, 2}, {31, 1}}, | ||
{{47, 5}, {44, 4}, {40, 3}, {36, 2}, {31, 1}}, | ||
{{47, 5}, {44, 4}, {41, 3}, {36, 2}, {32, 1}}, | ||
{{47, 5}, {44, 4}, {41, 3}, {36, 2}, {32, 1}}, | ||
{{47, 5}, {44, 4}, {41, 3}, {36, 2}, {32, 1}}, | ||
{{44, 5}, {41, 4}, {38, 3}, {35, 2}, {31, 1}} | ||
}; | ||
addAllTables(sitAndReachTable, Gender.FEMALE, ageTables, reverseOrder); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this supposed to be an assertion or exception?