forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from marcus-ny/branch-add-analytics-command
Add analytics command
- Loading branch information
Showing
8 changed files
with
123 additions
and
3 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
src/main/java/seedu/address/logic/commands/AnalyticsCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Analytics; | ||
import seedu.address.model.person.Person; | ||
|
||
/** | ||
* Represents a command to view the loans analytics data associated with a contact. | ||
*/ | ||
public class AnalyticsCommand extends Command { | ||
public static final String COMMAND_WORD = "analytics"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Analytics generated"; | ||
private final Index targetIndex; | ||
|
||
public AnalyticsCommand(Index targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Person> lastShownList = model.getFilteredPersonList(); | ||
|
||
if (targetIndex.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Person targetPerson = lastShownList.get(targetIndex.getZeroBased()); | ||
model.updateFilteredLoanList(loan -> loan.isAssignedTo(targetPerson) && loan.isActive()); | ||
Analytics targetAnalytics = Analytics.getAnalytics(model.getUniqueLoanList()); | ||
// TODO: Implement analytics GUI display logic | ||
return new CommandResult(MESSAGE_SUCCESS + targetAnalytics, false, false, true); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof AnalyticsCommand)) { | ||
return false; | ||
} | ||
|
||
AnalyticsCommand otherViewLoanCommand = (AnalyticsCommand) other; | ||
return targetIndex.equals(otherViewLoanCommand.targetIndex); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("targetIndex", targetIndex) | ||
.toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/seedu/address/logic/parser/AnalyticsCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.AnalyticsCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new AnalyticsCommand object | ||
*/ | ||
public class AnalyticsCommandParser implements Parser<AnalyticsCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the AnalyticsCommand | ||
* and returns an AnalyticsCommand object for execution. | ||
* | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public AnalyticsCommand parse(String args) throws ParseException { | ||
try { | ||
Index index = ParserUtil.parseIndex(args); | ||
return new AnalyticsCommand(index); | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
MESSAGE_INVALID_COMMAND_FORMAT, pe); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters