SCRAPE-9: Implement updateDailySummary() aggregation #14

Merged
stephen merged 1 commits from scraper/daily-summary into dev 2026-02-06 00:15:30 -07:00
Owner

Summary

Implements the updateDailySummary() function in scraperService.js that aggregates daily apartment inventory data into the daily_summaries collection.

Key features:

  • Upsert by date key - Idempotent daily summary storage, safe to re-run for the same date
  • Inventory tracking - Records new_units, rented_units, and stale_units arrays with corresponding count fields
  • Net change calculation - Computes net_change as the difference between new and rented unit counts
  • Availability tracking - Stores total_available_today and fetches total_available_yesterday from the previous day's summary
  • Turnover rate - Calculates turnover_rate as (rented_units_count / yesterday_total * 100), rounded to 2 decimal places
  • Edge case handling - Gracefully handles zero division, missing previous day summaries, and month boundary crossings

Test coverage:

  • 22 tests covering all functional areas: upsert behavior, array storage, count fields, net change, availability, turnover rate, edge cases, error handling, and logging
  • All tests passing

Test plan

  • Run npm test -- --testPathPatterns="updateDailySummary" - 22/22 tests pass
  • Verify upsert idempotency (insert + update scenarios)
  • Verify turnover rate edge cases (zero division, missing yesterday)
  • Verify error propagation and logging
## Summary Implements the `updateDailySummary()` function in `scraperService.js` that aggregates daily apartment inventory data into the `daily_summaries` collection. ### Key features: - **Upsert by date key** - Idempotent daily summary storage, safe to re-run for the same date - **Inventory tracking** - Records `new_units`, `rented_units`, and `stale_units` arrays with corresponding count fields - **Net change calculation** - Computes `net_change` as the difference between new and rented unit counts - **Availability tracking** - Stores `total_available_today` and fetches `total_available_yesterday` from the previous day's summary - **Turnover rate** - Calculates `turnover_rate` as `(rented_units_count / yesterday_total * 100)`, rounded to 2 decimal places - **Edge case handling** - Gracefully handles zero division, missing previous day summaries, and month boundary crossings ### Test coverage: - 22 tests covering all functional areas: upsert behavior, array storage, count fields, net change, availability, turnover rate, edge cases, error handling, and logging - All tests passing ## Test plan - [x] Run `npm test -- --testPathPatterns="updateDailySummary"` - 22/22 tests pass - [x] Verify upsert idempotency (insert + update scenarios) - [x] Verify turnover rate edge cases (zero division, missing yesterday) - [x] Verify error propagation and logging
stephen added 1 commit 2026-02-06 00:04:42 -07:00
Implement updateDailySummary() aggregation function
All checks were successful
CI/CD Pipeline - Apartment API / Scan Dependencies (pull_request) Successful in 12s
CI/CD Pipeline - Apartment API / Run Linting (pull_request) Successful in 9m36s
CI/CD Pipeline - Apartment API / Run Tests (pull_request) Successful in 9m51s
CI/CD Pipeline - Apartment API / Send Webhook Notification (pull_request) Successful in 2s
CI/CD Pipeline - Apartment API / Build & Push Image (pull_request) Has been skipped
CI/CD Pipeline - Apartment API / Deploy to Production (pull_request) Has been skipped
c25f2b4950
Add daily summary aggregation that tracks apartment inventory changes:
- Upsert summaries by date key for idempotent operation
- Track new_units, rented_units, and stale_units arrays with counts
- Calculate net_change (new - rented) and total_available_today
- Fetch previous day summary for total_available_yesterday
- Compute turnover_rate as percentage of rented vs yesterday available
- Handle edge cases: zero division, missing previous day, month boundaries
- Full test coverage with 22 tests across all functional areas
stephen merged commit b4978caf31 into dev 2026-02-06 00:15:30 -07:00
stephen deleted branch scraper/daily-summary 2026-02-06 00:15:31 -07:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: stephen/apartment-dashboard-api#14
No description provided.