-
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
Conversation
# Conflicts: # src/main/java/seedu/exercise/logic/commands/AddExerciseCommand.java # src/main/java/seedu/exercise/logic/commands/DeleteExerciseCommand.java # src/main/java/seedu/exercise/logic/commands/EditCommand.java
# Conflicts: # src/main/java/seedu/exercise/logic/parser/ParserUtil.java
# Conflicts: # src/main/java/seedu/exercise/logic/Logic.java # src/main/java/seedu/exercise/logic/LogicManager.java # src/main/java/seedu/exercise/logic/parser/ExerciseBookParser.java # src/main/java/seedu/exercise/model/Model.java # src/main/java/seedu/exercise/model/ModelManager.java
/** | ||
* Update statistic about deleted exercise. | ||
*/ | ||
private void updateStatistic(Model model) { |
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.
you can consider placing this method in the model class and just call model.updateStatistics()
.
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.
if (startDate == null && endDate == null) { | ||
this.startDate = Date.getOneWeekBeforeToday(); | ||
this.endDate = Date.getToday(); | ||
} else { |
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.
Please document this null behaviour well. Include it in the documentation
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
* Generates and returns statistic for different chart type. | ||
*/ | ||
public Statistic generateStatistic() { | ||
HashMap<String, Double> data; |
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.
what is this hashmap for?
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.
Deleted. I forgot to delete.
|
||
return generatePieChartStatistic(); | ||
|
||
} else { //barchart |
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.
you may want to add else if (chart.equals("barchart"))
and a else
block that throws an exception
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.
may want to consider using switch case to make it easier to read
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
public static final Prefix PREFIX_STARTDATE = new Prefix("s/"); | ||
public static final Prefix PREFIX_ENDDATE = new Prefix("e/"); |
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.
START_DATE
and END_DATE
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
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
import java.util.ArrayList; | ||
|
||
/** | ||
* Represents an Exercise's date in ExerHealth. |
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.
Change the documentation here to reflect what the date now does. It is no longer just an Exercise's date
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
* Returns today's Date. | ||
*/ | ||
public static Date getToday() { | ||
LocalDate today = LocalDate.now(ZoneId.of("Asia/Singapore")); |
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.
you may want to use ZoneId.systemDefault()
instead of hardcoding our zone
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
barChart.setTitle(statistic.getCategory() + " (" + statistic.getStartDate() | ||
+ " to " + statistic.getEndDate() + ")"); |
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.
May want to abstract this portion out into a Util
class so all your xxxPanels
can use it to format the title text.
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
public StatisticBuilder() { | ||
this.category = DEFAULT_CATEGORY; | ||
this.chart = DEFAULT_CHART; | ||
this.startDate = new Date(DEFAULT_START_DATE); | ||
this.endDate = new Date(DEFAULT_END_DATE); | ||
this.properties = new ArrayList<>(); | ||
this.values = new ArrayList<>(); | ||
} | ||
|
||
public Statistic build() { | ||
return new Statistic(category, chart, startDate, endDate, properties, values); |
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.
This is not how a builder would look like. This is more of a get a default statistics. Look at #96 under CustomPropertyBuilder
to see how it would look like
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
/** | ||
* Compute exercise count with filtered exercises list. | ||
*/ | ||
private HashMap<String, Double> getTotalExerciseCount() { |
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.
Maybe you can just return a list
of double
and abstract out the methods. The getTotalExerciseCount()
is very similar to getTotalExerciseQuantity()
. Entirely up to you if you wish to change
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.
To minimize confusion between this method and the one below, can consider calling this getTotalExerciseFrequency()
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.
Changed to getTotalExerciseFrequency()
@@ -79,6 +80,11 @@ | |||
*/ | |||
void setGuiSettings(GuiSettings guiSettings); | |||
|
|||
/** | |||
* Returns the Statistic. | |||
*/ |
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
StatsFactory statsFactory = new StatsFactory(exercises, chart, category, startDate, endDate); | ||
Statistic statistic = statsFactory.generateStatistic(); | ||
model.updateStatistic(statistic); | ||
return new CommandResult("Chart displayed"); |
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 consider replacing this magic literal with a MESSAGE_STATS_DISPLAY_SUCCESS
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
/** | ||
* Compute exercise count with filtered exercises list. | ||
*/ | ||
private HashMap<String, Double> getTotalExerciseCount() { |
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.
To minimize confusion between this method and the one below, can consider calling this getTotalExerciseFrequency()
int numberOfDaysApart = Date.numberOfDaysBetween(startDate, endDate); | ||
|
||
if (numberOfDaysApart > 31) { | ||
throw new ParseException("Start date and end date are too far apart"); |
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.
Might want to specify what's the max difference in the error messages. Also, better to store the error messages in a static final String. Same for below
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
} else if (argMultimap.arePrefixesPresent(PREFIX_ENDDATE) | ||
&& !argMultimap.arePrefixesPresent(PREFIX_STARTDATE)) { //only end date present | ||
|
||
throw new ParseException("Start date must be provided."); |
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 simply use "Start date must be provided with end date" for both
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
} else if (chart.equals("linechart")) { | ||
chartPlaceholder.getChildren().add(new LineChartPanel(statistic).getRoot()); | ||
} else { | ||
chartPlaceholder.getChildren().add(new PieChartPanel(statistic).getRoot()); |
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.
else if (chart.equals("piechart")) {
} else {
// Default chart / some text to show chart display error
}
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
ReadOnlyResourceBook<Exercise> exercises = model.getExerciseBookData(); | ||
Statistic outdatedStatistic = model.getStatistic(); | ||
StatsFactory statsFactory = new StatsFactory(exercises, outdatedStatistic.getChart(), | ||
outdatedStatistic.getCategory(), outdatedStatistic.getStartDate(), outdatedStatistic.getEndDate()); |
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.
May want to implement a constructor in StatsFactory that takes in exercises and an outdatedStatistic object so that you don't violate Law of Demeter.
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.
I have moved this method to model.
private String chart; | ||
private String category; | ||
private Date startDate; | ||
private Date endDate; |
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.
May want to implement immutable variables instead
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
|
||
return generatePieChartStatistic(); | ||
|
||
} else { //barchart |
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.
may want to consider using switch case to make it easier to read
String trimmedEndDate = endDate.trim(); | ||
parseDate(trimmedEndDate); | ||
if (!Date.isEndDateAfterStartDate(startDate.toString(), trimmedEndDate)) { | ||
throw new ParseException("End date must be before "); |
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.
ParseException should be "End date must be before start date"?
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
if (eDate.compareTo(sDate) < 0) { | ||
return false; | ||
} else { | ||
return true; |
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 simplify this expression to:
return eDate.compareTo(sDate) >= 0
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
|
||
if (d.compareTo(sDate) >= 0 && d.compareTo(eDate) <= 0) { | ||
return true; | ||
} |
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 simplify this expression as well
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
|
||
throw new ParseException("Start date must be provided."); | ||
|
||
} |
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.
what if both start date and end date are not present?
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.
it will set start day as a week before today's date and end date as today's date
ArrayList<Double> values = new ArrayList<>(); | ||
|
||
for (String n : names) { | ||
values.add(data.get(n)); |
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 expressed as:
return new ArrayList<>(data.values())
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.
I need it to correspond to the list of strings, so i did it this way.
/** | ||
* Compute exercise quantity with filtered exercises list. | ||
*/ | ||
private HashMap<String, Double> getTotalExerciseQuantity() { |
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.
Naming of this method (and getTotalExerciseCount) can be misleading.
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.
i have changed it to getTotalExerciseFrequency()
StatsFactory statsFactory = new StatsFactory(exercises, chart, category, startDate, endDate); | ||
Statistic statistic = statsFactory.generateStatistic(); | ||
model.updateStatistic(statistic); | ||
return new CommandResult("Chart displayed"); |
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.
May want to store the message in CommandResult as a private final String MESSAGE_SUCCESS in this class.
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
# Conflicts: # src/main/java/seedu/exercise/logic/parser/CliSyntax.java # src/main/java/seedu/exercise/logic/parser/ParserUtil.java # src/main/java/seedu/exercise/model/Model.java # src/main/java/seedu/exercise/model/ModelManager.java # src/test/java/seedu/exercise/logic/commands/AddExerciseCommandTest.java
@@ -143,7 +147,7 @@ public static Date parseEndDate(Date startDate, String endDate) throws ParseExce | |||
String trimmedEndDate = endDate.trim(); | |||
parseDate(trimmedEndDate); | |||
if (!Date.isEndDateAfterStartDate(startDate.toString(), trimmedEndDate)) { | |||
throw new ParseException("End date must be before "); | |||
throw new ParseException("End date must be after start date"); |
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.
Would be better if the message is stored in a final String MESSAGE_INVALID_END_DATE in the ParserUtil class or Date class
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.
👍
# Conflicts: # src/main/java/seedu/exercise/logic/parser/CliSyntax.java # src/main/java/seedu/exercise/model/Model.java
No description provided.