Skip to content

Conversation

@martin-mosteiro
Copy link
Collaborator

@martin-mosteiro martin-mosteiro commented Sep 3, 2025

On CEA, all the _helpers are about retrieving data, except the occupancy_helper, which includes occupancy models. I think this is a bit confusing, especially because it makes it harder to differentiate schedule_helper from occupancy_helper.

Why not just call it occupancy, since that is what the script is about? It's basically the same as thermal_loads (which isn't thermal_loads_helper) or thermal_network (which isn't thermal_network_helper).

I think this makes things a bit clearer with no downsides!

Summary by CodeRabbit

  • Refactor
    • Renamed public entry from "occupancy_helper" to "occupancy" across the app and schemas, updating public consumer/producer associations.
  • Chores
    • Config section renamed to "occupancy"; runtime logs and script wiring updated. Script inputs expanded to include building architecture, zone geometry, and weather files. Workflow steps and command invocations updated.
  • Tests
    • Unit-data generation and test suites updated to use the new entry points; outputs unchanged.
  • Documentation
    • Help text updated to reference the "occupancy" script.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 3, 2025

Walkthrough

Renames the occupancy entry point and public name from occupancy_helper → occupancy, moves the main function to cea.demand.occupancy.occupancy_main, and shifts configuration access from config.occupancy_helper to config.occupancy. Updates schemas, scripts, tests, workflows, and docstrings to the new name; no logic or schema changes.

Changes

Cohort / File(s) Summary
Occupancy entry point rename
cea/demand/occupancy.py
Function renamed occupancy_helper_mainoccupancy_main; reads config.occupancy.* (e.g., buildings, occupancy_model) instead of config.occupancy_helper.*; log text updated.
Schemas update (used_by / created_by)
cea/schemas.yml
Replaced occupancy_helper with occupancy in many used_by and created_by lists; schemas and validation unchanged.
Script registration & defaults
cea/scripts.yml, cea/default.config
Script entry renamed occupancy-helperoccupancy; module path updated to cea.demand.occupancy; default config section renamed [occupancy-helper][occupancy]; input-files list expanded to include additional dependencies.
Tests updated to new API
cea/tests/create_unittest_data.py, cea/tests/test_calc_thermal_loads.py, cea/tests/test_schedules.py
Imports and calls updated to occupancy_main from cea.demand.occupancy; config access switched to config.occupancy.occupancy_model; behavior unchanged.
Workflows & orchestration
cea/tests/workflows/sg_cooling.yml, cea/tests/workflows/zug_heating.yml, cea/utilities/batch_process_workflow.py
Workflow step and batch invocation renamed to occupancy (was occupancy-helper); arguments and parameters preserved.
Docs / docstrings
cea/inputlocator.py
Docstring: "occupancy-helper script" → "occupancy script"; no code changes.

Sequence Diagram(s)

sequenceDiagram
    participant Runner as Workflow / Script Runner
    participant Occupancy as cea.demand.occupancy
    participant Config as Configuration
    participant FS as Filesystem (inputs/outputs)

    Note over Runner,Occupancy #EDF7FF: Invocation renamed from "occupancy-helper" → "occupancy"
    Runner->>Occupancy: call occupancy_main(locator, config, building?)
    Occupancy->>Config: read config.occupancy.buildings, config.occupancy.occupancy_model
    Occupancy->>FS: read inputs (building_internal, building_comfort, building_architecture, zone_geometry, weather_file...)
    Occupancy-->>FS: write occupancy outputs (schedules / CSVs)
    Occupancy-->>Runner: return status / logs
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

about-interface, feature-data-management

Poem

I hopped from helper to simply "occupancy" bright,
Renamed my burrow, tuned configs just right.
Schemas and scripts now call out my name,
Tests nodded along — the logic the same.
Carrots and schedules, neat rows in the light 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately describes the primary change: renaming the occupancy_helper module for consistency and clarity across the codebase. The provided summaries show renames in the module, tests, config section, schemas, scripts, and workflows, which directly match the title. It is a concise, single sentence that avoids vague wording and communicates the PR's main intent to reviewers.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch occupancy_helper

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
cea/scripts.yml (1)

176-188: CLI parameters still point to occupancy-helper; this will bypass config.occupancy values at runtime

The script now reads from config.occupancy.*, but the CLI wiring exposes occupancy-helper parameters. This mismatch will cause CLI/Dashboard changes to be written under [occupancy-helper] and ignored by the code. Update the parameters group to occupancy to align with the code.

   - name: occupancy-helper
     label: "Energy Demand Part 1: building occupancy"
     short_description: Estimate building occupancy profiles using CEA models
     description: This Feature uses CEA models and input schedules to estimate the occupancy profile of buildings.
     interfaces: [dashboard, cli]
-    module: cea.demand.occupancy
+    module: cea.demand.occupancy
     parameters: ['general:scenario',
                  'general:multiprocessing',
                  'general:number-of-cpus-to-keep-free',
                  'general:debug',
-                 occupancy-helper]
+                 occupancy]

