Skip to content
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

Fixes #71 Implement Analytics class #72

Merged

Conversation

Joseph31416
Copy link

Minor changes to Person class:
Added getAnalytics() method.

Minor changes to DateUtil class:
Added addDay(Date date, int days) method.

Minor changes to Loan class:
Added isOverdue() method.

New Analytics class:
This class handles the analysis of a LoanRecords object.
This class can only be instantiated by calling the static method getAnalytics(LoanRecords loanRecords).
You should not be calling this method directly, instead you should call the getAnalytics() method from the Person class.
This class contains the following fields:

  • numLoans: total number of loans
  • numOverdueLoans: total number of overdue loans
  • numActiveLoans: total number of active loans
  • propOverdueLoans: proportion of loans that are overdue over active loans
  • propActiveLoans: proportion of loans that are active over total loans
  • totalValueLoaned: total value of all loans
  • totalValueOverdue: total value of all overdue loans
  • totalValueActive: total value of all active loans
  • averageLoanValue: average loan value of all loans
  • averageOverdueValue: average loan value of all overdue loans
  • averageActiveValue: average loan value of all active loans
  • earliestLoanDate: earliest loan date of all loans
  • earliestReturnDate: earliest return date of active loans
  • latestLoanDate: latest loan date of all loans
  • latestReturnDate: latest return date of active loans

Copy link

codecov bot commented Mar 24, 2024

Codecov Report

Attention: Patch coverage is 0% with 81 lines in your changes are missing coverage. Please review.

Project coverage is 59.43%. Comparing base (245eb7b) to head (d68397b).

Files Patch % Lines
...ain/java/seedu/address/model/person/Analytics.java 0.00% 75 Missing ⚠️
...main/java/seedu/address/commons/util/DateUtil.java 0.00% 3 Missing ⚠️
src/main/java/seedu/address/model/person/Loan.java 0.00% 2 Missing ⚠️
...c/main/java/seedu/address/model/person/Person.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master      #72      +/-   ##
============================================
- Coverage     62.21%   59.43%   -2.78%     
  Complexity      442      442              
============================================
  Files            84       85       +1     
  Lines          1736     1817      +81     
  Branches        166      178      +12     
============================================
  Hits           1080     1080              
- Misses          611      692      +81     
  Partials         45       45              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@narwhalsilent narwhalsilent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good functional addition to the project. Apart from minor concerns, the only thing requiring immediate change is the comment for the field propOverdueLoans, and maybe using StringBuilder for the long toString().

* @param days The number of days to add.
* @return The new Date object.
*/
public static Date addDay(Date date, int days) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not urgent, but I think we can refactor date representation in our project to use LocalDate or LocalDateTime. It is a more recent API that has more inbuilt methods such as plusDays() which can be used to avoid weird methods such as this,

private int numOverdueLoans; // total number of overdue loans
private int numActiveLoans; // total number of active loans

private float propOverdueLoans; // proportion of loans that are overdue over active loans

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment does not match implementation, which suggests it is proportion of overdue loans over all loans.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, it's fixed.

@@ -57,6 +57,10 @@ public Address getAddress() {
return address;
}

public Analytics getAnalytics() {
return Analytics.getAnalytics(loanRecords);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that each time the analytics are viewed, it is reconstructed. Is it possible to refactor this in the future such that it is maintained and modified?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible, but it's a trade-off between memory and runtime.


@Override
public String toString() {
return "Number of loans: " + numLoans + "\n"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe StringBuilder will be more appropriate since this is a significant number of strings?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, it's standard to just add strings like this since this is a constant operation.

analytics.updateDateFields(loan);
}
analytics.updatePropFields();
analytics.updateAverageFields();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the update methods must be called in a specific order to prevent errors. While it is not a concern now because each Analytics object is effectively immutable and getAnalytics() is the only way of obtaining it, it would be good if this can be addressed so that future iterations do not run into related bugs.

@Joseph31416 Joseph31416 marked this pull request as draft March 24, 2024 13:06
@Joseph31416 Joseph31416 marked this pull request as ready for review March 24, 2024 13:06
Copy link

@narwhalsilent narwhalsilent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@narwhalsilent narwhalsilent merged commit ccf4da6 into AY2324S2-CS2103T-W13-1:master Mar 24, 2024
3 of 5 checks passed
@marcus-ny marcus-ny added this to the v1.3 milestone Mar 24, 2024
@marcus-ny marcus-ny added the priority.High Must do label Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants