reports: consolidate user demographics handling into appendUserDemographics - #10399
Draft
Mutugiii wants to merge 1 commit into
Draft
reports: consolidate user demographics handling into appendUserDemographics#10399Mutugiii wants to merge 1 commit into
Mutugiii wants to merge 1 commit into
Conversation
Decision makers need the age and gender of members alongside the activity rows they export, so every per-member CSV in the manager reports now carries both columns: - Member Visits, Resource Views, Course Views and Courses Progress look the demographics up from the member's profile. - Chat Usage gains Gender and Age (years) columns. - Community Health keeps the age and gender stored on each anonymous examination instead of overwriting them, which previously exported the age of every health record as NaN. Along the way: - appendAge is replaced by appendUserDemographics, which matches members of child planets too (their docs are nested in a doc property, so the old lookup by name silently missed them and left the gender columns of the nation summary export empty). - ageFromBirthDate returns null rather than NaN when there is no usable birth date, and compares the day of the month rather than the day of the week, so a birthday later in the current month no longer counts as reached. - The gender labels of the survey export move to reports.utils so both exports share one source of truth. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012RPeuWgSojRNqiUXXz4mxB
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactors user demographics handling in the reports service by consolidating
appendAgeandappendGenderinto a singleappendUserDemographicsmethod. Extracts gender localization logic into a reusable utility function and improves age calculation to handle edge cases.Key Changes
appendAge()andappendGender()intoappendUserDemographics()to reduce duplication and provide a single entry point for adding user age and gender to activity recordslocalizedGender()utility inreports.utils.tsand reused it insubmissions.service.tsto eliminate duplicate gender formatting logicuserOfActivity()helper method that correctly handles nested user documents (from child planets stored indocproperty)ageFromBirthDate()to acceptDateobjects in addition to timestampsnullinstead ofNaNgetDate()instead ofgetDay()for accurate birthday calculationsreports-detail.component.tsto use the new consolidated method and export gender/age columns for login and AI chat activitiesreports.service.spec.tswith test coverage for the newappendUserDemographicsmethod and added tests forageFromBirthDateedge cases inutils.spec.tsImplementation Details
appendUserDemographicsmethod uses nullish coalescing (??) to preserve existing demographics on records while filling in missing values from user profileslocalizedGender()utility, which handles 'male'/'female' with localization and falls back to proper-cased input for other valueshttps://claude.ai/code/session_012RPeuWgSojRNqiUXXz4mxB