Skip to content

Commit

Permalink
Merge branch 'master' into filename-bug-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yeodonghan committed Nov 4, 2019
2 parents b94bf47 + 6a90b48 commit bf3d5ad
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) {

@Override
public void start(Stage primaryStage) {
logger.info("Starting AddressBook " + MainApp.VERSION);
logger.info("Starting Seller Manager Lite " + MainApp.VERSION);
ui.start(primaryStage);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/commons/core/LogsCenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class LogsCenter {
private static final int MAX_FILE_COUNT = 5;
private static final int MAX_FILE_SIZE_IN_BYTES = (int) (Math.pow(2, 20) * 5); // 5MB
private static final String LOG_FILE = "addressbook.log";
private static final String LOG_FILE = "sellerManager.log";
private static Level currentLogLevel = Level.INFO;
private static final Logger logger = LogsCenter.getLogger(LogsCenter.class);
private static FileHandler fileHandler;
Expand Down
23 changes: 19 additions & 4 deletions src/main/java/seedu/address/statistic/StatisticManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.math3.stat.StatUtils;

import javafx.collections.ObservableList;
import javafx.scene.chart.XYChart;
import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.util.MoneyUtil;
import seedu.address.commons.util.StringUtil;
import seedu.address.model.ReadOnlyDataBook;
Expand All @@ -27,18 +29,23 @@
*/
public class StatisticManager implements Statistic {

public StatisticManager() {}
private final Logger logger = LogsCenter.getLogger(StatisticManager.class);

public StatisticManager() {
logger.fine("Initializing statistic module");
}

/*--------------------Methods to calculate--------------------------*/
@Override
public XYChart.Series<String, Number> calculateTotalProfitOnCompletedGraph(ReadOnlyDataBook<Order> orderBook,
StatsPayload statsPayload) {
requireAllNonNull(orderBook, statsPayload);
logger.info("filtering orders from order Book");
//filter the list of orders to be only the orders within the starting and ending date.
List<Order> listOfFilteredOrders = getFilteredOrderListByDate(orderBook,
statsPayload)
.collect(Collectors.toList());

logger.info("calculating list of month");
// returns a list of Months between starting and ending date.
List<Calendar> listOfMonth = DateUtil.getListOfYearMonth(statsPayload);
XYChart.Series<String, Number> series = new XYChart.Series<>();
Expand All @@ -51,18 +58,20 @@ public XYChart.Series<String, Number> calculateTotalProfitOnCompletedGraph(ReadO
.collect(Collectors.toList());

listOfMonthlyProfit.stream().forEach(x -> series.getData().add(x));
logger.info("calculating monthly data of Profit");
return series;
}

@Override
public XYChart.Series<String, Number> calculateTotalRevenueOnCompletedGraph(ReadOnlyDataBook<Order> orderBook,
StatsPayload statsPayload) {
requireAllNonNull(orderBook, statsPayload);
logger.info("filtering orders from order Book");
//filter the list of orders to be only the orders within the starting and ending date.
List<Order> listOfFilteredOrders = getFilteredOrderListByDate(orderBook,
statsPayload)
.collect(Collectors.toList());

logger.info("calculating list of month");
// returns a list of Months between starting and ending date.
List<Calendar> listOfMonth = DateUtil.getListOfYearMonth(statsPayload);

Expand All @@ -76,6 +85,7 @@ public XYChart.Series<String, Number> calculateTotalRevenueOnCompletedGraph(Read
.collect(Collectors.toList());

listOfMonthlyRevenue.stream().forEach(x -> series.getData().add(x));
logger.info("calculating monthly data of Revenue");
return series;
}

Expand All @@ -84,10 +94,11 @@ public XYChart.Series<String, Number> calculateTotalCostOnCompletedGraph(ReadOnl
StatsPayload statsPayload) {
requireAllNonNull(orderBook, statsPayload);
//filter the list of orders to be only the orders within the starting and ending date.
logger.info("filtering orders from order Book");
List<Order> listOfFilteredOrders = getFilteredOrderListByDate(orderBook,
statsPayload)
.collect(Collectors.toList());

logger.info("calculating list of month");
// returns a list of Months between starting and ending date.
List<Calendar> listOfMonth = DateUtil.getListOfYearMonth(statsPayload);

Expand All @@ -101,6 +112,7 @@ public XYChart.Series<String, Number> calculateTotalCostOnCompletedGraph(ReadOnl
.collect(Collectors.toList());

listOfMonthlyCost.stream().forEach(x -> series.getData().add(x));
logger.info("calculating monthly data of Cost");
return series;
}

Expand All @@ -112,6 +124,7 @@ public String calculateTotalProfitOnCompleted(ReadOnlyDataBook<Order> orderBook,
double cost = this.getTotalCost(orderBook, statsPayload);
double totalProfit = revenue - cost;
totalProfit = new BigDecimal(totalProfit).setScale(2, RoundingMode.HALF_UP).doubleValue();
logger.info("calculating total profit");
return String.valueOf(totalProfit);
}

Expand All @@ -120,6 +133,7 @@ public String calculateTotalRevenueOnCompleted(ReadOnlyDataBook<Order> orderBook
requireAllNonNull(orderBook, statsPayload);
double totalRevenue = getTotalRevenue(orderBook, statsPayload);
totalRevenue = new BigDecimal(totalRevenue).setScale(2, RoundingMode.HALF_UP).doubleValue();
logger.info("calculating total Revenue");
return String.valueOf(totalRevenue);
}

Expand All @@ -129,6 +143,7 @@ public String calculateTotalCostOnCompleted(ReadOnlyDataBook<Order> orderBook, S
DecimalFormat format = new DecimalFormat("##.00");
double totalCost = getTotalCost(orderBook, statsPayload);
totalCost = new BigDecimal(totalCost).setScale(2, RoundingMode.HALF_UP).doubleValue();
logger.info("calculating total Cost");
return String.valueOf(totalCost);
}

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ private void handleExit() {
*/
@FXML
private void handleStats(StatsPayload statsPayload) {

if (statsPayload.isDefaultQuery()) {
logger.info("handling default statistics query of type " + statsPayload.getStatisticType());
switch (statsPayload.getStatisticType()) {
case PROFIT:
String totalProfitResult = this.logic.calculateTotalProfit(statsPayload);
Expand All @@ -221,21 +223,26 @@ private void handleStats(StatsPayload statsPayload) {
throw new EnumNotPresentException("Enum not present in stat command");
}
} else {
logger.info("handling statistics query of type "
+ statsPayload.getStatisticType());
//calculate stats with input to logic manager
switch (statsPayload.getStatisticType()) {
case PROFIT:
XYChart.Series<String, Number> profitResult = this.logic.calculateTotalProfitGraph(statsPayload);
this.statsWindow = new StatisticsWindow("Total Profit", profitResult);
logger.info("displaying chart");
this.statsWindow.show();
break;
case REVENUE:
XYChart.Series<String, Number> revenueResult = this.logic.calculateTotalRevenueGraph(statsPayload);
this.statsWindow = new StatisticsWindow("Total Revenue", revenueResult);
logger.info("displaying chart");
this.statsWindow.show();
break;
case COST:
XYChart.Series<String, Number> costResult = this.logic.calculateTotalCostGraph(statsPayload);
this.statsWindow = new StatisticsWindow("Total Cost", costResult);
logger.info("displaying chart");
this.statsWindow.show();
break;
default:
Expand Down Expand Up @@ -270,6 +277,7 @@ private CommandResult executeCommand(String commandText) throws CommandException
private void performUiChanges(CommandResult input) {
List<UiChange> listOfUiChange = input.getUiChange();
for (UiChange type : listOfUiChange) {
logger.info("executing Ui Change " + input.getUiChange().toString());
switch (type) {
case ARCHIVED_ORDER:
this.showArchivedOrderPanel();
Expand Down

0 comments on commit bf3d5ad

Please sign in to comment.