Skip to content

Commit

Permalink
Merge pull request #96 from butteredyakiimo/branch-stats
Browse files Browse the repository at this point in the history
Change stats to 2dp
  • Loading branch information
nananakx-x authored Nov 2, 2023
2 parents d9a10f1 + dadb7f7 commit 8535aad
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 39 deletions.
31 changes: 20 additions & 11 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Valid cases:
<div markdown="span" class="alert alert-warning">
:exclamation: <b>Important:</b> <br/>
Duplicate fosterers cannot be added; this is detected by the fosterer's name.</br>
e.g. <code>"Anne Tay"</code> is the same person as <code>"anne tay"</code> and <code>"anne tay"</code>.
e.g. <code>"Anne Tay"</code> is the same person as <code>"anne tay"</code> and <code>"anne (multiple spaces) tay"</code>.
</div>

Examples:
Expand Down Expand Up @@ -170,7 +170,7 @@ Alias: `find`

<div markdown="block" class="alert alert-info">

**:information_source: Notes about this command:**<br>
**:information_source: Notes about the command:**<br>

* The keywords are case-insensitive.

Expand Down Expand Up @@ -384,26 +384,34 @@ Format: `sort`
![Sort](images/screenshots/Sort.png)

### Viewing Statistics of Available Fosterers : `stats avail`
Displays statistics about fosterers who are available to foster, and the animals they can foster.

Format: `stats avail`

<div markdown="span" class="alert alert-warning">:exclamation: <b>Caution:</b><br/>
All statistic commands are calculated based on the currently displayed list.
Displays statistics about fosterers who are available to foster, and the animals they can foster. Percentages are calculated to 2 decimal places.

If you enter `find avail` before `stats avail`, the resulting statistic will show that 100% of listed fosterers are available. Hence, please ensure that the current list of fosterers is the desired list you want your statistics to be calculated from.
</div>
Format: `stats avail`

Examples:
* `list` followed by `stats avail`
* calculates statistics of available fosterers, based on all fosterers in the address book.
* `find cat` followed by `stats avail`
* calculates statistics of available fosterers, based on fosterers who are either currently fostering a cat or are able to foster a cat.


<div markdown="span" class="alert alert-warning">:exclamation: <b>Caution:</b><br/>

* All statistic commands are calculated based on the currently displayed list.

If you enter `find avail` before `stats avail`, the resulting statistic will show that 100% of listed fosterers are available. Hence, please ensure that the current list of fosterers is the desired list you want your statistics to be calculated from.

* Percentages may not add up to 100.00%.

For example, there are 3 available fosterers: 1 is able to foster a dog, 1 is able to foster a cat, and 1 is unknown. The calculated percentages will be all be 33.33%, adding up to 99.99%. It can be assumed that each group takes up 1/3 out of 100.00%.
</div>

![Stats](images/screenshots/StatsAvail.png)


### Viewing Statistics of Current Fosterers : `stats current`
Displays statistics about fosterers who are currently fostering, and the type of animals they are fostering.
Displays statistics about fosterers who are currently fostering, and the type of animals they are fostering. Percentages are calculated to 2 decimal places.

Format: `stats current`

Expand All @@ -413,11 +421,12 @@ Examples:
* `find dog` followed by `stats current`
* calculates statistics of current fosterers, based on fosterers who are either currently fostering a dog, or are able to foster a dog.

![Stats](images/screenshots/StatsCurr.png)
![Stats](images/screenshots/StatsCurrent.png)


### Viewing Housing Statistics : `stats housing`
Displays statistics about fosterers who are living in a HDB, Condo or Landed.
Percentages are calculated to 2 decimal places.

Format: `stats housing`

