Skip to content

Commit 1b377ce

Browse files
authored
Merge pull request #2 from KevFan/rebase
Rebase
2 parents 6aeebad + 3c0d3e3 commit 1b377ce

33 files changed

+1338
-404
lines changed

README.md

+43-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,44 @@
1-
# web_assignment2_gym_app
1+
# Web Assignment 2 - Play Framework Gym Applet
2+
3+
### Purpose Of Project:
4+
The project uses the play framework to develop a gym applet to allows member's of a gym to register and login to access their list of assessments if any, to add assessments and to generate some simple analytics such as BMI.
5+
6+
A trainer can also log in, view a list of members he manages, update comment for assessments and delete members.
7+
8+
### How to start project:
9+
The project is build using play framework 1.4.4. The project has not been tested in any other play framework versions.
10+
11+
### User Instructions:
12+
To start the project, download/clone the repository and run the play run command at the project directory.
13+
14+
Alternative, if the project is deployed, you can visit <link>
15+
16+
Note: Website is intended for use on a desktop - some functionality such as change in opacity on hover or pop up text on hover may not work as intended when viewed on a mobile system
17+
18+
### Feature List:
19+
+ Session information
20+
+ Assessments - sorted by date
21+
+ Member - registration
22+
+ Member - add assessments
23+
+ Member - delete assessments
24+
+ Member - update account details
25+
+ Trainer - update assessment comment
26+
+ Trainer - delete member
27+
28+
### Notes:
29+
+ Trainer can delete member assessments but this logs the trainer out afterwards due to view redirection in the delete assessments method
30+
+ Trainer can only view members that he/she manages, therefore newly registered member's that are not assigned to a trainer cannot be viewed
31+
+ There is no sign up available for a Trainer
32+
33+
### List of Software + Technologies Used
34+
+ Play Framework 1.4.4
35+
+ Heroku (if deployed)
36+
37+
38+
### Authors:
39+
Kevin Fan
40+
41+
42+
### Version/Date:
43+
16th May 2017
244

3-
Test commit

app/Bootstrap.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import java.util.List;
2-
3-
import play.*;
4-
import play.jobs.*;
5-
import play.test.*;
6-
7-
import models.*;
1+
import play.jobs.*;
2+
import play.test.*;
3+
import models.*;
84

95
/**
6+
* Class that loads the data yml file to the play database
107
* Created by kevin on 04/04/2017.
118
*/
129

