Skip to content

Snehita - Add mock data so every chart on the Total Construction Summary is populated - #2467

Open
snehitakandula wants to merge 4 commits into
developmentfrom
Snehita_mock_data_tcs
Open

snehitakandula wants to merge 4 commits into
developmentfrom
Snehita_mock_data_tcs

Conversation

@snehitakandula

Copy link
Copy Markdown

Description

Implements: (PRIORITY HIGH) Phase 2 – Add mock data so every chart on the Total Construction Summary is populated (BM Dashboard → Reports → Total Construction Summary).

Screenshot 2026-10-31 170528

How each task item is addressed:

  1. Realistic mock data for projects, materials, tools, rentals, issues, injuries, labor and costs, covering recent weeks → a seeder inserts ~590 records across 19 collections for the last 8 weeks (issues with severity, injuries ×3, rentals, returned-late tools, tool downtime/stoppage/availability, expenditure, cost tracking, risk profiles, labor time logs and costs, lessons, materials with weekly usage and purchases, tools, project status).
  2. Consistent project names → all mock data is attached to the existing BM projects (Building 1, Building 2, Building 3, Residential Test - Project, Commercial Test - Project), the same names the charts already show.
  3. Every chart shows data by default → see "Charts" below for what is now populated and what cannot be filled by data.
  4. Document how to load and reset → see "How to load and reset" below (also in the header of src/scripts/seedTcsMockData.js).

How to load and reset the mock data

From the HGNRest root, with the usual .env:

node src/scripts/seedTcsMockData.js          # removes previous mock data, then loads fresh data
node src/scripts/seedTcsMockData.js --reset  # removes the mock data only

Every inserted ID is recorded in a mockDataManifests document, so reset deletes only the mock records. Nothing created by other developers on the shared dev database is touched. Running the load again replaces the mock data instead of duplicating it.

Main changes explained:

  1. src/utilities/tcsMockDataSeeder.js: builds the mock records (seeded random, so the data is consistent between runs) and contains the load/reset logic. Models are passed in, so it is unit-testable.
  2. src/scripts/seedTcsMockData.js: CLI runner (same pattern as seedToolReplacements.js).
  3. src/models/bmdashboard/mockDataManifest.js: stores the inserted IDs for a safe reset.
  4. src/utilities/__tests__/tcsMockDataSeeder.test.js: 15 unit tests with mocked models (record builders, date range, field limits, risk profile/project name linking, reset deletes only manifest IDs, missing projects or admin user).

Notes on how some charts read their data:

  • Risk Profile reads the project name from an Issues document whose _id is the risk profile's projectId, so one Issues document per project is created and linked.
  • Project Status cards match ProjectStatus and LaborCost to projects by name, so those are seeded by name.

Charts

Now populated: Quantity of Materials Used (Last Week), Total Material Cost per Project, Project Status (Completed Projects, Avg Duration, Material Cost, Material Used, Material Wasted, Labor Cost), Issues Breakdown, Issue Chart, Longest Open Issues, Injury Severity by Projects, Injury by Worker Category, Lessons Learnt, Supplier Performance, Tools Returned Late, Paid Labor Cost, Expenditure, Actual vs Planned, Cost Breakdown, Risk Profile (by project name).

Cannot be filled by mock data (frontend/backend behavior, not data):

  • Project Status: Total / Active / Delayed Projects and Material Available are "current snapshot" metrics shown only when the date range includes today, but the date dropdown only offers last week. Total Labor Hours is hardcoded as unavailable in weeklyProjectSummaryService.
  • Rental Cost Over Time defaults to 1/1/2024–12/1/2024 (mock data is in recent weeks).
  • Proportion of Tools/Equipment and Most Frequent Keywords stay empty until a project/source is selected.
  • Distribution of Labor Hours, Loss Tracking, Cost Variance Trend, Expense Bar, Cost Prediction use hardcoded frontend data (covered by separate "use real data" tasks).
  • Cost Breakdown model uses a unique numeric projectId, so it was not seeded to avoid colliding with existing rows.

How to test:

  1. Check out this branch, npm install, npm run build, copy src/data to dist/data, npm start
  2. Run npx jest tcsMockDataSeeder; all 15 tests pass
  3. Run node src/scripts/seedTcsMockData.js and check the printed summary
  4. With the frontend on development, go to /bmdashboard/totalconstructionsummary and verify the charts above show data
  5. Run node src/scripts/seedTcsMockData.js --reset and confirm the mock data is removed (then load it again)

Screenshots:

Screenshot 2026-11-05 003626 Screenshot 2026-11-04 231504

Note:

Backend only. The mock data is currently loaded on the dev database.

@snehitakandula snehitakandula added the High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible label Nov 5, 2026
@sonarqubecloud

sonarqubecloud Bot commented Nov 5, 2026

Copy link
Copy Markdown

This branch has not been deployed

No deployments
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.

1 participant