Skip to content

Conversation

@Aditya-gam
Copy link
Contributor

@Aditya-gam Aditya-gam commented Oct 9, 2025

Description

This PR implements a new donutChartData object in the volunteer statistics API to provide three mutually exclusive volunteer categories for improved donut chart visualization and accurate reporting. Additionally, it includes critical bug fixes to prevent application crashes when no Blue Square data exists.

Implements: Volunteer Status Donut Chart with Mutually Exclusive Categories
Screenshot 2025-10-09 at 1 28 03 PM

Related PRs (if any):

Main changes explained:

  1. Added donutChartData Object (src/helpers/overviewReportHelper.js)

    • Introduced a new donutChartData object in the getVolunteerNumberStats function response
    • Contains three mutually exclusive volunteer categories:
      • existingActive: Active volunteers who are not new (calculated as activeVolunteers - newVolunteers)
      • newActive: New volunteers created within the date range
      • deactivated: All inactive volunteers
    • Each category includes:
      • count: The number of volunteers in that category
      • percentageOutOfTotal: Rounded percentage (2 decimal places) calculated against total volunteers
      • comparisonPercentage (optional): Growth/decline percentage when comparison dates are provided.
  2. Added Comparison Data for Donut Chart (src/helpers/overviewReportHelper.js)

    • Implemented comparison percentage calculations for all three donut chart categories when comparisonStartDate and comparisonEndDate are provided
    • Uses the existing calculateGrowthPercentage helper function for consistency
    • Properly handles edge cases (division by zero, no comparison data)
  3. Bug Fix: Added Optional Chaining for Blue Square Stats (src/helpers/overviewReportHelper.js)

    • Added optional chaining (?.) and default values (|| 0) to prevent crashes when no Blue Square infringement data exists
    • Ensures graceful handling of empty datasets without application errors

The implementation ensures:

  • activeVolunteers.count = donutChartData.existingActive.count + donutChartData.newActive.count
  • totalVolunteers.count = activeVolunteers.count + deactivatedVolunteers.count
  • donutChartData.existingActive.count + donutChartData.newActive.count + donutChartData.deactivated.count = totalVolunteers.count
  • All percentages sum to approximately 1.00 (allowing for rounding)
  • No negative counts are possible

How to test:

Prerequisites:

  1. Check out the current branch: Aditya-fix/volunteer-status-donut-chart-percentages
  2. Reinstall dependencies using rm -rf node_modules package-lock.json && npm cache clean --force
  3. Run npm install to install dependencies
  4. Start the backend server: npm run dev
  5. Ensure MongoDB is running with volunteer data

Test Cases:

API Testing Instructions:
Check

  • Local server running on port 4500
  • Valid authentication token
  • API testing tool (Postman, curl, etc.)

Test 1: Basic Request (No Comparison)

Request:

  • Method: GET
  • URL: http://localhost:4500/api/reports/volunteerstats?startDate=2024-01-01&endDate=2024-12-31
  • Headers: Authorization Bearer token, Content-Type: application/json

Verify:

  1. Response contains donutChartData object with three categories: existingActive, newActive, deactivated
  2. Each category has count and percentageOutOfTotal fields
  3. No comparisonPercentage fields present
  4. activeVolunteers.count equals existingActive.count + newActive.count

Test 2: With Comparison Dates

Request:

  • URL: http://localhost:4500/api/reports/volunteerstats?startDate=2024-01-01&endDate=2024-12-31&comparisonStartDate=2023-01-01&comparisonEndDate=2023-12-31
  • Same headers as Test 1

Verify:

  1. All three donut chart categories include the comparisonPercentage field
  2. Values show growth/decline or "No Comparison Data"

Test 3: Mathematical Consistency

Using any successful response, verify:

  1. activeVolunteers.count === (existingActive.count + newActive.count)
  2. totalVolunteers.count === (activeVolunteers.count + deactivatedVolunteers.count)
  3. Sum of all donut chart counts equals totalVolunteers.count
  4. Sum of donut chart percentages ≈ 1.00 (within 0.02)
  5. All count values ≥ 0

Test 4: Missing Parameters

Request:

  • URL: http://localhost:4500/api/reports/volunteerstats (no query params)

Verify:

  • Status: 400
  • Error: "Please provide a start and end date."

Screenshots or videos of changes:

TestingVideo.mov

Note:

  • Search for donutChartData in the JSON response object to verify the data.

