Skip to content

Commit

Permalink
Add ability to list transactions for last N days and add spending hab…
Browse files Browse the repository at this point in the history
…it message to time insights list
  • Loading branch information
chydarren committed Oct 31, 2022
1 parent 378d4e8 commit ec2ab77
Showing 6 changed files with 146 additions and 73 deletions.
7 changes: 5 additions & 2 deletions src/main/java/seedu/duke/Ui.java
Original file line number Diff line number Diff line change
@@ -136,12 +136,15 @@ public static void showTimeInsightsList(String list, String message, String inco
* @param incomeMessage A string containing the formatted income amount.
* @param expenseMessage A string containing the formatted expense amount.
* @param savingsMessage A string containing the formatted savings amount.
* @param spendingHabitComment A string containing the formatted spending habit comment.
* @param budgetMessage A string containing the formatted budget amount.
* @param budgetAdvice A string containing the formatted budget advice.
*/
public static void showTimeInsightsList(String list, String message, String incomeMessage,
String expenseMessage, String savingsMessage, String budgetMessage, String budgetAdvice) {
printMessages(message, list, incomeMessage, expenseMessage, savingsMessage, budgetMessage, budgetAdvice);
String expenseMessage, String savingsMessage, String budgetMessage, String spendingHabitComment,
String budgetAdvice) {
printMessages(message, list, incomeMessage, expenseMessage, savingsMessage, budgetMessage,
spendingHabitComment, budgetAdvice);
}

//@@author chydarren
32 changes: 20 additions & 12 deletions src/main/java/seedu/duke/command/StatsCommand.java
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@
import static seedu.duke.common.InfoMessages.INFO_INCOME;
import static seedu.duke.common.InfoMessages.INFO_SAVINGS;
import static seedu.duke.common.InfoMessages.INFO_BUDGET;
import static seedu.duke.common.InfoMessages.INFO_SPENDING_HABIT;
import static seedu.duke.common.InfoMessages.INFO_STATS_CATEGORY;
import static seedu.duke.common.InfoMessages.INFO_STATS_EMPTY;
import static seedu.duke.common.InfoMessages.INFO_STATS_EXPENDITURE_HEADER;
@@ -200,33 +201,40 @@ public void statsTypeCategoricalSavingsOrMonthlyExpenditure(TransactionList tran
* Produces info strings, list of categories and summary statistics.
*
* @param transactions An instance of the TransactionList class.
* @param ui An instance of the Ui class.
*/
public void statsTypeTimeInsights(TransactionList transactions) {
public void statsTypeTimeInsights(TransactionList transactions, Ui ui) {
ArrayList<Transaction> timeTransactions = getTimeTransactions(transactions);
String timeInsightsList = transactions.listTimeStats(timeTransactions, year, month, period, number);

if (timeInsightsList.isEmpty()) {
statsLogger.log(Level.INFO, "Time insights list is empty as there are no transactions available.");
Ui.showInfoMessage(INFO_STATS_EMPTY.toString());
ui.showInfoMessage(INFO_STATS_EMPTY.toString());
return;
}

// summary values
ArrayList<String> amounts;
amounts = transactions.processTimeSummaryStats(timeTransactions);
ArrayList<String> timeInsightsValues;
timeInsightsValues = transactions.processTimeSummaryStats(timeTransactions);

String incomeMessage = INFO_STATS_EXPENDITURE_HEADER + LINE_SEPARATOR.toString()
+ String.format("%s%s%s", INFO_INCOME, COLON_SPACE, DOLLAR_SIGN) + amounts.get(0);
String expensesMessage = String.format("%s%s%s", INFO_EXPENSE, COLON_SPACE, DOLLAR_SIGN) + amounts.get(1);
String savingsMessage = String.format("%s%s%s", INFO_SAVINGS, COLON_SPACE, DOLLAR_SIGN) + amounts.get(2);
+ String.format("%s%s%s", INFO_INCOME, COLON_SPACE, DOLLAR_SIGN) + timeInsightsValues.get(0);
String expensesMessage = String.format("%s%s%s", INFO_EXPENSE, COLON_SPACE, DOLLAR_SIGN)
+ timeInsightsValues.get(1);
String savingsMessage = String.format("%s%s%s", INFO_SAVINGS, COLON_SPACE, DOLLAR_SIGN)
+ timeInsightsValues.get(2);
String habitMessage = String.format("%s%s%s", INFO_SPENDING_HABIT, COLON_SPACE, timeInsightsValues.get(3));

printTimeInsightsStatistics(timeInsightsList, amounts, incomeMessage, expensesMessage, savingsMessage);
printTimeInsightsStatistics(timeInsightsList, timeInsightsValues, incomeMessage, expensesMessage,
savingsMessage, habitMessage);

assert !timeInsightsList.isEmpty();
statsLogger.log(Level.INFO, "Time insights list has info available for the specified time period.");

}

//@@author wcwy

/**
* Prints the statistics for time insights based on the parameters chosen.
*
@@ -237,19 +245,19 @@ public void statsTypeTimeInsights(TransactionList transactions) {
* @param savingsMessage A string containing the formatted savings.
*/
private static void printTimeInsightsStatistics(String timeInsightsList, ArrayList<String> amounts,
String incomeMessage, String expensesMessage, String savingsMessage) {
String incomeMessage, String expensesMessage, String savingsMessage, String spendingHabitComment) {

if (containMonthYear() == CONTAIN_BOTH) {
// Information on budget is only displayed when displaying a specific month's time insights
// Information on spending habit and budget displayed only when displaying a specific month's time insights
String budgetMessage = String.format("%s%s%s", INFO_BUDGET, COLON_SPACE, DOLLAR_SIGN) + Budget.getBudget();

long budgetLeft = Budget.calculateBudgetLeft(Long.parseLong(amounts.get(1)));
String budgetAdvice = Budget.generateBudgetAdvice(budgetLeft, Budget.hasExceededBudget(budgetLeft));

Ui.showTimeInsightsList(timeInsightsList, INFO_STATS_TIME_INSIGHTS.toString(), incomeMessage,
expensesMessage, savingsMessage, budgetMessage, budgetAdvice);
expensesMessage, savingsMessage, budgetMessage, spendingHabitComment, budgetAdvice);
//@@author paullowse
} else {
//@@author paullowse
Ui.showTimeInsightsList(timeInsightsList, INFO_STATS_TIME_INSIGHTS.toString(), incomeMessage,
expensesMessage, savingsMessage);
}
6 changes: 5 additions & 1 deletion src/main/java/seedu/duke/common/Constants.java
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@ public class Constants {
public static final int MAXIMUM_STATS_NUMBER = 100;
public static final int MINIMUM_STATS_NUMBER = 1;


//@@author wcwy

/*
@@ -28,6 +27,11 @@ public class Constants {
// One million transactions is the capacity allowed
public static int MAX_TRANSACTIONS_COUNT = 1000000;

//@@author chydarren

// An amount that has no value in it
public static int NO_AMOUNT_VALUE = 0;

//@@author chinhan99

// The amount of one transaction is allowed to be in the range of 1 <= x <= 10000000
7 changes: 4 additions & 3 deletions src/main/java/seedu/duke/common/InfoMessages.java
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ public enum InfoMessages {
INFO_EXPENSE("Expense"),
INFO_SAVINGS("Savings"),
INFO_BUDGET("Budget"),
INFO_SPENDING_HABIT("Spending Habit"),
INFO_DIVIDER("____________________________________________________________"),
INFO_ADD_EXPENSE("I have added the following Expense transaction:"),
INFO_ADD_INCOME("I have added the following Income transaction:"),
@@ -27,17 +28,17 @@ public enum InfoMessages {
INFO_LIST("Here are your transaction records:"),
INFO_LIST_EMPTY("There are no transaction records found."),
INFO_LIST_FILTERED("Here are the transaction records that match your search expression:"),
INFO_LIST_UNFILTERED("There are no transaction records that match your search expression."),
INFO_LIST_FILTERED_EMPTY("There are no transaction records that match your search expression."),
INFO_STATS_EMPTY("There are no statistics available yet for the given statistics type."),
INFO_STATS_CATEGORY("Here are your net categorical savings:"),
INFO_STATS_MONTHLY("Here are your requested monthly statistics:"),
INFO_STATS_MONTHLY("Here is a summary of your monthly expenditure:"),
INFO_STATS_HABIT_VERY_HIGH_SAVINGS("Excellent! You saved quite a lot this month."),
INFO_STATS_HABIT_HIGH_SAVINGS("Wow, keep up the good work. You saved at least two-third of your income."),
INFO_STATS_HABIT_MEDIUM_SAVINGS("Good effort, you saved at least half of your income."),
INFO_STATS_HABIT_LOW_SAVINGS("Hmm, you are spending more than 50% of what you earned. "
+ "Do strike a balance between what you earn and what you spend for better savings!"),
INFO_STATS_HABIT_VERY_LOW_SAVINGS("You spent way more than what you have earned for the current month. "
+ "Please spend wisely based on your income"),
+ "Please spend wisely based on your income."),
INFO_STATS_TIME_INSIGHTS("Here are the categorical savings and expenditure summary for"),
INFO_STATS_CATEGORIES_HEADER("-----Categorical Savings-----"),
INFO_STATS_EXPENDITURE_HEADER("-----Expenditure Summary-----"),
Loading

0 comments on commit ec2ab77

Please sign in to comment.