If you intend to keep the CLI name occupancy-helper for backward compatibility, that’s fine—just ensure the parameter section is occupancy. I can open a follow-up PR to add a deprecation note in docs.

cea/tests/test_schedules.py (1)

135-139: Bug: occupancy_main returns None; create_data breaks when reading schedules from the return value

occupancy_main writes files and returns None (see occupancy.py). The current code assigns its return to calculated_schedules and then indexes it, which will raise at runtime.

Fix by generating the schedules and then reading the produced CSV:

-    calculated_schedules = occupancy_main(locator, config)
-    if not test_config.has_section('test_mixed_use_schedules'):
-        test_config.add_section('test_mixed_use_schedules')
-    test_config.set('test_mixed_use_schedules', 'reference_results', json.dumps(
-        {schedule: calculated_schedules[schedule][REFERENCE_TIME] for schedule in calculated_schedules.keys()}))
+    # Generate schedules for B1011 and read the resulting CSV
+    occupancy_main(locator, config, building='B1011')
+    calculated_schedules = pd.read_csv(locator.get_occupancy_model_file('B1011')).set_index('date')
+    if not test_config.has_section('test_mixed_use_schedules'):
+        test_config.add_section('test_mixed_use_schedules')
+    test_config.set(
+        'test_mixed_use_schedules',
+        'reference_results',
+        json.dumps({schedule: calculated_schedules[schedule][REFERENCE_TIME]
+                    for schedule in calculated_schedules.columns})
+    )
🧹 Nitpick comments (5)
cea/demand/occupancy.py (1)

480-483: Tidy the log message (double space) and prefer f-strings

Minor UX nit: fix the extra space and modernize the formatting.

-    print('Running occupancy model  with schedule model=%s' % config.occupancy.occupancy_model)
+    print(f'Running occupancy model with schedule model={config.occupancy.occupancy_model}')
cea/schemas.yml (1)

1769-1769: Back-compat consideration: temporary dual listing.

If any external tooling parses used_by to resolve script names, consider (optionally) listing both “occupancy” and “occupancy_helper” for one release cycle, then remove the latter.
Example (pattern only):

-  used_by:
-  - occupancy
+  used_by:
+  - occupancy
+  - occupancy_helper  # deprecated; remove next release

Also applies to: 1824-1824, 1918-1918, 2113-2114, 2409-2409, 2458-2458, 2529-2529, 2560-2560, 2591-2591, 2661-2661, 2733-2733, 10571-10572, 19442-19443, 21040-21041, 21174-21175

cea/tests/test_schedules.py (1)

56-56: Scope the run to a single building and force determinism for stability/perf

Limit schedule generation to B1011 (the only file you read) and explicitly set the deterministic model to avoid stochastic drift and speed up the test.

Apply:

-        occupancy_main(locator, config)
+        # Ensure deterministic schedules and limit computation to the needed building
+        config.occupancy.occupancy_model = "deterministic"
+        occupancy_main(locator, config, building='B1011')

If config.multiprocessing was previously used, confirm config.general.multiprocessing = False is the current way to disable parallelism for tests.

cea/tests/create_unittest_data.py (2)

56-56: Make fixture generation reproducible and faster

Set deterministic occupancy and disable multiprocessing before generating schedules for B1011.

-    occupancy_main(locator, config, building='B1011')
+    # Make fixtures reproducible and fast
+    config.general.multiprocessing = False
+    config.occupancy.occupancy_model = "deterministic"
+    occupancy_main(locator, config, building='B1011')

129-129: Consistency with config API when disabling parallelism

Elsewhere we use config.general.multiprocessing = False. Keep it consistent here to ensure get_number_of_processes() behaves as expected.

Update in run_for_single_building (context outside the changed line):

# before
config.multiprocessing = False

# after
config.general.multiprocessing = False

If unsure, search the repo for get_number_of_processes and confirm it reads from config.general.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 360235a and 2a4d9bd.

