Skip to content

Commit

Permalink
Merge pull request #152 from AY1920S2-CS2103T-W16-1/dev
Browse files Browse the repository at this point in the history
Update master with latest version
  • Loading branch information
BransonNg authored Mar 31, 2020
2 parents cd2debe + 39b5c52 commit e2514bf
Show file tree
Hide file tree
Showing 117 changed files with 4,503 additions and 563 deletions.
31 changes: 31 additions & 0 deletions sample_data/statistics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"dayDatas" : [ {
"date" : "2020-03-17",
"pomDurationData" : "10",
"tasksDoneData" : "2"
}, {
"date" : "2020-03-18",
"pomDurationData" : "0",
"tasksDoneData" : "0"
}, {
"date" : "2020-03-19",
"pomDurationData" : "40",
"tasksDoneData" : "7"
}, {
"date" : "2020-03-20",
"pomDurationData" : "30",
"tasksDoneData" : "4"
}, {
"date" : "2020-03-21",
"pomDurationData" : "70",
"tasksDoneData" : "1"
}, {
"date" : "2020-03-22",
"pomDurationData" : "100",
"tasksDoneData" : "3"
}, {
"date" : "2020-03-23",
"pomDurationData" : "90",
"tasksDoneData" : "2"
} ]
}
36 changes: 24 additions & 12 deletions sample_data/tasklist.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,84 @@
"priority" : "2",
"description" : "123, Jurong West Ave 6, #08-111",
"done" : "Y",
"tagged" : [ "neighbours" ]
"tagged" : [ "neighbours" ],
"reminder": ""
}, {
"name" : "David Li",
"priority" : "2",
"description" : "123, Jurong West Ave 6, #08-111",
"done" : "Y",
"tagged" : [ "family" ]
"tagged" : [ "family" ],
"reminder": ""
}, {
"name" : "Irfan Ibrahim",
"priority" : "1",
"description" : "123, Jurong West Ave 6, #08-111",
"done" : "Y",
"tagged" : [ "classmates" ]
"tagged" : [ "classmates" ],
"reminder": ""
}, {
"name" : "Roy Balakrishnan",
"priority" : "1",
"description" : "123, Jurong West Ave 6, #08-111",
"done" : "Y",
"tagged" : [ "colleagues" ]
"tagged" : [ "colleagues" ],
"reminder": ""
}, {
"name" : "bran",
"priority" : "1",
"description" : "123, Jurong West Ave 6, #08-111",
"done" : "Y",
"tagged" : [ ]
"tagged" : [ ],
"reminder": ""
}, {
"name" : "John Doe",
"priority" : "1",
"description" : "123, Jurong West Ave 6, #08-111",
"done" : "Y",
"tagged" : [ "owesMoney", "friends" ]
"tagged" : [ "owesMoney", "friends" ],
"reminder": ""
}, {
"name" : "John Roe",
"priority" : "3",
"description" : "311, Clementi Ave 2, #02-25",
"done" : "Y",
"tagged" : [ "owesMoney", "friends" ]
"tagged" : [ "owesMoney", "friends" ],
"reminder": ""
}, {
"name" : "Math Homework",
"priority" : "1",
"description" : "Chapter 5, Pages 1 - 3",
"done" : "Y",
"tagged" : [ ]
"tagged" : [ ],
"reminder": ""
}, {
"name" : "Math Homewo",
"priority" : "1",
"description" : "Chapter 5, Pages 1 - 3",
"done" : "N",
"tagged" : [ ]
"tagged" : [ ],
"reminder": ""
}, {
"name" : "Hello world",
"priority" : "1",
"description" : "Chapter 5, Pages 1 - 3",
"done" : "N",
"tagged" : [ "somebodythatiusedtoknow" ]
"tagged" : [ "somebodythatiusedtoknow" ],
"reminder": ""
}, {
"name" : "blabla",
"priority" : "1",
"description" : "Chapter 5, Pages 1 - 3",
"done" : "N",
"tagged" : [ "forschool" ]
"tagged" : [ "forschool" ],
"reminder": ""
}, {
"name" : "Math Homework2",
"priority" : "1",
"description" : "Chapter 5, Pages 1 - 3",
"done" : "N",
"tagged" : [ "forschool" ]
"tagged" : [ "forschool" ],
"reminder": ""
} ]
}
52 changes: 47 additions & 5 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,29 @@
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.Logic;
import seedu.address.logic.LogicManager;
import seedu.address.logic.PetManager;
import seedu.address.logic.PomodoroManager;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.Pet;
import seedu.address.model.Pomodoro;
import seedu.address.model.ReadOnlyPet;
import seedu.address.model.ReadOnlyPomodoro;
import seedu.address.model.ReadOnlyStatistics;
import seedu.address.model.ReadOnlyTaskList;
import seedu.address.model.ReadOnlyUserPrefs;
import seedu.address.model.Statistics;
import seedu.address.model.TaskList;
import seedu.address.model.UserPrefs;
import seedu.address.model.util.SampleDataUtil;
import seedu.address.storage.JsonPetStorage;
import seedu.address.storage.JsonPomodoroStorage;
import seedu.address.storage.JsonStatisticsStorage;
import seedu.address.storage.JsonTaskListStorage;
import seedu.address.storage.JsonUserPrefsStorage;
import seedu.address.storage.PetStorage;
import seedu.address.storage.PomodoroStorage;
import seedu.address.storage.StatisticsStorage;
import seedu.address.storage.Storage;
import seedu.address.storage.StorageManager;
import seedu.address.storage.TaskListStorage;
Expand All @@ -52,6 +57,7 @@ public class MainApp extends Application {
protected Model model;
protected Config config;
protected PomodoroManager pomodoro;
protected PetManager petManager;

@Override
public void init() throws Exception {
Expand All @@ -67,8 +73,16 @@ public void init() throws Exception {
TaskListStorage taskListStorage = new JsonTaskListStorage(userPrefs.getTaskListFilePath());
PetStorage petStorage = new JsonPetStorage(userPrefs.getPetFilePath());
PomodoroStorage pomodoroStorage = new JsonPomodoroStorage(userPrefs.getPomodoroFilePath());
StatisticsStorage statisticsStorage =
new JsonStatisticsStorage(userPrefs.getStatisticsFilePath());

storage =
new StorageManager(taskListStorage, petStorage, pomodoroStorage, userPrefsStorage);
new StorageManager(
taskListStorage,
petStorage,
pomodoroStorage,
statisticsStorage,
userPrefsStorage);

initLogging(config);

Expand All @@ -78,7 +92,13 @@ public void init() throws Exception {

pomodoro = new PomodoroManager();

ui = new UiManager(logic, pomodoro);
petManager = new PetManager();

model.setPomodoroManager(pomodoro);

model.setPetManager(petManager);

ui = new UiManager(logic, pomodoro, petManager);
}

/**
Expand All @@ -92,9 +112,12 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
Optional<ReadOnlyTaskList> taskListOptional;
Optional<ReadOnlyPet> petOptional;
Optional<ReadOnlyPomodoro> pomodoroOptional;
Optional<ReadOnlyStatistics> statisticsOptional;

ReadOnlyTaskList initialData;
ReadOnlyPet initialPet;
ReadOnlyPomodoro initialPomodoro;
ReadOnlyStatistics statistics;

try {
taskListOptional = storage.readTaskList();
Expand Down Expand Up @@ -144,7 +167,24 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
initialPomodoro = new Pomodoro();
}

return new ModelManager(initialData, initialPet, initialPomodoro, userPrefs);
try {
statisticsOptional = storage.readStatistics();
if (!statisticsOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample Statistics");
}
statistics = statisticsOptional.orElse(new Statistics());
} catch (DataConversionException e) {
logger.warning(
"Data file not in the correct format. Will be starting with an empty Statistics");
statistics = new Statistics();
} catch (IOException e) {
logger.warning(
"Problem while reading from the file. Will be starting with an empty Statistics");
statistics = new Statistics();
}

return new ModelManager(
initialData, initialPet, initialPomodoro, statistics, userPrefs);
}

private void initLogging(Config config) {
Expand Down Expand Up @@ -181,7 +221,8 @@ protected Config initConfig(Path configFilePath) {
initializedConfig = new Config();
}

// Update config file in case it was missing to begin with or there are new/unused fields
// Update config file in case it was missing to begin with or there are
// new/unused fields
try {
ConfigUtil.saveConfig(initializedConfig, configFilePathUsed);
} catch (IOException e) {
Expand Down Expand Up @@ -215,7 +256,8 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) {
initializedPrefs = new UserPrefs();
}

// Update prefs file in case it was missing to begin with or there are new/unused fields
// Update prefs file in case it was missing to begin with or there are
// new/unused fields
try {
storage.saveUserPrefs(initializedPrefs);
} catch (IOException e) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public class Messages {
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_INVALID_TASK_TO_BE_DONED =
"Task has already been marked as done!";
public static final String MESSAGE_FIELD_UNKNOWN = "The fields do not exist %1$s";
}
3 changes: 1 addition & 2 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.ReadOnlyTaskList;
import seedu.address.model.task.Task;
import seedu.address.ui.PetDisplayHandler;

/** API of the Logic component */
public interface Logic {
Expand Down Expand Up @@ -41,5 +40,5 @@ public interface Logic {
/** Set the user prefs' GUI settings. */
void setGuiSettings(GuiSettings guiSettings);

PetDisplayHandler getPetDisplayHandler();
void incrementPomExp();
}
12 changes: 8 additions & 4 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import seedu.address.model.ReadOnlyTaskList;
import seedu.address.model.task.Task;
import seedu.address.storage.Storage;
import seedu.address.ui.PetDisplayHandler;

/** The main LogicManager of the app. */
public class LogicManager implements Logic {
Expand Down Expand Up @@ -57,7 +56,12 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
} catch (IOException ioe) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
}
model.updatePetDisplayHandler();

try {
storage.saveStatistics(model.getStatistics());
} catch (IOException ioe) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
}

return commandResult;
}
Expand Down Expand Up @@ -88,7 +92,7 @@ public void setGuiSettings(GuiSettings guiSettings) {
}

@Override
public PetDisplayHandler getPetDisplayHandler() {
return model.getPetDisplayHandler();
public void incrementPomExp() {
model.incrementPomExp();
}
}
Loading

0 comments on commit e2514bf

Please sign in to comment.