forked from nus-cs2103-AY1920S1/addressbook-level3
-
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.
* Add StatsCommandParser * Add StatsCommand * Add methods in ParseUtil * Add prefix in CliSyntax * Add StatsFactory * Add Statistic * Add default statistic * Add BarChartPanel * Add LineChartPanel * Add PieChartPanel * Refactor code * Add javadoc and refactor code * Add update statistic when model is edited * Refactor code for statistic in model * Add statistic methods in modelstub in test * Edit values return for barchart * Add javadoc comments * Add newline at EOF in fxml * Add restrictions to number of days between start date and end date for stats command * Refactor code * Update user guide * Add newline at EOF in data/exercisedatabases.json * Change strings in ParserUtil and store as final String in Date and Statistic Closes #71, closes #72 and closes #73
- Loading branch information
1 parent
ff18877
commit 780bbaa
Showing
29 changed files
with
1,148 additions
and
8 deletions.
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
106 changes: 106 additions & 0 deletions
106
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,106 @@ | ||
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 { | ||
|
||
public static final String MESSAGE_INVALID_CATEGORY = "Category can only be \'exercise\' or \'calories\'"; | ||
public static final String MESSAGE_INVALID_CHART_TYPE = "Chart type can only be \'piechart\' or " | ||
+ "\'linechart\' or \'barchart\'"; | ||
|
||
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.