📒 Files selected for processing (6)
  • cea/demand/occupancy.py (2 hunks)
  • cea/schemas.yml (16 hunks)
  • cea/scripts.yml (1 hunks)
  • cea/tests/create_unittest_data.py (3 hunks)
  • cea/tests/test_calc_thermal_loads.py (3 hunks)
  • cea/tests/test_schedules.py (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
cea/tests/test_schedules.py (1)
cea/demand/occupancy.py (1)
  • occupancy_main (35-92)
cea/demand/occupancy.py (3)
cea/inputlocator.py (1)
  • InputLocator (20-1474)
cea/config.py (1)
  • Configuration (35-277)
cea/datamanagement/void_deck_migrator.py (1)
  • migrate_void_deck_data (7-35)
cea/tests/create_unittest_data.py (1)
cea/demand/occupancy.py (1)
  • occupancy_main (35-92)
cea/tests/test_calc_thermal_loads.py (1)
cea/demand/occupancy.py (1)
  • occupancy_main (35-92)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: tests (macos-latest)
  • GitHub Check: tests (windows-latest)
🔇 Additional comments (9)
cea/schemas.yml (4)

1769-1769: Rename applied consistently to building property schemas.

used_by now lists "occupancy" for get_building_architecture, get_building_comfort, get_building_internal, and get_building_weekly_schedules. Looks correct.

Also applies to: 1824-1824, 1918-1918, 2113-2114


2409-2409: Envelope database dependencies updated to “occupancy”.

Good alignment with the module rename; no schema keys changed.

Also applies to: 2458-2458, 2529-2529, 2560-2560, 2591-2591, 2661-2661, 2733-2733


10571-10572: Radiation/envelope systems used_by includes “occupancy”. Verify actual usage.

If occupancy doesn’t read envelope/radiation-derived systems directly, consider dropping redundant used_by entries to keep dependency graphs tight.
Would you like a quick grep script to confirm references in cea/demand/occupancy.py?


19164-19165: Everything now uses outputs/data/occupancy via get_occupancy_model_file; no occupancy_helper references remain.

cea/tests/test_schedules.py (1)

17-17: Import rename LGTM

Import updated to the new API is correct and consistent with the PR intent.

cea/tests/create_unittest_data.py (1)

21-21: Import rename LGTM

Import aligns with the new module/function naming.

cea/tests/test_calc_thermal_loads.py (3)

14-14: Import rename LGTM

Correct import of the new entry point.


66-67: Deterministic occupancy and new API usage LGTM

Explicitly setting config.occupancy.occupancy_model and calling occupancy_main with the building is correct and keeps the test stable.


122-122: Per-building occupancy generation LGTM

Calling occupancy_main per building matches the intended flow and works with config.general.multiprocessing = False.

Comment on lines +35 to 40
def occupancy_main(locator: cea.inputlocator.InputLocator, config: cea.config.Configuration, building=None):
migrate_void_deck_data(locator)
# local variables
buildings: List[str] = config.occupancy_helper.buildings
occupancy_model: str = config.occupancy_helper.occupancy_model
buildings: List[str] = config.occupancy.buildings
occupancy_model: str = config.occupancy.occupancy_model

Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Rename + config path switch look good; ensure [occupancy] section exists at runtime

The function rename and move to config.occupancy.* read cleanly. Please confirm the default/user config files define an occupancy section with buildings and occupancy_model, and that all callers/tests set these under occupancy (not occupancy_helper).

Run:


🏁 Script executed:

#!/bin/bash
# 1) Find any stale references that might break at runtime
rg -nP -C2 '\boccupancy_helper_main\b|\bconfig\.occupancy_helper\b|occupancy[_-]helper' 

# 2) Verify [occupancy] section exists in config templates
rg -nP -n '^\[occupancy\]' -C2

Length of output: 2451


Remove stale occupancy-helper references and introduce [occupancy] config section

  • Rename config section: in cea/default.config, change [occupancy-helper] to [occupancy] and ensure buildings and occupancy_model are defined.
  • Update CLI commands: in cea/scripts.yml (around lines 175–179 and 185–189), replace name: occupancy-helper and related script entries with the new command (e.g. occupancy).
  • Adjust workflow code: in cea/utilities/batch_process_workflow.py (line 122), update ['cea', 'occupancy-helper', …] to ['cea', 'occupancy', …].
  • Fix tests: in cea/tests/workflows/zug_heating.yml and sg_cooling.yml (line 31), change - script: occupancy-helper to - script: occupancy.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cea/default.config (1)

322-334: Implement config migration for deprecated [occupancy-helper]
No code still reads occupancy_helper (verified); add logic in your config‐formatting tool (e.g. write-config/format-helper) to rename users’ [occupancy-helper] blocks to [occupancy].

🧹 Nitpick comments (1)
cea/scripts.yml (1)

178-178: Capitalize label for consistency.

Use “Energy Demand Part 1: Building Occupancy” to match title casing used elsewhere.

-    label: "Energy Demand Part 1: building occupancy"
+    label: "Energy Demand Part 1: Building Occupancy"
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2a4d9bd and 8674aa2.

📒 Files selected for processing (6)
  • cea/default.config (1 hunks)
  • cea/inputlocator.py (1 hunks)
  • cea/scripts.yml (1 hunks)
  • cea/tests/workflows/sg_cooling.yml (1 hunks)
  • cea/tests/workflows/zug_heating.yml (1 hunks)
  • cea/utilities/batch_process_workflow.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • cea/inputlocator.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: tests (windows-latest)
  • GitHub Check: tests (ubuntu-latest)
  • GitHub Check: tests (macos-latest)
🔇 Additional comments (6)
cea/utilities/batch_process_workflow.py (1)

121-124: Verified cea occupancy CLI is in scripts.yml (line 177) and no occupancy-helper references exist.

cea/tests/workflows/sg_cooling.yml (1)

31-31: Workflow step renamed to occupancy — LGTM.

Matches the CLI rename; ordering relative to radiation and demand remains correct.

cea/tests/workflows/zug_heating.yml (1)

31-31: Workflow step renamed to occupancy — LGTM.

Consistent with the repository-wide rename.

cea/scripts.yml (3)

177-183: Entry rename and module target updated — good alignment.

‘name: occupancy’ and ‘module: cea.demand.occupancy’ align with the new API.


189-194: InputLocator methods exist
Verified that get_building_architecture, get_zone_geometry, and get_weather_file are implemented in cea/inputlocator.py.


187-187: All consumers updated to config.occupancy; no lingering occupancy_helper or occupancy-helper references detected.

@ShiZhongming
Copy link
Collaborator

Hi @martin-mosteiro
Thanks for spotting this and making the changes!
You are right about the naming convention issue, and it does open many more issues for the terms we have been using in CEA. Let's discuss in the next meeting?

Terrain input is not used by the occupancy script
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (7)
cea/schemas.yml (7)

2406-2409: Mass assemblies: drop occupancy from used_by unless proven needed.

No clear link between occupancy script and mass assembly DB.

Apply:

   used_by:
   - demand
   - radiation
-  - occupancy

2454-2458: Floor assemblies: same concern—likely not used by occupancy.

Apply:

   used_by:
   - demand
   - radiation
-  - occupancy

2525-2529: Roof assemblies: remove occupancy from used_by if unused.

Apply:

   used_by:
   - demand
   - radiation
-  - occupancy

2557-2560: Shading assemblies: occupancy probably doesn’t consume this DB.

Apply:

   used_by:
   - demand
   - radiation
-  - occupancy

2588-2591: Tightness assemblies: same — recommend removing occupancy.

Apply:

   used_by:
   - demand
   - radiation
-  - occupancy

2658-2661: Wall assemblies: remove occupancy unless there’s a direct call.

Apply:

   used_by:
   - demand
   - radiation
-  - occupancy

2730-2733: Window assemblies: remove occupancy from used_by if unused.

Apply:

   used_by:
   - demand
   - radiation
-  - occupancy
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8674aa2 and 90f82b8.

📒 Files selected for processing (1)
  • cea/schemas.yml (15 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: tests (macos-latest)
  • GitHub Check: tests (windows-latest)
  • GitHub Check: tests (ubuntu-latest)
🔇 Additional comments (7)
cea/schemas.yml (7)

19164-19165: Rename producer from occupancy_helper → occupancy looks correct.

This aligns the schema’s created_by with the new module name.


1824-1825: OK to add occupancy as consumer of building comfort.

Occupancy outputs include setpoints; dependency makes sense.


1918-1919: OK to add occupancy as consumer of building internal loads.

Occupancy uses densities/people gains; this is accurate.


21039-21041: OK to add occupancy as consumer of weather file.

Occupancy reads weather; dependency is correct.


21173-21178: OK to add occupancy as consumer of zone geometry.

The module loads zone geometry; this is correct.


1769-1769: Keep occupancy in used_by — it's referenced by cea/demand/occupancy.py:54

cea/demand/occupancy.py line 54: architecture = pd.read_csv(locator.get_building_architecture()).set_index('name') — do not remove - occupancy from used_by.

Likely an incorrect or invalid review comment.


10569-10572: Likely remove occupancy from envelope systems database — verify first

Repo search limited to cea/demand/occupancy.py returned no matches; usage not confirmed. If occupancy is unused by envelope systems, remove it from cea/schemas.yml.

Suggested change:

 get_database_envelope_systems:
   ...
   used_by:
   - demand
   - radiation
-  - occupancy

Verify (repo-wide):

rg -nP --glob '!**/venv/**' 'get_database_envelope_systems|locator\.get_database_envelope_systems'
rg -nP --glob '!**/venv/**' '^\s*-\s*occupancy\b' cea/schemas.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants