forked from nus-cs2103-AY1920S1/addressbook-level3
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implements stats feature #114
Merged
Merged
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
8e8b85c
Add StatsCommandParser
jietung 294c0dc
Add StatsCommand
jietung 970a84b
Add methods in ParseUtil
jietung eda80c9
Add prefix in CliSyntax
jietung 8b28d1d
Add StatsFactory
jietung b96a2a6
Add Statistic
jietung aa4114a
Add default statistic
jietung 8a8fb14
Add BarChartPanel
jietung 24d8594
Add LineChartPanel
jietung 7dbc682
Add PieChartPanel
jietung 1972b2b
Refactor code
jietung ff3e256
Add javadoc and refactor code
jietung 3564cb3
Add update statistic when model is edited
jietung e0bbb5c
Merge branch 'master' into stats
jietung 48787f4
Merge branch 'master' into stats
jietung d21a9f5
Refactor code for statistic in model
jietung 7f08e47
Add statistic methods in modelstub in test
jietung d7fe210
Edit values return for barchart
jietung 5c84bc7
Add javadoc comments
jietung e09f656
Add newline at EOF in fxml
jietung 9437726
Merge branch 'master' into stats
jietung 5d3ba34
Add restrictions to number of days between start date and end date fo…
jietung f3acd64
Refactor code
jietung a7109bc
Update user guide
jietung b27e29b
Merge branch 'master' into stats
jietung 7f8bd44
Add newline at EOF in data/exercisedatabases.json
jietung 6b52ef9
Change strings in ParserUtil and store as final String in Date and St…
jietung 84b5db1
Merge branch 'master' into stats
jietung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
101 changes: 101 additions & 0 deletions
101
src/main/java/seedu/exercise/logic/commands/statistic/Statistic.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,101 @@ | ||
package seedu.exercise.logic.commands.statistic; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.exercise.commons.util.CollectionUtil.requireAllNonNull; | ||
|
||
import java.util.ArrayList; | ||
|
||
import seedu.exercise.model.property.Date; | ||
|
||
/** | ||
* Represents a Statistic with data needed to generate chart. | ||
*/ | ||
public class Statistic { | ||
private String category; | ||
private String chart; | ||
private Date startDate; | ||
private Date endDate; | ||
private ArrayList<String> properties; | ||
private ArrayList<Double> values; | ||
|
||
/** | ||
* Every field must be present and not null. | ||
*/ | ||
public Statistic(String category, String chart, Date startDate, Date endDate, | ||
ArrayList<String> properties, ArrayList<Double> values) { | ||
requireAllNonNull(category, chart, startDate, endDate, properties, values); | ||
this.category = category; | ||
this.chart = chart; | ||
this.startDate = startDate; | ||
this.endDate = endDate; | ||
this.properties = properties; | ||
this.values = values; | ||
} | ||
|
||
/** | ||
* Resets the existing data of this {@code Statistic} with {@code newStatistic}. | ||
*/ | ||
public void resetData(Statistic newStatistic) { | ||
requireNonNull(newStatistic); | ||
setCategory(newStatistic.getCategory()); | ||
setChart(newStatistic.getChart()); | ||
setStartDate(newStatistic.getStartDate()); | ||
setEndDate(newStatistic.getEndDate()); | ||
setProperties(newStatistic.getProperties()); | ||
setValues(newStatistic.getValues()); | ||
} | ||
|
||
private void setCategory(String category) { | ||
requireNonNull(category); | ||
this.category = category; | ||
} | ||
|
||
private void setChart(String chart) { | ||
requireNonNull(chart); | ||
this.chart = chart; | ||
} | ||
|
||
private void setStartDate(Date startDate) { | ||
requireNonNull(startDate); | ||
this.startDate = startDate; | ||
} | ||
|
||
private void setEndDate(Date endDate) { | ||
requireNonNull(endDate); | ||
this.endDate = endDate; | ||
} | ||
|
||
private void setProperties(ArrayList<String> properties) { | ||
requireNonNull(properties); | ||
this.properties = properties; | ||
} | ||
|
||
private void setValues(ArrayList<Double> values) { | ||
requireNonNull(values); | ||
this.values = values; | ||
} | ||
|
||
public String getCategory() { | ||
return category; | ||
} | ||
|
||
public String getChart() { | ||
return chart; | ||
} | ||
|
||
public Date getStartDate() { | ||
return startDate; | ||
} | ||
|
||
public Date getEndDate() { | ||
return endDate; | ||
} | ||
|
||
public ArrayList<String> getProperties() { | ||
return properties; | ||
} | ||
|
||
public ArrayList<Double> getValues() { | ||
return values; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/seedu/exercise/logic/commands/statistic/StatsCommand.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,65 @@ | ||
package seedu.exercise.logic.commands.statistic; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_CATEGORY; | ||
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_CHART; | ||
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_END_DATE; | ||
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_START_DATE; | ||
|
||
import seedu.exercise.logic.commands.Command; | ||
import seedu.exercise.logic.commands.CommandResult; | ||
import seedu.exercise.model.Model; | ||
import seedu.exercise.model.ReadOnlyResourceBook; | ||
import seedu.exercise.model.property.Date; | ||
import seedu.exercise.model.resource.Exercise; | ||
|
||
/** | ||
* Generate statistic with given parameters. | ||
*/ | ||
public class StatsCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "stats"; | ||
|
||
public static final String MESSAGE_STATS_DISPLAY_SUCCESS = "Chart displayed."; | ||
|
||
public static final String MESSAGE_USAGE = "Parameters: " | ||
+ PREFIX_CATEGORY + "CATEGORY " | ||
+ PREFIX_CHART + "CHART TYPE " | ||
+ PREFIX_START_DATE + "START DATE " | ||
+ PREFIX_END_DATE + "END DATE " + "\n" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_CATEGORY + "calories " | ||
+ PREFIX_CHART + "barchart " | ||
+ PREFIX_START_DATE + "30/03/2019 " | ||
+ PREFIX_END_DATE + "05/04/2019 "; | ||
|
||
private final String chart; | ||
private final String category; | ||
private final Date startDate; | ||
private final Date endDate; | ||
|
||
/** | ||
* Creates a StatsCommand to generate statistic. | ||
*/ | ||
public StatsCommand(String chart, String category, Date startDate, Date endDate) { | ||
this.chart = chart; | ||
this.category = category; | ||
this.startDate = startDate; | ||
this.endDate = endDate; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
requireNonNull(model); | ||
ReadOnlyResourceBook<Exercise> exercises = model.getExerciseBookData(); | ||
StatsFactory statsFactory = new StatsFactory(exercises, chart, category, startDate, endDate); | ||
Statistic statistic = statsFactory.generateStatistic(); | ||
model.setStatistic(statistic); | ||
return new CommandResult(MESSAGE_STATS_DISPLAY_SUCCESS); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be slightly more descriptive about this comment. Maybe "Returns the Statistic object currently in focus" or something that describe its purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done