Expand Down
Binary file modified docs/images/screenshots/StatsAvail.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 removed docs/images/screenshots/StatsCurr.png
Binary file not shown.
Binary file added docs/images/screenshots/StatsCurrent.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/screenshots/StatsHousing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
*/
public class StatsAvailCommand extends StatsCommand {
public static final String COMMAND_WORD = "avail";
public static final String MESSAGE_AVAIL_SUMMARY = "%1$d out of %2$d listed are available (%3$.1f%%)!";
public static final String MESSAGE_AVAIL_SUMMARY = "%1$d out of %2$d listed are available (%3$.2f%%)!";

public static final String MESSAGE_AVAIL_DETAILS = "Out of those available, \n"
+ "- %1$d can foster dogs (%2$.1f%%)\n"
+ "- %3$d can foster cats (%4$.1f%%)\n"
+ "- %5$d unknown (%6$.1f%%)";
+ "- %1$d can foster dogs (%2$.2f%%)\n"
+ "- %3$d can foster cats (%4$.2f%%)\n"
+ "- %5$d unknown (%6$.2f%%)";

/**
* Returns a list of available fosterers.
Expand Down Expand Up @@ -67,7 +67,7 @@ public CommandResult execute(Model model) throws CommandException {

List<Person> availableFosterers = getAvailableFosterers(lastShownList);
int availableCount = availableFosterers.size();
float availPercent = calculatePercentage(availableCount, total);
double availPercent = calculatePercentage(availableCount, total);
String resultSummary = String.format(MESSAGE_AVAIL_SUMMARY, availableCount, total, availPercent);

if (availableCount == 0) {
Expand All @@ -78,9 +78,9 @@ public CommandResult execute(Model model) throws CommandException {
int canFosterCatsCount = getAbleCatCount(availableFosterers);
int unknownCount = availableCount - canFosterDogsCount - canFosterCatsCount;

float canFosterDogsPercent = calculatePercentage(canFosterDogsCount, availableCount);
float canFosterCatsPercent = calculatePercentage(canFosterCatsCount, availableCount);
float unknownPercent = calculatePercentage(unknownCount, availableCount);
double canFosterDogsPercent = calculatePercentage(canFosterDogsCount, availableCount);
double canFosterCatsPercent = calculatePercentage(canFosterCatsCount, availableCount);
double unknownPercent = 100.0 - canFosterCatsPercent - canFosterDogsPercent;

String resultDetails = String.format(MESSAGE_AVAIL_DETAILS, canFosterDogsCount, canFosterDogsPercent,
canFosterCatsCount, canFosterCatsPercent, unknownCount, unknownPercent);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/StatsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public abstract class StatsCommand extends Command {
/**
* Calculates the percentage of a numerator and denominator.
*/
protected static float calculatePercentage(int num, int denom) {
protected static double calculatePercentage(int num, int denom) {
assert(denom != 0);
return num / (float) denom * 100;
return num / (double) denom * 100;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
public class StatsCurrentCommand extends StatsCommand {
public static final String COMMAND_WORD = "current";
public static final String MESSAGE_CURRENT_SUMMARY = "%1$d out of %2$d listed are "
+ "currently fostering (%3$.1f%%)!";
+ "currently fostering (%3$.2f%%)!";

public static final String MESSAGE_CURRENT_DETAILS = "- %1$d fostering dogs (%2$.1f%%)\n"
+ "- %3$d fostering cats (%4$.1f%%)";
public static final String MESSAGE_CURRENT_DETAILS = "- %1$d fostering dogs (%2$.2f%%)\n"
+ "- %3$d fostering cats (%4$.2f%%)";

/**
* Returns a list of fosterers who are currently fostering.
Expand Down Expand Up @@ -72,7 +72,7 @@ public CommandResult execute(Model model) throws CommandException {

List<Person> currentFosterers = getCurrentFosterers(lastShownList);
int currentCount = currentFosterers.size();
float currentPercent = calculatePercentage(currentCount, total);
double currentPercent = calculatePercentage(currentCount, total);
String resultSummary = String.format(MESSAGE_CURRENT_SUMMARY, currentCount, total, currentPercent);

if (currentCount == 0) {
Expand All @@ -82,8 +82,8 @@ public CommandResult execute(Model model) throws CommandException {
int fosteringDogsCount = getCurrentDogCount(currentFosterers);
int fosteringCatsCount = getCurrentCatCount(currentFosterers);

float fosteringDogsPercent = calculatePercentage(fosteringDogsCount, currentCount);
float fosteringCatsPercent = calculatePercentage(fosteringCatsCount, currentCount);
double fosteringDogsPercent = calculatePercentage(fosteringDogsCount, currentCount);
double fosteringCatsPercent = 100.0 - fosteringDogsPercent;

String resultDetails = String.format(MESSAGE_CURRENT_DETAILS, fosteringDogsCount,
fosteringDogsPercent, fosteringCatsCount, fosteringCatsPercent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
public class StatsHousingCommand extends StatsCommand {
public static final String COMMAND_WORD = "housing";
public static final String MESSAGE_HOUSING_SUCCESS = "Out of %1$d listed,\n"
+ "- %2$d live in HDB (%3$.1f%%)\n"
+ "- %4$d live in Condo (%5$.1f%%)\n"
+ "- %6$d live in Landed (%7$.1f%%)\n"
+ "- %8$d unknown (%9$.1f%%)";
+ "- %2$d live in HDB (%3$.2f%%)\n"
+ "- %4$d live in Condo (%5$.2f%%)\n"
+ "- %6$d live in Landed (%7$.2f%%)\n"
+ "- %8$d unknown (%9$.2f%%)";

/**
* Returns the number of fosterers who stay in HDB.
Expand Down Expand Up @@ -67,10 +67,10 @@ public CommandResult execute(Model model) throws CommandException {
int landedCount = getLandedCount(lastShownList);
int unknownCount = total - hdbCount - condoCount - landedCount;

float hdbPercent = calculatePercentage(hdbCount, total);
float condoPercent = calculatePercentage(condoCount, total);
float landedPercent = calculatePercentage(landedCount, total);
float unknownPercent = calculatePercentage(unknownCount, total);
double hdbPercent = calculatePercentage(hdbCount, total);
double condoPercent = calculatePercentage(condoCount, total);
double landedPercent = calculatePercentage(landedCount, total);
double unknownPercent = 100.0 - hdbPercent - condoPercent - landedPercent;

String result = String.format(MESSAGE_HOUSING_SUCCESS, total, hdbCount, hdbPercent,
condoCount, condoPercent, landedCount, landedPercent, unknownCount, unknownPercent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public void calculatePercentage() {
});

assertEquals(0.0, StatsCommand.calculatePercentage(0, 10));
assertEquals(3 / (float) 10 * 100, StatsCommand.calculatePercentage(3, 10));
assertEquals(10 / (float) 3 * 100, StatsCommand.calculatePercentage(10, 3));
assertEquals(-9 / (float) 10 * 100, StatsCommand.calculatePercentage(-9, 10));
assertEquals(-9 / (float) -10 * 100, StatsCommand.calculatePercentage(-9, -10));
assertEquals(3 / (double) 10 * 100, StatsCommand.calculatePercentage(3, 10));
assertEquals(10 / (double) 3 * 100, StatsCommand.calculatePercentage(10, 3));
assertEquals(-9 / (double) 10 * 100, StatsCommand.calculatePercentage(-9, 10));
assertEquals(-9 / (double) -10 * 100, StatsCommand.calculatePercentage(-9, -10));
}
}

0 comments on commit 8535aad

Please sign in to comment.