Skip to content
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

datn02 PPP update #186

Merged
merged 8 commits into from
Nov 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,20 +243,21 @@ information of the `IngredientGroup` is taken note of to be printed when the fun

### 4.3. Deleting ingredients

Delete is performed on individual ingredients in groups. For example, the current ingredient inventory is
Delete is performed on individual ingredients in groups. Users are to supply the information for the ingredient to delete by
their groups and numbers in the list. For example, the current ingredient inventory is
```
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
1. Carrot | Total Amount: 12.200 kg
1.1. Amount Left: 10.000 kg | Expiry Date: 23/12/2021
1.2. Amount Left: 2.200 kg | Expiry Date: 25/12/2021

2. Potato | Total Amount: 7.1 kg
Amount Left: 5.0 kg | Expiry Date: 25/12/2021
Amount Left: 2.1 kg | Expiry Date: 12/11/2021
2. Potato | Total Amount: 7.100 kg
2.1. Amount Left: 2.100 kg | Expiry Date: 12/11/2021
2.2. Amount Left: 5.000 kg | Expiry Date: 25/12/2021

3. Beef | Total Amount: 5.1 kg
Amount Left: 5.1 kg | Expiry Date: 01/02/2022
3. Beef | Total Amount: 5.100 kg
3.1. Amount Left: 5.100 kg | Expiry Date: 01/02/2022
```
Then calling `delete n/ carrot e/ 25/12/2021` will remove the second entry in the `carrot` category.
Then calling `delete 1.1` will remove the second entry in the `carrot` category.
The sequence diagram below illustrates the above command example

![image](images/DeleteSequenceDiagram.png)
Expand Down
57 changes: 31 additions & 26 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ given is equal to the existing stock of the ingredient, the ingredient is automa
of displaying zero stock for the item.)
If the ingredient has multiple entries, the earliest expiring one will be deducted first, as a good practice for inventory management.

Command: `subtract GROUP_INDEX a/[AMOUNT]`
Command: `subtract [GROUP_INDEX] a/[AMOUNT]`

The parameters used in the command are:

Expand All @@ -206,7 +206,7 @@ ____________________________________________________
You can delete an ingredient from the ingredient list based on its name and expiry date in the list if you wish to stop
tracking it (e.g. if that batch has expired).

Command: `delete GROUP_INDEX.INGREDIENT_INDEX`
Command: `delete [GROUP_INDEX.INGREDIENT_INDEX]`

The parameter used in the command are:
* `GROUP_INDEX`: the index of the group the ingredient to delete is in
Expand Down Expand Up @@ -240,16 +240,16 @@ This is the current list:
list
____________________________________________________
Here is the list of the ingredients currently in inventory:
1. Carrot | Total Amount: 2.000 kg
1.1. Amount Left: 2.000 kg | Expiry Date: 11/11/2021
1. Carrot | Total Amount: 2.000 kg
1.1. Amount Left: 2.000 kg | Expiry Date: 11/11/2021

2. Plum | Total Amount: 7.000 kg
2.1. Amount Left: 2.000 kg | Expiry Date: 05/11/2021
2.2. Amount Left: 5.000 kg | Expiry Date: 12/11/2021
2. Plum | Total Amount: 7.000 kg
2.1. Amount Left: 2.000 kg | Expiry Date: 06/11/2021
2.2. Amount Left: 5.000 kg | Expiry Date: 12/11/2021

3. Pumpkin | Total Amount: 6.000 kg
3.1. Amount Left: 6.000 kg | Expiry Date: 06/11/2021
3.2. Amount Left: 1.000 kg | Expiry Date: 21/11/2021
3. Pumpkin | Total Amount: 6.000 kg
3.1. Amount Left: 6.000 kg | Expiry Date: 06/11/2021
3.2. Amount Left: 1.000 kg | Expiry Date: 21/11/2021
____________________________________________________

```
Expand All @@ -259,10 +259,10 @@ Output:
expire 13/11/2021
____________________________________________________
There are 4 ingredients expiring by: 13/11/2021
Plum | Amount Left: 2.000 kg | Expiry Date: 05/11/2021
Pumpkin | Amount Left: 6.000 kg | Expiry Date: 06/11/2021
Carrot | Amount Left: 2.000 kg | Expiry Date: 11/11/2021
Plum | Amount Left: 5.000 kg | Expiry Date: 12/11/2021
Plum | Amount Left: 2.000 kg | Expiry Date: 06/11/2021
Pumpkin | Amount Left: 6.000 kg | Expiry Date: 06/11/2021
Carrot | Amount Left: 2.000 kg | Expiry Date: 11/11/2021
Plum | Amount Left: 5.000 kg | Expiry Date: 12/11/2021
____________________________________________________
```