- Add donutChartData object with three categories: existingActive, newActive, deactivated
- Include count, percentageOutOfTotal, and optional comparisonPercentage for each category
- Calculate existingActive as activeVolunteers minus newVolunteers to prevent double counting
- Add comparison percentage support for all donut chart categories
- Fix: Add optional chaining to Blue Square stats to prevent crashes on empty data
- Ensure all percentages sum to 1.00 and maintain mathematical consistency
- Backward compatible: existing API fields remain unchanged
@RitzzzZ2021
Copy link
Contributor

RitzzzZ2021 commented Oct 13, 2025

Test locally. Test 3 failed, and others work perfectly. Please look into the Error in Test 3.

Test 1: Basic Request (No Comparison) >> pass

  • Response contains donutChartData object with three categories: existingActive, newActive, deactivated
  • Each category has count and percentageOutOfTotal fields
  • No comparisonPercentage fields present
  • activeVolunteers.count equals existingActive.count + newActive.count
image

Test 2: With Comparison Dates >> pass

  • All three donut chart categories include the comparisonPercentage field
  • Values show growth/decline or "No Comparison Data"
image

Test 3: Edge Case - No Data (Blue Square Bug Fix) >> not pass

  • Server returns message: Error occured while fetching data.
  • TypeError: Cannot read properties of undefined (reading 'totalHours')
image

Test 4: Mathematical Consistency >> pass

All verified:

  • activeVolunteers.count === (existingActive.count + newActive.count)
  • totalVolunteers.count === (activeVolunteers.count + deactivatedVolunteers.count)
  • Sum of all donut chart counts equals totalVolunteers.count
  • Sum of donut chart percentages ≈ 1.00 (within 0.02)
  • All count values ≥ 0

Test 5: Missing Parameters >> pass

  • Status: 400
  • Error: "Please provide a start and end date."
image

Copy link

@Aswin20010 Aswin20010 left a comment

Choose a reason for hiding this comment

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

Reviewed PR #4191+1794 update that introduces support for the new donutChartData structure in the Volunteer Status chart. Verified correct extraction of nested .count properties from existingActive, newActive, and deactivated categories, along with backward compatibility for the legacy data format. Confirmed updated chart labels (“Existing Active,” “New Active,” and “Deactivated”) accurately reflect volunteer status categories and display proper color coding. Tested hybrid data access logic with optional chaining and default values to ensure no rendering or NaN% errors occur. Validated that the metric cards continue to function using the original data structure without regression. Conducted end-to-end testing under Dashboard → Reports → Total Organization Summary after clearing cache and reinstalling dependencies. Checked percentage accuracy, total count display, and dynamic updates upon changing date ranges. No UI, data, or logic issues found — approved the PR.
Screenshot 2025-10-20 at 2 43 51 PM
Screenshot 2025-10-20 at 2 44 12 PM
Screenshot 2025-10-20 at 2 45 06 PM

@Aditya-gam
Copy link
Contributor Author

Test locally. Test 3 failed, and others work perfectly. Please look into the Error in Test 3.

Test 1: Basic Request (No Comparison) >> pass

  • Response contains donutChartData object with three categories: existingActive, newActive, deactivated
  • Each category has count and percentageOutOfTotal fields
  • No comparisonPercentage fields present
  • activeVolunteers.count equals existingActive.count + newActive.count
image **Test 2: With Comparison Dates** >> pass
  • All three donut chart categories include the comparisonPercentage field
  • Values show growth/decline or "No Comparison Data"
image **Test 3: Edge Case - No Data (Blue Square Bug Fix)** >> not pass
  • Server returns message: Error occured while fetching data.
  • TypeError: Cannot read properties of undefined (reading 'totalHours')
image **Test 4: Mathematical Consistency** >> pass

All verified:

  • activeVolunteers.count === (existingActive.count + newActive.count)
  • totalVolunteers.count === (activeVolunteers.count + deactivatedVolunteers.count)
  • Sum of all donut chart counts equals totalVolunteers.count
  • Sum of donut chart percentages ≈ 1.00 (within 0.02)
  • All count values ≥ 0

Test 5: Missing Parameters >> pass

  • Status: 400
  • Error: "Please provide a start and end date."
image

The blue squares fix wasn't a part of this PR. I added that because backend won't work without that. It is not a permenant fix.

Copy link
Contributor

@deep3072 deep3072 left a comment

Choose a reason for hiding this comment

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

All the testcases work as expected:

Testcase 1:
Screenshot 2025-10-24 at 23 43 45

Testcase 2:
Screenshot 2025-10-24 at 23 48 35

Testcase 3:
Screenshot 2025-10-24 at 23 50 28

Testcase 4:
Screenshot 2025-10-24 at 23 52 37

@one-community
Copy link
Member

Thank you all, merging!

@one-community one-community merged commit 0bbeacb into development Nov 17, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants