Skip to content

Commit

Permalink
Merge pull request #185 from ngoivanessa/v2.0
Browse files Browse the repository at this point in the history
update DG
  • Loading branch information
ngoivanessa authored Nov 5, 2021
2 parents 642dfe1 + 5f81da2 commit e2ba463
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 24 deletions.
68 changes: 59 additions & 9 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
&nbsp;&nbsp;[3.2. UI component](#32-ui-component) <br>
&nbsp;&nbsp;[3.3. Parser component](#33-parser-component) <br>
&nbsp;&nbsp;[3.4. Command component](#34-command-component) <br>
&nbsp;&nbsp;[3.5. IngredientList component](#35-ingredientlist-component) <br>
&nbsp;&nbsp;[3.6. Storage component](#36-storage-component) <br>
&nbsp;&nbsp;[3.5. IngredientGroup component](#35-ingredientgroup-component) <br>
&nbsp;&nbsp;[3.6. IngredientList component](#36-ingredientlist-component) <br>
&nbsp;&nbsp;[3.7. Storage component](#37-storage-component) <br>
[4. Implementation](#4-implementation) <br>
&nbsp;&nbsp;[4.1. Alerts](#41-alerts) <br>
&nbsp;&nbsp;[4.2. Deleting Ingredients](#42-deleting-ingredients) <br>
&nbsp;&nbsp;[4.1. Adding Ingredients](#41-adding-ingredients) <br>
&nbsp;&nbsp;[4.2. Alerts](#42-alerts) <br>
&nbsp;&nbsp;[4.3. Delete Ingredients](#43-deleting-ingredients) <br>
[5. Product scope](#5-product-scope) <br>
[6. User stories](#6-user-stories) <br>
[7. Non-functional requirements](#7-non-functional-requirements) <br>
Expand Down Expand Up @@ -79,7 +81,8 @@ The App consists of 6 major components:
* `UI`: Class that deals with the interaction with the user.
* `Parser`: Class that processes inputs and executes commands.
* `Command`: A set of classes covering the functionalities of the App.
* `IngredientList`: Class that holds the information of ingredients.
* `IngredientGroup`: Class that holds all entries of a single ingredient.
* `IngredientList`: Class that holds the list of all ingredients in the inventory. It is made up of multiple instances of `IngredientGroup`.
* `Storage`: Reads data from, and writes data

**Interaction between architecture components**
Expand Down Expand Up @@ -117,7 +120,28 @@ A quick overview of how a command is parsed and executed is as such:
* `parseXYZCommand()` creates an instance of the corresponding `XYZCommand` class and calls its `run()` method.
* Thus, the command entered by the user is executed.

### 3.5. IngredientList component
###3.5 IngredientGroup component
The **IngredientGroup** component can be found in the `ingredients` package

An instance `IngredientGroup` is created for each new ingredient.
A new ingredient is defined as one with a different name as compared to all existing ingredients.

Each instance of `IngredientGroup` is made up multiple `Ingredient`. One entry in an `IngredientGroup` corresponds to one `Ingredient`.
All entries with the same ingredient name is stored in the same `IngredientGroup`.

In the example below, there are 2 `IngredientGroup`, Carrot and White Carrot. Carrot contains 2 `Ingredient` (entries) while White Carrot contains 3 `Ingredient` (entries).
```
1. Carrot | Total Amount: 12.2 kg
Amount Left: 10.0 kg | Expiry Date: 23/12/2021
Amount Left: 2.2 kg | Expiry Date: 25/12/2021
2. White Carrot | Total Amount: 17.1 kg
Amount Left: 5.0 kg | Expiry Date: 25/12/2021
Amount Left: 2.1 kg | Expiry Date: 12/11/2021
Amount Left: 10.0 kg | Expiry Date: 01/02/2022
```

### 3.6. IngredientList component

The **IngredientList** component can be found in the `ingredients` package

Expand All @@ -132,7 +156,7 @@ The `IngredientList` class

Each of the `Ingredient` objects contains information about an ingredient, namely its `name`, `amount` in stock and the `expiry` date.

### 3.6. Storage component
### 3.7. Storage component

The **Storage** component can be found in the `Storage` package

Expand All @@ -151,7 +175,33 @@ of the storage class only when there is a change in the ingredient list of the p

## 4. Implementation

### 4.1. Alerts
### 4.1. Adding Ingredients
Ingredients can be added using the `add` command followed by 3 parameters prefixed with flags for identification by SITUS:
* `n/`: Name of the ingredient
* `a/` : Amount of the ingredient (kg)
* `e/` : Expiry date of the ingredient (DD/MM/YYYY)

E.g. `add n/carrots a/200 e/25-12-2021`

1. The initial user input is stored as an entire string. It is first processed by the `Parser` class. `Parser` first checks for the validity of the input.
If valid, it then breaks the user input into an array of 3 elements and converts the parameters into their appropriate variable types.


2. The array containing the parameters are then passed to the `AddCommand` class which calls the `add` method in `IngredientList`.


3. First, `isIngredientInList(ingredientName)` method in `IngredientList' checks if the new ingredient to be added is repeated. The ingredient name is used as the key to search.
* If the ingredient already exists in the ingredient list, the `get(ingredientIndex)` method searches for the index of the corresponding group that the ingredient belongs to, and appends the ingredient details to the end of the current ingredient group.
* If the ingredient does not exist in the ingredient list, a new `IngredientGroup` is created.


4. The updated `IngredientList` is stored in the external memory through the `Storage` class.

The overall sequence diagram can be seen below.
![image](images/AddSequenceDiagram.png)


### 4.2. Alerts

Alerts are displayed automatically on startup, and when the user enters the command to display alerts. There are 3 types of commands:
* `alerts all`: displays alerts for both alert types below
Expand Down Expand Up @@ -191,7 +241,7 @@ For `AlertLowStockCommand`, it is less complicated, and the sequence diagram sho
The `totalAmount` for each `IngredientGroup` in the `IngredientList` is obtained and compared to the threshold amount. The
information of the `IngredientGroup` is taken note of to be printed when the function is returned.

### 4.2. Deleting ingredients
### 4.3. Deleting ingredients

Delete is performed on individual ingredients in groups. For example, the current ingredient inventory is
```
Expand Down
93 changes: 93 additions & 0 deletions docs/diagrams/AddSequenceDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
@startuml
'https://plantuml.com/sequence-diagram
!include style.puml


Participant "<<class>> Parser" as parser PARSER_COLOUR
Participant ":AddCommand" as add COMMAND_COLOUR
Participant ":IngredientList" as ingredient_list INGREDIENTLIST_COLOUR
Participant ":IngredientGroup" as ingredient_group INGREDIENTGROUP_COLOUR
Participant ":Ingredient" as ingredientClass INGREDIENT_COLOUR
Participant ":Storage" as storage STORAGE_COLOUR


-> parser: parse ("add a/carrot n/200 e/ 25/12/2021")
activate parser PARSER_COLOUR

parser -> parser : parseAddCommand("a/carrot n/200 e/ 25/12/2021")
activate parser PARSER_COLOUR

parser -> add **: AddCommand(ingredient)
activate add COMMAND_COLOUR
return

parser -> add : run()
activate add COMMAND_COLOUR

add -> ingredient_list : getInstance()
activate ingredient_list INGREDIENTLIST_COLOUR
return instance

add -> ingredient_list : add(ingredient)
activate ingredient_list INGREDIENTLIST_COLOUR

ingredient_list -> ingredientClass : getName()
activate ingredientClass INGREDIENT_COLOUR
return ingredientName

ingredient_list -> ingredient_list : isIngredientInList(ingredientName)
activate ingredient_list INGREDIENTLIST_COLOUR
return isRepeatedName

alt !isRepeatedName
ingredient_list -> ingredient_group **: IngredientGroup()
activate ingredient_group INGREDIENTGROUP_COLOUR
return newIngredientGroup

ingredient_list -> ingredient_list : add(newIngredientGroup)
activate ingredient_list INGREDIENTLIST_COLOUR
return

ingredient_list -> ingredient_group : setIngredientGroupName(ingredientName)
activate ingredient_group INGREDIENTGROUP_COLOUR
return

ingredient_list -> ingredient_group : add (ingredient)
activate ingredient_group INGREDIENTGROUP_COLOUR
return


else isRepeatedName
ingredient_list -> ingredient_list : findIngredientIndexInList(ingredientName)
activate ingredient_list INGREDIENTLIST_COLOUR
return ingredientIndex

ingredient_list -> ingredient_list : get(ingredientIndex)
activate ingredient_list INGREDIENTLIST_COLOUR
return
ingredient_list -> ingredient_group : add(ingredient)
activate ingredient_group INGREDIENTGROUP_COLOUR
return
end

ingredient_list -> storage : writeIngredientsToMemory(ingredientList)
activate storage STORAGE_COLOUR
return

return

return resultMsg
return resultMsg
return CLI message











@enduml
9 changes: 5 additions & 4 deletions docs/diagrams/IngredientListDiagram.puml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@startuml
!include style.puml
hide circle
skinparam classAttributeIconSize 0
skinparam arrowColor #Crimson
Expand All @@ -10,12 +11,12 @@ skinparam class {


Package "IngredientList"<<RECTANGLE>>{
class IngredientList #DeepSkyBlue
class IngredientGroup #DeepSkyBlue
class Ingredient #DeepSkyBlue
class IngredientList INGREDIENTLIST_COLOUR
class IngredientGroup INGREDIENTGROUP_COLOUR
class Ingredient INGREDIENT_COLOUR
}

class Storage #GoldenRod
class Storage STORAGE_COLOUR

IngredientList --> "0..*" IngredientGroup
IngredientGroup : totalAmount: Double
Expand Down
2 changes: 1 addition & 1 deletion docs/diagrams/ParserDiagram.puml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ abstract class Command #pink {
+ {abstract} run() : String
}

class Parser #deepSkyBlue {
class Parser #F3722C {
- {static} parseXYZCommand(command : String) : String
}

Expand Down
3 changes: 3 additions & 0 deletions docs/diagrams/SysArch Diagram.puml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Package "SITUS"<<Rectangle>>{
Class Command COMMAND_COLOUR
Class IngredientList INGREDIENTLIST_COLOUR
Class Main MAIN_COLOUR
Class IngredientGroup INGREDIENTGROUP_COLOUR
}

Class "<$user>" as User
Expand All @@ -24,6 +25,8 @@ Command -l[COMMAND_COLOUR]-> UI
IngredientList -r[INGREDIENTLIST_COLOUR]-> Storage
Storage -r[STORAGE_COLOUR]..> LocalStorage
Storage -l[STORAGE_COLOUR]..> IngredientList
IngredientList -d[INGREDIENTLIST_COLOUR]-> IngredientGroup
IngredientGroup -u[INGREDIENTGROUP_COLOUR]-> IngredientList

'UI -d--> Main
'Main -r--> Parser
Expand Down
20 changes: 10 additions & 10 deletions docs/diagrams/style.puml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
' https://plantuml-documentation.readthedocs.io/en/latest/formatting/color-names.html#all-color-names
'/

!define UI_COLOUR #LimeGreen
!define PARSER_COLOUR #Orchid
!define PARSER_COLOUR_S1 #Magenta
!define INGREDIENTLIST_COLOUR #DeepSkyBlue
!define INGREDIENTGROUP_COLOUR #SkyBlue
!define INGREDIENT_COLOUR #LightBlue
!define STORAGE_COLOUR #GoldenRod
!define COMMAND_COLOUR #Red
!define UI_COLOUR #F9C74F
!define PARSER_COLOUR #F3722C
!define PARSER_COLOUR_S1 #Orchid
!define INGREDIENTLIST_COLOUR #43AA8B
!define INGREDIENTGROUP_COLOUR #90BE6D
!define INGREDIENT_COLOUR #EAEFBD
!define STORAGE_COLOUR #577590
!define COMMAND_COLOUR #F8961E
!define COMMAND_COLOUR_S1 #Pink
!define COMMAND_COLOUR_S2 #DarkSalmon
!define DATE_COLOUR #Khaki
!define MAIN_COLOUR #Grey
!define DATE_COLOUR #7C4E7E
!define MAIN_COLOUR #F94144

skinparam MinClassWidth 50
skinparam MaxClassWidth 200
Expand Down
Binary file added docs/images/AddSequenceDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/SysArch Diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/java/seedu/situs/ingredients/IngredientList.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public static ArrayList<IngredientGroup> getIngredientList() {
return ingredientList;
}

//@@author ngoivanessa
/**
* Uses ingredient name as key to search if ingredient currently exists in ingredient list.
*
Expand All @@ -90,6 +91,7 @@ public boolean isIngredientInList(String ingredientName) {
return false;
}

//@@author ngoivanessa
/**
* Uses ingredient name as key to find the index of the corresponding ingredient.
* in the ingredient list.
Expand All @@ -107,6 +109,7 @@ public int findIngredientIndexInList(String ingredientName) {
return -1;
}

//@@author ngoivanessa
/**
* Adds ingredient to ingredient list.
*
Expand Down Expand Up @@ -212,6 +215,7 @@ public Ingredient removeIngredientFromGroup(int groupNumber, int ingredientNumbe
return removedIngredient;
}

//@@author ngoivanessa
/**
* Get ingredient group based on ingredient number (i.e. all duplicates of the same ingredient).
*
Expand Down

0 comments on commit e2ba463

Please sign in to comment.