Expand All @@ -282,19 +282,19 @@ Outputs:
find carrot
____________________________________________________
I found these ingredients for "carrot":
2. Carrot | Total Amount: 200.000 kg
2.1. Amount Left: 200.000 kg | Expiry Date: 01/03/2022
2. Carrot | Total Amount: 200.000 kg
2.1. Amount Left: 200.000 kg | Expiry Date: 01/03/2022
____________________________________________________
```
```
find potato tomato
____________________________________________________
I found these ingredients for "potato":
1. Potato | Total Amount: 0.600 kg
1.1. Amount Left: 0.600 kg | Expiry Date: 30/12/2021
1. Potato | Total Amount: 0.600 kg
1.1. Amount Left: 0.600 kg | Expiry Date: 30/12/2021
I found these ingredients for "tomato":
4. Tomato | Total Amount: 23.700 kg
4.1. Amount Left: 23.700 kg | Expiry Date: 21/11/2021
4. Tomato | Total Amount: 23.700 kg
4.1. Amount Left: 23.700 kg | Expiry Date: 21/11/2021
____________________________________________________
```

Expand All @@ -314,13 +314,17 @@ Output (using list shown in [Section 2.7](#27-search-ingredients-by-expiry)):
```
alerts expiry
____________________________________________________
No ingredients expiring by 27/10/2021
There are 3 ingredients expiring by: 11/11/2021
Plum | Amount Left: 2.000 kg | Expiry Date: 06/11/2021
Pumpkin | Amount Left: 6.000 kg | Expiry Date: 06/11/2021
Carrot | Amount Left: 2.000 kg | Expiry Date: 11/11/2021
____________________________________________________
alerts stock
____________________________________________________
There are 1 ingredients with stock less than 5.0 kg
Potato | Total Amount: 0.600 kg
1.1. Amount Left: 0.600 kg | Expiry Date: 30/12/2021
There are 1 ingredients with stock less than 10.0 kg
Carrot | Total Amount: 2.000 kg
Plum | Total Amount: 7.000 kg
Pumpkin | Total Amount: 7.000 kg
____________________________________________________
```

Expand Down Expand Up @@ -394,8 +398,9 @@ ____________________________________________________

**Q**: How do I save my ingredient list?

**A**: The ingredient list is automatically saved after any operations that edits its contents. They are saved under
`data\"ingredients.txt"`
**A**: The ingredient list is automatically saved after any operations that edits its contents.
- The ingredient data is saved under `data/ingredients.txt`
- The threshold data for expiry and stock are saved under `data/thresholds.txt`

**Q**: How do I transfer my data to another computer?

Expand Down
16 changes: 6 additions & 10 deletions docs/diagrams/DeleteSequenceDiagram.puml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ Participant ":IngredientGroup" as ingredient_group INGREDIENTGROUP_COLOUR

Participant ":Storage" as storage STORAGE_COLOUR

-> parser : parse("delete n/ carrot e/ 25/12/2021")
-> parser : parse("delete 1.1")
activate parser PARSER_COLOUR

parser -> parser : parseDeleteCommand()
activate parser PARSER_COLOUR_S1

parser -> delete **: DeleteCommand("carrot", "25/12/2021")
parser -> delete **: DeleteCommand(1, 1)
activate delete COMMAND_COLOUR
return

Expand All @@ -26,16 +26,12 @@ delete -> ingredient_list : getInstance()
activate ingredient_list INGREDIENTLIST_COLOUR
return instance

delete -> ingredient_list : removeIngredientFromGroup()
delete -> ingredient_list : removeIngredientFromGroup(1, 1)
activate ingredient_list INGREDIENTLIST_COLOUR

ingredient_list -> ingredient_list : findIngredientIndexInList("carrot")
ingredient_list -> ingredient_list : getIngredientGroup(1)
activate ingredient_list INGREDIENTLIST_COLOUR
return groupIndexToRemove

ingredient_list -> ingredient_group : findIngredientIndexByExpiry(25/12/2021)
activate ingredient_group INGREDIENTGROUP_COLOUR
return ingredientIndexToRemove
return

ingredient_list -> ingredient_group : remove()
activate ingredient_group INGREDIENTGROUP_COLOUR
Expand All @@ -53,4 +49,4 @@ return resultMsg

return CLI message

@enduml
@enduml
Binary file modified docs/images/DeleteSequenceDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 8 additions & 9 deletions docs/team/datn02.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,24 @@ Users interact with in through a CLI, and is written in Java.
- **What it does**: the `Parser` class is responsible for parsing and receiving of commands.
- **Justification**: creating a seperate class to handle parsing and checking commands of user input is one of the recommended approach to OOP code.
2. `Command` abstract class
- **What it does**: the `Command` class provides a template for *all* commands type in the code to inherit. This class include abstract methods, which are modified and implemented a bit differently by each command inheritor.
- **What it does**: the `Command` class provides a template for *all* commands type in the code to inherit.
- **Justification**: Since command are to be run based on user's input, the idea of having the `run` method to be returned the same (`String` type) by all other command class is useful. Therefore, the `Command` class is implemented.
3. `DateCommand` command class
- **What it does**: the `DateCommand` class provides a way to modify/check if the current date/time in the system is correct.
- **Justification**: since ingredient expiry is one of the top priority of this application, wrong date stored in the system could be troublesome when checking the inventory. This command provides a way to fix the wrong date in the system to ensure correct expiry calculation is peformed.
- **Justification**: this command provides a way to fix the wrong date in the system to ensure correct expiry calculation is peformed.
4. `CurrentDate` class
- **What it does**: the `CurrentDate` class provides a way to retrieve/display the current date of the system in the `LocalDate` format.
- **Justification**: this class is used in any command/methods that require calculations of expiry date between food products and current date to get the expiry period. Providing a separate class to retrieve this information is useful, and contributes to the OOP-ness of the code.
- **Justification**: This class is responsible for retrieving current date in the system for expiry calculation.
5. `Storage` class
- **What it does**: the `Storage` class is responsible for writing/reading ingredients data from the memory.
- **Justification**: the ability to read and write ingredient data to a memory file is helpful for long-term ingredient tracking. In addition, re-writing the ingredient data back into the memory file everytime the ingredient list is changed reduces the chance of data corruption in an event of program crashing.
- **Difficulties encountered**: previously, both threshold data and ingredient data are stored in one single data file. In addition, in the PE-d, testers have reported that any invalid lines in the memory file would skip the rest of the ingredient information to add into the database. Therefore, modifying and detecting errors in data file of both threshold and ingredient data is difficult.
- **Solution**: We have split the ingredient and threshold data into separate memory files (credit: @mudkip8). In addition, a check method was added in the `loadIngredientsFromMemory()` method to skip invalid ingredients data lines, while retaining the integrity of the rest of the data file to add into the current ingredient database.
- **Justification**: the ability to read and write ingredient data to a memory file is helpful for long-term ingredient tracking.
- **Difficulties encountered**: in the PE-d, testers have reported that any invalid lines in the memory file would skip the rest of the ingredient information.
- **Solution**: split the ingredient and threshold data into separate memory files. In addition, a check method was added in the `loadIngredientsFromMemory()` method to skip invalid ingredients data lines, while retaining the integrity of the rest of the data file to add into the current ingredient database.
6. `DeleteCommand` class
- **What it does**: this class is responsible for removing ingredients from the database based on the ingredient group number and ingredient number.
- **Justification**: since ingredients of the same name are grouped together, and within groups they are sorted by expiry date, deleting by their numbers in lists and groups provides a faster way to operate this command.
- **Further details**: previously, this command is operated by supplying the ingredient name and expiry date instead of ingredient numbers in the list. This involved checking of the ingredient name, and then checking the matching expiry date in each individual ingredient groups. This method was lengthy and error-prone, and since the ingredients are already sorted accordingly to their name and expiry, the current method of this command is carried out.
- **Justification**: deleting by their numbers in lists and groups provides a faster way to operate this command.
7. Others
- Participated in early stages of `AlertExpiringSoon` command, which later completed by @mudkip8.
- Participated in early stages of `AlertExpiringSoon` command, which later completed by [@mudkip8](https://github.com/mudkip8).
- Added sorting methods in the `IngredientGroup` class.
- Added `add()` and `deleteIngredientFromGroup()` methods in `IngredientList` class for adding and removing ingredients.
- Debugged and fixed `SubtractCommand` and `UpdateCommand` with their respecting methods `subtractIngredientFromGroup()` and `update()` in `IngredientList` class.
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/seedu/situs/Situs.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,14 @@ public static void run() {
UI.printCommandOutput(resultMsg);
}
}
exit();
}

public static void main(String[] args) {
public Situs() {
initialize();
run();
exit();
}

public static void main(String[] args) {
new Situs().run();
}
}
6 changes: 4 additions & 2 deletions src/main/java/seedu/situs/ingredients/IngredientList.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,15 @@ public String subtractIngredientFromGroup(int groupNumber, Double subtractAmount
throw new SitusException(INVALID_SUBTRACT);
}


// remove groups that total amount is approx 0
//@@author datn02
if (Math.abs(currentGroup.getTotalAmount() - subtractAmount) < 0.001) {
ingredientList.remove(groupNumber - 1);
storage.writeIngredientsToMemory(ingredientList);
return subtractedIngredientName;
}

//@@author AayushMathur7
currentGroup.subtractFromTotalAmount(subtractAmount);

while (subtractAmount != 0.0) {
Expand Down Expand Up @@ -206,7 +208,7 @@ public Ingredient removeIngredientFromGroup(int groupNumber, int ingredientNumbe
removedIngredient = getIngredientGroup(groupNumber)
.remove(ingredientNumber);

if (getIngredientGroup(groupNumber).getIngredientGroupSize() < 0.001) {
if (getIngredientGroup(groupNumber).getIngredientGroupSize() <= 0) {
ingredientList.remove(groupNumber - 1);
}

Expand Down