1310
@OnApplicationStart
1411
public class Bootstrap extends Job {
12+
/**
13+
* Method that loads the data.yml file when there are no members in the database
14+
*/
1515
public void doJob() {
1616
if(Member.count() == 0) {
1717
Fixtures.loadModels("data.yml");

app/controllers/About.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
import play.*;
44
import play.mvc.*;
55

6-
public class About extends Controller
7-
{
8-
public static void index() {
9-
Logger.info("Rendering about");
10-
render ("about.html");
11-
}
6+
/**
7+
* Controller class to render the abouts page
8+
*/
9+
public class About extends Controller {
10+
/**
11+
* Method to log and render the about.html page
12+
*/
13+
public static void index() {
14+
Logger.info("Rendering about");
15+
render("about.html");
16+
}
1217
}

app/controllers/Accounts.java

+42-4
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,51 @@
55
import play.mvc.Controller;
66

77
/**
8+
* Controller class to control the accounts of Member and Trainers
89
* Created by kevin on 08/04/2017.
910
*/
1011
public class Accounts extends Controller {
12+
/**
13+
* Method that render's the signup.html view
14+
*/
1115
public static void signup() {
1216
render("signup.html");
1317
}
1418

19+
/**
20+
* Method that render's the login.html view
21+
*/
1522
public static void login() {
1623
render("login.html");
1724
}
1825

26+
/**
27+
* Method that registers a new member to the gym applet.
28+
* @param name Name of the Member
29+
* @param gender Gender of the Member
30+
* @param email Email of the Member
31+
* @param password Password of the Member
32+
* @param address Address of the Member
33+
* @param height Height of the Member
34+
* @param startingWeight Starting Weight of the Member
35+
*/
1936
public static void register(String name, String gender, String email, String password, String address, double height, double startingWeight) {
20-
Logger.info("Registering new user " + email);
21-
Member member = new Member(name, gender, email, password, address, height, startingWeight);
22-
member.save();
23-
redirect("/");
37+
if (Member.findByEmail(email) != null || Trainer.findByEmail(email) != null) {
38+
Logger.info("User email already used");
39+
redirect("/");
40+
} else {
41+
Logger.info("Registering new user " + email);
42+
Member member = new Member(name, gender, email, password, address, height, startingWeight);
43+
member.save();
44+
redirect("/");
45+
}
2446
}
2547

48+
/**
49+
* Method that authenticate the passed in email and password to an existing member/trainer's account
50+
* @param email Email of the member/trainer
51+
* @param password Password of the account
52+
*/
2653
public static void authenticate(String email, String password) {
2754
Logger.info("Attempting to authenticate with " + email + ":" + password);
2855
Trainer trainer = Trainer.findByEmail(email);
@@ -42,11 +69,18 @@ public static void authenticate(String email, String password) {
4269
}
4370
}
4471

72+
/**
73+
* Method to end the session
74+
*/
4575
public static void logout() {
4676
session.clear();
4777
redirect("/");
4878
}
4979

80+
/**
81+
* Method to return the Member of the current session
82+
* @return Member of the current session if logged in successfully
83+
*/
5084
public static Member getLoggedInMember() {
5185
Member member = null;
5286
if (session.contains("logged_in_Memberid")) {
@@ -58,6 +92,10 @@ public static Member getLoggedInMember() {
5892
return member;
5993
}
6094

95+
/**
96+
* Method to return the Trainer of the current session
97+
* @return Trainer of the current session if logged in successfully
98+
*/
6199
public static Trainer getLoggedInTrainer() {
62100
Trainer trainer = null;
63101
if (session.contains("logged_in_Tainerid")) {

app/controllers/Admin.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
import play.mvc.Controller;
99

1010
/**
11+
* Controller that renders the trainer account session view
1112
* Created by kevin on 04/04/2017.
1213
*/
1314
public class Admin extends Controller {
15+
/**
16+
* Method that renders the the trainer view of the list of member's he manages
17+
*/
1418
public static void index() {
15-
Logger.info("Rendering Admin");
19+
Logger.info("Rendering Trainer view");
1620

1721
Trainer trainer = Accounts.getLoggedInTrainer();
1822
List<Member> memberList = trainer.memberList;

app/controllers/Dashboard.java

+20-110
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
import java.util.Collections;
99
import java.util.List;
1010

11+
/**
12+
* Class that serves as the Controller for the main dashboard for a Member
13+
*/
1114
public class Dashboard extends Controller {
15+
/**
16+
* Renders the dashboard for the current member, and their assessments sorted in reverse order
17+
*/
1218
public static void index() {
1319
Logger.info("Rendering Dashboard");
1420
Member member = Accounts.getLoggedInMember();
@@ -17,6 +23,15 @@ public static void index() {
1723
render("dashboard.html", member, assessmentlist);
1824
}
1925

26+
/**
27+
* Adds a new assessment for the member
28+
* @param weight Weight measurement of the assessment
29+
* @param chest Chest measurement of the assessment
30+
* @param thigh Thigh measurement of the assessment
31+
* @param upperArm Upper Arm measurement of the assessment
32+
* @param waist Waist measurement of the assessment
33+
* @param hips Hips measurement of the assessment
34+
*/
2035
public static void addAssessment(double weight, double chest, double thigh, double upperArm, double waist, double hips) {
2136
Member member = Accounts.getLoggedInMember();
2237
Assessment assessment = new Assessment(weight, chest, thigh, upperArm, waist, hips);
@@ -26,6 +41,11 @@ public static void addAssessment(double weight, double chest, double thigh, doub
2641
redirect("/dashboard");
2742
}
2843

44+
/**
45+
* Deletes an assessment from the current member's list of assessments
46+
* @param id Member id
47+
* @param assessmentid Assessment id
48+
*/
2949
public static void deleteAssessment(Long id, Long assessmentid) {
3050
Member member = Member.findById(id);
3151
Assessment assessment = Assessment.findById(assessmentid);
@@ -35,114 +55,4 @@ public static void deleteAssessment(Long id, Long assessmentid) {
3555
Logger.info("Deleting Assessment");
3656
redirect("/dashboard");
3757
}
38-
39-
/**
40-
* This method calculates the BMI value for the member.
41-
* <p>
42-
* The formula used for BMI is weight divided by the square of the height.
43-
*
44-
* @return the BMI value for the member. The number returned is truncated to two decimal places.
45-
**/
46-
public static double calculateBMI() {
47-
Member member = Accounts.getLoggedInMember();
48-
if (member.height <= 0)
49-
return 0;
50-
else if (member.assessmentlist.size() != 0) {
51-
return toTwoDecimalPlaces(member.assessmentlist.get(0).weight / ((member.height * member.height)));
52-
} else {
53-
return toTwoDecimalPlaces(member.startingWeight / (member.height * member.height));
54-
}
55-
}
56-
57-
/*
58-
* This is a private helper method. It ensures that all double data returned from this class
59-
* is restricted to two decimal places. Note: this method does not round
60-
*/
61-
private static double toTwoDecimalPlaces(double num) {
62-
return (int) (num * 100) / 100.0;
63-
}
64-
65-
66-
/**
67-
* This method determines the BMI category that the member belongs to.
68-
* <p>
69-
* <pre>
70-
*
71-
* The category is determined by the magnitude of the members BMI according to the following:
72-
*
73-
* BMI less than 15 (exclusive) is "VERY SEVERELY UNDERWEIGHT"
74-
* BMI between 15 (inclusive) and 16 (exclusive) is "SEVERELY UNDERWEIGHT"
75-
* BMI between 16 (inclusive) and 18.5 (exclusive) is "UNDERWEIGHT"
76-
* BMI between 18.5 (inclusive) and 25 (exclusive) is "NORMAL"
77-
* BMI between 25 (inclusive) and 30 (exclusive) is "OVERWEIGHT"
78-
* BMI between 30 (inclusive) and 35 (exclusive) is "MODERATELY OBESE"
79-
* BMI between 35 (inclusive) and 40 (exclusive) is "SEVERELY OBESE"
80-
* BMI greater than 40 (inclusive) is "VERY SEVERELY OBESE"
81-
*
82-
* </pre>
83-
*
84-
* @return <pre>
85-
* The format of the String is similar to this (note the double quotes around the category):
86-
* "NORMAL".
87-
* </pre>
88-
*/
89-
public static String determineBMICategory() {
90-
double bmi = calculateBMI();
91-
92-
if (bmi < 15) return "VERY SEVERELY UNDERWEIGHT";
93-
else if (bmi < 16) return "SEVERELY UNDERWEIGHT";
94-
else if (bmi < 18.5) return "UNDERWEIGHT";
95-
else if (bmi < 25) return "NORMAL";
96-
else if (bmi < 30) return "OVERWEIGHT";
97-
else if (bmi < 35) return "MODERATELY OBESE";
98-
else if (bmi < 40) return "SEVERELY OBESE";
99-
else return "VERY SEVERELY OBESE";
100-
}
101-
102-
/**
103-
* This method returns a boolean to indicate if the member has an ideal
104-
* body weight based on the Devine formula.
105-
* <p>
106-
* <pre>
107-
* For males, an ideal body weight is: 50 kg + 2.3 kg for each inch over 5 feet.
108-
* For females, an ideal body weight is: 45.5 kg + 2.3 kg for each inch over 5 feet.
109-
*
110-
* Note: if no gender is specified, return the result of the female calculation.
111-
*
112-
* </pre>
113-
*
114-
* @return Returns true if the result of the devine formula is within 2 kgs (inclusive) of the
115-
* starting weight; false if it is outside this range.
116-
*/
117-
public static boolean isIdealBodyWeight() {
118-
Member member = Accounts.getLoggedInMember();
119-
double fiveFeet = 60.0;
120-
double idealBodyWeight;
121-
122-
double inches = member.height * 39.37;
123-
124-
if (inches <= fiveFeet) {
125-
if (member.gender.equals("M")) {
126-
idealBodyWeight = 50;
127-
} else {
128-
idealBodyWeight = 45.5;
129-
}
130-
} else {
131-
if (member.gender.equals("M")) {
132-
idealBodyWeight = 50 + ((inches - fiveFeet) * 2.3);
133-
} else {
134-
idealBodyWeight = 45.5 + ((inches - fiveFeet) * 2.3);
135-
}
136-
}
137-
138-
if (member.assessmentlist.isEmpty()) {
139-
return ((idealBodyWeight <= (member.startingWeight + 2.0))
140-
&& (idealBodyWeight >= (member.startingWeight - 2.0))
141-
);
142-
} else {
143-
return ((idealBodyWeight <= (member.assessmentlist.get(0).weight + 2.0))
144-
&& (idealBodyWeight >= (member.assessmentlist.get(0).weight - 2.0))
145-
);
146-
}
147-
}
14858
}

0 commit comments

Comments
 (0)