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

Adds a new Statistics Page #940

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft

Adds a new Statistics Page #940

wants to merge 30 commits into from

Conversation

akshat22
Copy link
Collaborator

Description

Adds a new statistics page #871 to Field Book with the following features:

  • Displays multiple stats divided into season cards.
  • Ability to toggle between year and month view.
  • Display additional context on individual stats via dialogs and toast messages.
  • Ability to export individual cards as an image with a Field Book logo by long-pressing the card.
  • Display a calendar style heatmap for the number of observations collected on each day.

Type of change

What type of changes does your code introduce? Put an x in boxes that apply.

  • CHANGE (fix or feature that would cause existing functionality to not work as expected)
  • FEATURE (non-breaking change which adds functionality)
  • BUGFIX (non-breaking change which fixes an issue)
  • ENHANCEMENT (non-breaking change which improves existing functionality)
  • NONE (if none of the other choices apply. Example, tooling, build system, CI, docs, etc.)

Checklist:

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated relevant documentation

Changelog entry

Please add a one-line changelog entry below. This will be copied to the changelog file during the release process.

Added a new statistics page to display summary of collected data.

@akshat22 akshat22 requested a review from chaneylc March 25, 2024 22:00
@chaneylc
Copy link
Member

chaneylc commented Mar 26, 2024

First of all this looks awesome!

  • Replace snackbar message with a share button on each card, alternatively it could be a toolbar button and allow the cards to be selectable.
  • I noticed the statistics_card.xml is fairly complicated, I think you can use grid layout manager / recycler view / adapter pattern here where you define view holders for each stat type, so it's easier to add/adjust stats in the future.
  • image count is only based on "photo", this will only count images captured on the device camera, there are other photo formats like go pro and usb that won't be counted. For now update your logic with the offbeat Formats enum.
  • declare a threshold variable (30) for your total interval check
  • static strings should be replaced with resources
  • Since the stat processing time scales with the amount of data in the database, the activity should start with some sort of "loading stats..." UI while the data processes in the background. I found with large databases it takes a while for the screen to appear after clicking Statistics.
  • @trife do you want this feature wrapped in alpha/beta settings?

Copy link
Member

@chaneylc chaneylc left a comment

Choose a reason for hiding this comment

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

See above comment for requested changes.

@trife
Copy link
Member

trife commented Mar 28, 2024

@akshat22 for the heatmap, you're going to need to either use the heatmap composable or adapt one of the vertical scrolling calendar views.

@akshat22 akshat22 linked an issue Mar 30, 2024 that may be closed by this pull request
11 tasks
@trife
Copy link
Member

trife commented Apr 3, 2024

  • Replace the export icon with this one
  • Cancel previous toast before showing new ones
  • Toast text changes: Entries: "...entries have been phenotyped"; Data: "...observations have been collected"; Time: "...hours spent phenotyping"; Photos: "...photos have been captured"
  • Dialog title changes: "Fields imported in YYYY", use unique ID for title of Most dialog
  • Month view needs a loading dialog while it processes
  • Use month names instead of numbers (e.g. 2024 February)
  • Heatmap: Add toolbar buttons to move calendar to the first day with obs, last day with obs, and select a date range
  • Add the counter icon to the heatmap toolbar: when clicked it swaps the day number in the calendar for the number of observations collected that day
  • Add date range picker that filters calendar view to specified dates
  • Mostly out of curiosity to see how it looks: set the titles of the stat elements to hidden
  • Make sure you use one of the available Field Book text styles for the textviews in this PR
  • How difficult is it to stylize the exported card? It might be good to change the top line of the images to " Field Book Stats for February 2024"
  • Use a tablayout for the stats with "Total", "By Year", and "By Month" tabs. Since this will remove the need to swap back and forth between month/year views, remove the current swap icon and reuse it for the heatmap feature instead of the checkerboard.
  • Swap the icons for fields and plots. Update the icon in ConfigActivity for Fields to match.

@akshat22 akshat22 requested review from chaneylc and trife April 25, 2024 03:01
@chaneylc
Copy link
Member

The Config Activity Fields icon is different, is that on purpose?

Tried to select a date range, I think it crashes if you only have one date:

FATAL EXCEPTION: main (Ask Gemini)
                                                                                                    Process: com.fieldbook.tracker.debug, PID: 26100
                                                                                                    java.lang.NullPointerException: Attempt to invoke virtual method 'int java.util.Calendar.get(int)' on a null object reference
                                                                                                    	at com.fieldbook.tracker.dialogs.DateRangePickerDialog.lambda$onCreateDialog$0$com-fieldbook-tracker-dialogs-DateRangePickerDialog(DateRangePickerDialog.java:60)
                                                                                                    	at com.fieldbook.tracker.dialogs.DateRangePickerDialog$$ExternalSyntheticLambda0.onClick(Unknown Source:2)
                                                                                                    	at androidx.appcompat.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:107)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:232)
                                                                                                    	at android.os.Looper.loop(Looper.java:317)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8501)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)

DataHelper database;
List<String> seasons = new ArrayList<>();
RecyclerView rvStatisticsCard;
private int toggleVariable = 0; // 0: Total, 1: Year, 2: Month
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be best to define an enum here

Date date;

// e.g. '2024-03'
if (cardTitle.length() == 7) {
Copy link
Member

Choose a reason for hiding this comment

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

I think you can use ReyclerView ViewTypes to solve this in a more modular way.

reference: https://stackoverflow.com/questions/26245139/how-to-create-recyclerview-with-multiple-view-types

LocalDate heatMapStartDate, heatMapEndDate;
Calendar dateSelectorStartRange, dateSelectorEndRange;
DateTimeFormatter timeStampFormat;
private static final String TIME_STAMP_PATTERN = "yyyy-MM-dd HH:mm:ss.SSSZZZZZ";
Copy link
Member

Choose a reason for hiding this comment

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

You can reference this in SqlUtil.kt

Comment on lines 279 to 288
private int getColorForObservations(int observations) {
if (observations == 1) {
return 0xFFb2f2bb;
} else if (observations < 5) {
return 0xFF69db7c;
} else if (observations < 8) {
return 0xFF40c057;
} else {
return 0xFF2f9e44;
}
Copy link
Member

Choose a reason for hiding this comment

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

These should be theme attributes. Threshold value magic numbers should be defined as constants.

@akshat22
Copy link
Collaborator Author

The Config Activity Fields icon is different, is that on purpose?

@chaneylc This is in reference to one of Trevor's notes in the previous comment to switch the icons for Fields and Plots.

Tried to select a date range, I think it crashes if you only have one date:

Noted, will fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add "Statistics" page to configActivity
3 participants