Developer Guide for traKCAL

The purpose of this developer guide is as reference for future collaborators of trakCAL.

By: CS2113-T09-4
Since: October 2020
Licence: MIT


1.0 Introduction

Welcome to traKCAL!

traKCAL is a desktop application for managing and visualizing your calorie intake, optimized for use via Command Line Interface (CLI) whilst retaining the benefits of a Graphical User Interface (GUI).

This guide will provide information on the design and implementation of traKCAL to help you get started on your journey of becoming a contributor to traKCAL. This guide will also explain the various features available in traKCAL, to provide you with a better understanding of the current version of traKCAL


1.1 Table of Contents


2.0 Prerequisites



2.1 Setting up

  1. Fork the traKCAL repository here and git clone it to a convenient location on your desktop eg. Desktop.
  2. Open any IDE (Intellij preferred) and click Configure -> Project Defaults -> Project Structure -> New and ensure that a valid Java 11 SDK is selected.
  3. Next, go to Import Project and select the build.gradle file.
  4. Click Open as Project and accept all default settings.
  5. After opening the project, go to src -> main -> java -> seedu.duke -> Trakcal and right click on the Trakcal class. Select the Run 'Trakcal.main()' option.
  6. Upon successful run, the following opening message will be shown:

     ====================================================================================
     | Hello from                                                                       |
     |  _                  _  __   ___     _     _                                      |
     | | |_   _ _   __ _  | |/ /  / __|   /_\   | |                                     |
     | |  _| | '_| / _` | | ' <  | (__   / _ \  | |__                                   |
     |  \__| |_|   \__,_| |_|\_\  \___| /_/ \_\ |____|                                  |
     |                                                                                  |
     | Hello! I'm traKCAL.                                                              |
     | Please do input 'help' for the commands and their respective input format.       |
     ====================================================================================
    
  7. You will then be prompted to create a new user profile.



3.0 Design

3.1 Architecture

ArchitectureDiagram

Figure 1. Architecture diagram of traKCAL

The Architecture Diagram shown above explains the high-level design of traKCAL. There are 8 components in traKCAL, and their functionalities will be discussed below:


3.2 Ui component

Ui Component

Figure 2. Diagram for UI component

The UI component deals with interactions with the user by displaying appropriate messages to the user, including the welcome message and appropriate error messages whenever an error has been detected.


3.3 Logic component

Logic Component

Figure 2. Diagram for logic component

* This means that there are multiple PrepareCommand children classes inherited by the PrepareCommand class.

The main bulk of data processing takes place in the logic component. In this component, the data from the user input is checked for its validity and parsed down further to the PrepareCommand class to its respective command classes. These command classes are derived from the Command class. Each different command block deals with the proposed functionality which can be associated with Ui,storage or model components.


3.4 Model component

Model_Component

Figure 3. Diagram for Model component

In the Model component,


3.5 Command component

Before executing the command, user input has to be prepared first to ensure that all the parameters are correctly in place. This is done by the PrepareCommand class.

Prepare_Component

Figure 4. Diagram for PrepareCommand

After preparing the user input and ensuring that all necessary parameters are in place, the respective prepareCommand classes will return a command which will be executed by traKCAL. Below shows all the different Command classes inherited.

Command_Component

Figure 4. Diagram for Command component


3.6 Storage component

traKCAL saves both user profile data and activity entries in a text file and csv (comma separated values) file respectively.
It also handles the logging file that records down the different types operations or errors that was performed during the program.

Storage_Component

Figure 5. Diagram for Storage component


On program launch:

  1. Storage is initialised and checks for existing saved data.
  2. If saved data exists, Storage will read the saved data and parses them into model objects such as activity lists for the activity data.
  3. Else, if saved data does not exist, Storage will create an empty save file in the tpData directory.
  4. New users will be prompted to create their profile by inputting their details and saved through UserInfoStorage.

On Command execution:


3.7 Exception component

This component contains all the exception classes used in traKCAL.

Exception_Component

Figure 6. Diagram for Exception component


3.8 UserProfile component

This component contains the information such as the user’s name, gender, height, weight, active level and the weight goal.

userProfile

Figure 4. Diagram for UserProfile component



4.0 Implementation

4.1 Create User Profile feature

Current Implementation

The sequence diagram below shows how the components will react to a new user or for a returning user.

CreateNewUserFeature

Figure 7. Components interactions for traKCAL create user profile feature

The following has been omitted from the diagram to increase readability:


Design Considerations



4.2 Shortcut feature

4.2.1 Creating a shortcut

Current Implementation

The sequence diagram below shows how the components in traKCAL work together to create a new shortcut.

Users can create a shortcut with unlimited number of entries in this format: createSet **SHORTCUT_NAME** ...

Some examples include:

createSet **SHORTCUT_NAME** f/ **FOOD_DESCRIPTION** c/ **CALORIE_COUNT** + f/ **FOOD_DESCRIPTION** c/ **CALORIE_COUNT**

createSet **SHORTCUT_NAME** e/ **EXERCISE_DESCRIPTION** c/ **CALORIE_COUNT**

createSet **SHORTCUT_NAME** e/ **EXERCISE_DESCRIPTION** c/ **CALORIE_COUNT** + e/ **EXERCISE_DESCRIPTION** c/ **CALORIE_COUNT** + f/ **FOOD_DESCRIPTION** c/ **CALORIE_COUNT**

createSetFeature

Figure 8. Components interaction for traKCAL create set feature


Design Considerations



4.2.2 Using a shortcut to add to a activity list

Current Implementation

The sequence diagram below shows how the components in traKCAL work together to add entries in a shortcut to the activity list.

Users can call any existing shortcut in this format: addSet **SHORTCUT_NAME**

addSetFeature

Figure 9. Components interaction for traKCAL add set feature


Design Considerations



4.3 Add activity feature

Current Implementation

The adding mechanism is used by AddFoodCommand and AddExerciseCommand to add to the list of date stated in user input. If date is not stated, then it will be added to today’s list.

The following sequence diagram shows how AddFoodCommand is carried out when the user issues add command, in this case, add f/ food c/ 170 d/ 2020-10-22:

Add Food

Figure 10. Component interactions for add food command

AddExerciseCommand diagram has a similar logic.


Design Considerations

Aspect: How to add food/exercise

Current choice: Using single letter words as tags for input commands. (e.g. add f/ jelly c/ 100 d/ 2020-11-09)

Alternative: Using full words as tags for input commands. (e.g. add food/ chicken chop calorie/ 70 date/ 2020-11-08)

Aspect: Input parameters for add food/exercise

Current choice: Input format for adding: add f/ FOOD_DESCRIPTION c/ CALORIE_COUNT <d/ DATE> OR add f/ EXERCISE_DESCRIPTION c/ CALORIE_COUNT <d/ DATE> Where words in CAPS are parameters to be filled by the user and word in are optional. Not including the parameter would add to today's list.

Alternative: Input format for adding: add f/ FOOD_DESCRIPTION c/ CALORIE_COUNT d/ DATE OR add f/ EXERCISE_DESCRIPTION c/ CALORIE_COUNT d/ DATE Where words in CAPS are parameters to be filled by the user.



4.4 Listing feature for find and list commands

The listing mechanism used by ListCommand and FindCommand to display the required list of activities is facilitated by the lastSeenList of class ActivityList. The lastSeenList is the list that the user would see after a list or find command.
The following operations could be applied to the lastSeenList which would change the actual data in the database:

The details of those operations can be found further down.


4.4.1 List

The list command displays the list of entries for the current date while the list <DATE> command displays the list of entries for the date as specified by the parameter.

For example,

Given below is an example usage scenario and how the lastSeenList behaves for different list commands.


Step 1. The user launches the application for the first time. The lastSeenList will be pointed to the ActivityList for today’s date. This means that any edit, delete or move commands will be performed on the ActivityList for today’s date in this case, the date would be 2020-11-12. lastSeenList first state Figure 12. First state of lastSeenList


Step 2. The user executes a list 2020-11-10. This list 2020-11-10 command causes the lastSeenList to be pointed to the actvityList for 2020-11-10. This This means that any edit, delete or move commands will be performed on the activityList for 2020-11-10. lastSeenList second state Figure 13. Second state of lastSeenList


The following sequence diagram shows how the lastSeenList is set after a “list date” command where date is of YYYY-MM-DD or after a “list” command where the date is the current date.

Listing feature for find and list commands

Figure 14. Sequence diagram of setting the lastSeenList after a list command

Design considerations



4.4.2 Find

This listing feature for the find command also uses the lastSeenList which is of ActivityList class.
The lastSeenList is the list that the user would see after a list command.
Using the lastSeenList allows users to make changes e.g delete command using the numbered index of a single find command.

For example,

The editing mechanism is used by the basic find features: FindDescriptionCommand, FindCalorieCommand, as well as the advanced find features: FindAllCommand and FindEitherCommand to look for keywords in the list.

Given below is an example usage scenario and how the lastSeenList for a find command.

Step 1. The user executes a find e/ running This find e/ running command will intialize the lastSeenList to a new ActivityList and is made up of Activities that contains the running keyword as per the command. This lastSeenList will not point to any other activityList in the dayMap hashmap. lastSeenList third state Figure 12. Third state of lastSeenList


The following sequence diagram shows how the lastSeenList is set after a find command.

Find Sequence Diagram

Figure 13. Sequence diagram of setting the lastSeenList after a find command



4.5 Displaying the list after find or list commands

4.5.1 Current implementation

The mechanism used to display the lastSeenList invoked by the list or find commands is facilitated by the listDrawer and findDrawer class respectively. They both work in a similar manner but the list produced by findDrawer has an extra column which contains the dates of the respective entries.

The following sequence diagram shows how the listDrawer class is used to display the lastSeenList.

list_Drawer

Figure 14. Sequence diagram of the usage of listDrawer to display the list

Design considerations



4.6 Edit activity in list feature

4.6.1 Current Implementation

The editing mechanism is used by EditFoodCommand and EditExerciseCommand to amend the current list of activities.

The following Sequence Diagram shows how EditFoodCommand is carried out when the user issues edit command, in this case, edit 1 f/ egg c/ 10:

Edit_Food

Figure 15. Sequence diagram of edit food feature

EditExerciseCommand diagram has a similar logic.


4.6.2 Design considerations

Aspect: How editing is carried out

Current choice: User MUST pull out the list they want to edit to before calling the edit function. list then edit f/ FOOD_DESCRIPTION c/ CALORIE_COUNT OR edit e/ EXERCISE_DESCRIPTION c/ CALORIE_COUNT

Alternative: Adding a date tag in edit: edit f/ FOOD_DESCRIPTION c/ CALORIE_COUNT d/ DATE OR edit e/ EXERCISE_DESCRIPTION c/ CALORIE_COUNT d/ DATE



4.7 Chaining feature

4.7.1 Current Implementation

The chaining mechanism can be used by the various commands available The following are the types of command that can be chained:

The following sequence diagram shows how the chaining works after command is entered:

Chain_Command

Figure 17. Sequence diagram of chaining feature

The following is a diagram on the classes that are allowed to be chained.

Object_Diagram_Of_PrepareCommand

Figure 18. Object diagram of allowed PrepareCommand subclass

The following is a diagram on the classes that are allowed to be chained.

Object_Diagram_Of_Command

Figure 19. Object diagram of allowed Command subclass


4.7.2 Design considerations

Aspect: Which features to chain

Alternative 1 (current choice): Allow only certain features to be chained.

Alternative 2: Allow all features to be chained.



4.8 Move feature

This feature allows the user to manually move an activity from one position to another.

The following sequence diagram shows how the move command is executed, where index1 is the position to be moved from and index 2 is the position to be moved below.

Move_command

Figure 20. Sequence diagram of move feature


Design Considerations


4.9 Graph feature

The graph implementation shows the progress of the daily net calories over the period of 7 days. The GraphProperty class extracts the available days from the stored data in the application.

The days are sorted accordingly and the latest 7 days are chosen from the sorted list. The GraphProperty class extracts these data and calculates the attributes needed to build the graph. The GraphDrawing class makes use of these properties to draw the graph.

Examples of graph properties include:

  1. Maximum/minimum calories
  2. Calorie interval
  3. 2-Dimensional array representation of the graph

Graph_Sequence_Diagram

Figure 21. Sequence diagram of move feature

As shown above, when the execute command of GraphCommand is called, the GraphProperty object is created, the properties of the graph are then stored and calculated in setProperty function.

Next, the graphDrawing object is created and uses the properties calculated earlier to print out the graph.

In the case where there are less than 7 days stored, all the days will be displayed.



4.10 Delete feature

The delete feature consists of delete by index and delete all commands. Delete by index deletes the activities one at a time while the delete all deletes all the activities for the current day.

Delete_Sequence_Diagram

Figure 22. Sequence diagram of delete by index feature

As shown above, when the DeleteByIndexCommand is executed, the deleteActivity method is called from the DayMap class where the ActivityList containing the intended activities to be deleted is selected and calls removeActivity method to remove the specific activity from the ActivityList.

The sequence diagram for the Delete all is very similar to this diagram where the whole ActivityList is cleared instead of one Activity. The resulting list will be empty.



5.0 Appendix: Requirements

5.1 Product scope

5.1.1 Target user profile

{Describe the target user profile}


5.1.2 Value proposition

{Describe the value proposition: what problem does it solve?}


5.2 User Stories

Version As a … I want to … So that I can …
v1.0 new user see usage instructions refer to them when I forget how to use the application
v1.0 user add food consumed/exercise done keep track of my daily activities
v1.0 user list out the activities done for the day track it and amend it if any errors occur
v1.0 user delete entries entered remove erroneous entries
v1.0 forgetful user find activities via keyword pull out the entries that I want
v1.0 beginner in working out track the calories intake feel assured that my workout is on the right track
v1.0 student who is a health enthusiast keep track of my daily intake of calories better manage my health
v2.0 gym user upload the amount of calories consumed or lost track the surplus or deficit of calories
v2.0 overweight student calculate the estimated amount of calories lost facilitate my weight loss regime
v2.0 underweight student calculate the estimated amount of calories gained facilitate my weight gain regime
v2.0 weight conscious person track the amount of calories gained or lost maintain my weight
v2.0 careless student go back and edit entries entered earlier correct the errors I have made
v2.0 frequent user have pre-set repetitive actions entered by me save time when inputting data
v2.0 lazy user be able to chain input save time when inputting data


5.3 Non-Functional Requirements

{Give non-functional requirements}

  1. Should work on any mainstream OS as long as it has Java 11 or above installed.
  2. A user with above average typing speed for regular English text (i.e. not code, not system admin commands) should be able to accomplish most of the tasks faster using commands than using the mouse.


5.4 Glossary


5.5 Instructions for manual testing

{Give instructions on how to do a manual product testing e.g., how to load sample data to be used for testing}

Starting up application

  1. Ensure that you have Java 11 or above installed, if not, it can be found here
  2. Down the latest version of traKCAL from here
  3. Create an empty folder in a convenient location eg. Desktop and copy jar file over to it.
  4. Open command window/terminal in that window and navigate into the file directory,
  5. Run the command java -jar {filename}.jar e.g., java -jar traKCAL.jar.
  6. Upon successful run, you will get the following greeting message.
====================================================================================
| Hello from                                                                       |
|  _                  _  __   ___     _     _                                      |
| | |_   _ _   __ _  | |/ /  / __|   /_\   | |                                     |
| |  _| | '_| / _` | | ' <  | (__   / _ \  | |__                                   |
|  \__| |_|   \__,_| |_|\_\  \___| /_/ \_\ |____|                                  |
|                                                                                  |
| Hello! I'm traKCAL.                                                              |
| Please do input 'help' for the commands and their respective input format.       |
====================================================================================
  1. Enter help to view help list containing the features, and their respective input format.
  2. For a detailed list on the available features, please refer to user guide

Exiting the application

  1. To terminate traKCAL, enter bye. A successful terminating of application would look like this:
=====================================================================================================
| Thank you for using traKCAL. See you again!                                                       |
=====================================================================================================

Editing user profile

Editing user name and gender

Editing user activity level

Incorrect inputs to try:


Creating a shortcut

Creating a shortcut with 2 food entries

Creating a shortcut with 1 exercise entry

Creating a shortcut with 1 food entry and 1 exercise entry

Incorrect inputs to try:


Adding a shortcut into list

Adding a shortcut

Incorrect inputs to try:


Adding an entry into list

Adding a food entry with date

Adding a food entry without date

Adding an exercise entry with date

Adding an exercise entry without date

Incorrect inputs to try:


Editing an entry in list

This feature allows editing of list entry from:

  1. food to food
  2. food to exercise
  3. exercise to food
  4. exercise to exercise

Prerequisite: The index that the user want to edit on has to exist in the list.

Editing an entry in today’s list from food to food

Editing an entry in today’s list from food to exercise

Editing an entry in another day’s list from exercise to exercise

Editing an entry in another day’s list from exercise to food

Incorrect inputs to try:


Chaining of features

This feature allows only 4 features to be chained, add, list, edit and graph. There is no fixed format as there are many combinations available! Input commands MUST be separated by &&

Example 1

Example 2

Example 3

Example 4

Incorrect inputs to try:

Find feature

Finding an entry using find d/

Finding an entry using find c/

Finding an entry using find a/

Finding an entry using find e/

Incorrect inputs to try:

Deleting Activities

This feature has two further sub features, delete by index and delete all. Both delete features require at least one activity to be in the list Deletion of entry can further by checked by list command.

Deleting 2nd entry from a list with 2 items

Deleting all entries from the list with some activities in list.

Incorrect Input: Deleting on an empty list or invalid index:

Deleting with invalid description:

Graph features

Shows upto 7 days of net calories.

There is no data at all.

List Feature

Listing the activities for today

Listing the activities for a specific day

Incorrect inputs to try:

Move feature

Moving an activity from the 1st position to the 4th position

Moving an activity from the 4th position to the 1st position

Other incorrect commands to try