Skip to content

Commit 472a1f3

Browse files
Merge pull request #52 from pnnl/feature/whole-project-wattage-uvalue-location
allowed wattage and uvalue api payload updates
2 parents b031eea + 191b41c commit 472a1f3

13 files changed

Lines changed: 357 additions & 116 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ All notable changes to this project are documented in this file.
44

55
## [Unreleased]
66

7+
### Changed (breaking)
8+
- `COMcheckClient.calculate_interior_space_allowed_wattage(project, area_description, energy_code=None)` now takes the whole project and the `areaDescription` of the interior space, instead of an `InteriorSpace` and an energy code. It sends the project to `POST /{energyCode}/activity-use/allowed-wattage?areaDescription=...`. The energy code defaults to `project.control.code`
9+
- `COMcheckClient.calculate_interior_spaces_allowed_wattage(project, energy_code=None)` now takes the whole project instead of a list of `InteriorSpace` objects and returns allowed wattage for every interior space in it. The energy code defaults to `project.control.code`
10+
- `COMCheckApiService.interior_space_allowed_wattage(project_data, energy_code, area_description)` and `COMCheckApiService.interior_spaces_allowed_wattage(project_data, energy_code)` send the whole project
11+
- `COMcheckClient.update_uvalues` now also sends `project.location` with the envelope; the u-value endpoint requires it because the required u-values depend on the climate zone
12+
13+
### Fixed
14+
- `update_uvalues` no longer raises when the API returns `null` for `propUValue` or `effectiveUFactor`; the existing value is kept
15+
716
### Added
817
- Docs and AI skill note that mechanical requirements (`requirementAnswer`) are not supported and must be filled out on COMcheck Web
918
- Renewable energy operations module (`project_renewable_operations`) for managing on-site renewable systems and off-site procurement

‎comcheck_api/ai/skill/SKILL.md‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,21 @@ Triggers:
6060
for known lifecycle values (the catalog isn't exhaustive — only
6161
the terminal pair is guaranteed stable).
6262
- **U-values are calculated server-side**: `update_uvalues(project)`
63-
fetches the proposed/effective u-values for the envelope and writes
63+
sends the envelope plus `project.location` (required — the climate zone
64+
drives the required u-values), fetches the proposed/effective u-values, and
65+
writes
6466
them back onto the matching `agWall`, `bgWall`, `roof`, and `floor`
6567
assemblies (only these get calculated u-values; `effectiveUFactor`
6668
is `agWall`-only). `start_run_simulation` calls this automatically,
6769
so you rarely call it directly — use it only when you need refreshed
6870
u-values on a project outside the simulation flow.
6971
- **Interior lighting allowed wattage is also calculated server-side**:
70-
`calculate_interior_space_allowed_wattage(interior_space, energy_code)` and
71-
`calculate_interior_spaces_allowed_wattage(interior_spaces, energy_code)`
72-
take an `InteriorSpace` (or a list of them) plus the energy code as an
73-
explicit string — `InteriorSpace` has no `control.code` of its own. Neither
74-
method mutates the input or writes to `allowedWattage`; both return the
72+
`calculate_interior_space_allowed_wattage(project, area_description)` and
73+
`calculate_interior_spaces_allowed_wattage(project)` send the whole
74+
project; the single form picks the interior space by its
75+
`areaDescription`, which must already exist in the project. The energy code
76+
defaults to `project.control.code` (override with `energy_code=`). Neither
77+
method mutates the project or writes to `allowedWattage`; both return the
7578
raw calculation payload (`{"spaceAllowedWattage": ...}` for the single
7679
form, `{areaDescription: wattage, ...}` for the list form).
7780
- **Renewable areas and capacity are calculated server-side**:

‎comcheck_api/ai/skill/reference/operations.md‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,17 @@ Allowed wattage is calculated server-side via two `COMcheckClient` methods,
135135
not an `il_ops` function:
136136

137137
```python
138-
energy_code = str(project.control.code) # InteriorSpace alone has no control.code
139-
140-
result = client.calculate_interior_space_allowed_wattage(interior_space, energy_code)
138+
# Both send the whole project; energy code defaults to project.control.code
139+
result = client.calculate_interior_space_allowed_wattage(project, "Open Office")
141140
# {"spaceAllowedWattage": 560}
142141

143-
results = client.calculate_interior_spaces_allowed_wattage(
144-
[interior_space, second_interior_space], energy_code
145-
)
142+
results = client.calculate_interior_spaces_allowed_wattage(project)
146143
# {"Open Office": 560, "Conference Room": 610} — keyed by areaDescription
147144
```
148145

149-
Neither call mutates the `InteriorSpace` objects or writes onto
150-
`allowedWattage` — they return the raw calculation payload.
146+
The interior space must already be in the project (add it with
147+
`il_ops.add_interior_space_to_project`). Neither call mutates the project or
148+
writes onto `allowedWattage` — they return the raw calculation payload.
151149

152150
## Exterior lighting operations
153151

‎comcheck_api/ai/skill/reference/simulation.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ client = COMcheckClient(api_key="...")
4444
| Method | Returns | Purpose |
4545
|---|---|---|
4646
| `client.start_run_simulation(project, project_id=None)` | `str` (session ID) | Kick off the simulation. Always refreshes the envelope u-values first (via `update_uvalues`). If `project_id` is provided, the project is also saved/updated. |
47-
| `client.update_uvalues(project)` | `ComBuilding` | Calculate assembly u-values and write them back onto the project's `agWall`, `bgWall`, `roof`, and `floor` assemblies (matched by `assemblyType`). Mutates and returns the same project. Called automatically by `start_run_simulation`. |
47+
| `client.update_uvalues(project)` | `ComBuilding` | Send the envelope and `project.location` (required), calculate assembly u-values, and write them back onto the project's `agWall`, `bgWall`, `roof`, and `floor` assemblies (matched by `assemblyType`). Mutates and returns the same project. Called automatically by `start_run_simulation`. |
4848
| `client.get_simulation_status(session_id)` | `dict` | Current status. Fields: `sessionId`, `status` (see the Status values table above), optional `message`. |
4949
| `client.get_simulation_result(session_id)` | `dict` | Final result. Fields: `sessionId`, `performanceRating`, `energyCreditPerformanceRating`, `proposedBpf`, `baselineBpf`. |
5050

‎comcheck_api/api/api_services.py‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,17 @@ def update_project(
199199
def assemblies_uvalue(
200200
self, envelope_data: Dict[str, Any], energy_code: str
201201
) -> Dict[str, Any]:
202-
"""get assemblies u values
202+
"""Calculate assembly u-values.
203203
204204
Args:
205-
envelope_data: The envelope data to send in the request body
205+
envelope_data: The request body: the envelope assembly arrays
206+
(``roof``, ``agWall``, ``bgWall``, ``floor``) plus the
207+
project ``location``, which is required because the
208+
required u-values depend on the climate zone.
206209
energy_code: The energy code for the api end point path
207210
208211
Returns:
209-
RunSimulationResponse with session information
212+
API response data as dictionary
210213
211214
Raises:
212215
COMCheckHTTPError: If the API returns an error status
@@ -224,13 +227,15 @@ def assemblies_uvalue(
224227
self._handle_api_error(error)
225228

226229
def interior_space_allowed_wattage(
227-
self, interior_space_data: Dict[str, Any], energy_code: str
230+
self, project_data: Dict[str, Any], energy_code: str, area_description: str
228231
) -> Dict[str, Any]:
229232
"""Calculate allowed wattage for a single interior lighting space.
230233
231234
Args:
232-
interior_space_data: The interior space data to send in the request body
235+
project_data: The whole project to send in the request body
233236
energy_code: The energy code for the api end point path
237+
area_description: The ``areaDescription`` of the interior space
238+
(``activityUse``) in the project to calculate
234239
235240
Returns:
236241
API response data as dictionary
@@ -242,20 +247,22 @@ def interior_space_allowed_wattage(
242247
try:
243248
client = self._get_client()
244249
response = client.post(
245-
f"/{energy_code}/activity-use/allowed-wattage", json=interior_space_data
250+
f"/{energy_code}/activity-use/allowed-wattage",
251+
params={"areaDescription": area_description},
252+
json=project_data,
246253
)
247254
response.raise_for_status()
248255
return response.json()
249256
except Exception as error:
250257
self._handle_api_error(error)
251258

252259
def interior_spaces_allowed_wattage(
253-
self, interior_spaces_data: list[Dict[str, Any]], energy_code: str
260+
self, project_data: Dict[str, Any], energy_code: str
254261
) -> Dict[str, Any]:
255-
"""Calculate allowed wattage for a list of interior lighting spaces.
262+
"""Calculate allowed wattage for every interior lighting space in a project.
256263
257264
Args:
258-
interior_spaces_data: The list of interior space data to send in the request body
265+
project_data: The whole project to send in the request body
259266
energy_code: The energy code for the api end point path
260267
261268
Returns:
@@ -269,7 +276,7 @@ def interior_spaces_allowed_wattage(
269276
client = self._get_client()
270277
response = client.post(
271278
f"/{energy_code}/activity-uses/allowed-wattage",
272-
json=interior_spaces_data,
279+
json=project_data,
273280
)
274281
response.raise_for_status()
275282
return response.json()

‎comcheck_api/client/comcheck_client.py‎

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
PlantEfficiency,
3131
FanSystemComplianceResult,
3232
)
33-
from comcheck_api.types.common_types import InteriorSpace
3433
from comcheck_api.types.core_types import (
3534
MISSING,
3635
ComBuilding,
@@ -283,11 +282,13 @@ def _parse_data(self, data, mode):
283282
def update_uvalues(self, project: ComBuilding) -> ComBuilding:
284283
"""Calculate assembly u-values and update the project in place.
285284
286-
Sends the full envelope to the u-value endpoint and writes the returned
287-
values back onto the matching ``agWall``, ``bgWall``, ``roof``, and
288-
``floor`` components (matched by ``assemblyType``). Only these assembly
289-
types receive calculated u-values; ``effectiveUFactor`` applies to
290-
``agWall`` only.
285+
Sends the envelope and the project ``location`` to the u-value
286+
endpoint and writes the returned values back onto the matching
287+
``agWall``, ``bgWall``, ``roof``, and ``floor`` components (matched by
288+
``assemblyType``). Only these assembly types receive calculated
289+
u-values; ``effectiveUFactor`` applies to ``agWall`` only. The
290+
location is required because the required u-values depend on the
291+
climate zone.
291292
292293
Args:
293294
project: The project whose envelope u-values should be refreshed.
@@ -296,70 +297,87 @@ def update_uvalues(self, project: ComBuilding) -> ComBuilding:
296297
The same ``project`` instance, with u-values updated.
297298
"""
298299
energy_code = str(project.control.code)
299-
envelope_data = project.envelope.model_dump(mode="json")
300+
request_data = project.envelope.model_dump(mode="json")
301+
request_data["location"] = project.location.model_dump(mode="json")
300302
updated_assembly_uvalues = self._service.assemblies_uvalue(
301-
envelope_data, energy_code
303+
request_data, energy_code
302304
)["data"]
303305

304-
for wall in project.envelope.agWall:
305-
for uvalue in updated_assembly_uvalues.get("agWall", []):
306-
if wall.assemblyType == uvalue["assemblyType"]:
307-
wall.effectiveUFactor = float(uvalue["effectiveUFactor"])
308-
wall.propUValue = float(uvalue["propUValue"])
309-
for wall in project.envelope.bgWall:
310-
for uvalue in updated_assembly_uvalues.get("bgWall", []):
311-
if wall.assemblyType == uvalue["assemblyType"]:
312-
wall.propUValue = float(uvalue["propUValue"])
313-
for roof in project.envelope.roof:
314-
for uvalue in updated_assembly_uvalues.get("roof", []):
315-
if roof.assemblyType == uvalue["assemblyType"]:
316-
roof.propUValue = float(uvalue["propUValue"])
317-
for floor in project.envelope.floor:
318-
for uvalue in updated_assembly_uvalues.get("floor", []):
319-
if floor.assemblyType == uvalue["assemblyType"]:
320-
floor.propUValue = float(uvalue["propUValue"])
306+
def _apply(components, key: str, effective: bool = False) -> None:
307+
results = {
308+
uvalue["assemblyType"]: uvalue
309+
for uvalue in updated_assembly_uvalues.get(key, [])
310+
}
311+
for component in components:
312+
uvalue = results.get(component.assemblyType)
313+
if uvalue is None:
314+
continue
315+
prop_uvalue = _optional_float(uvalue.get("propUValue"))
316+
if prop_uvalue is not None:
317+
component.propUValue = prop_uvalue
318+
if effective:
319+
effective_ufactor = _optional_float(uvalue.get("effectiveUFactor"))
320+
if effective_ufactor is not None:
321+
component.effectiveUFactor = effective_ufactor
322+
323+
_apply(project.envelope.agWall, "agWall", effective=True)
324+
_apply(project.envelope.bgWall, "bgWall")
325+
_apply(project.envelope.roof, "roof")
326+
_apply(project.envelope.floor, "floor")
321327

322328
return project
323329

324330
def calculate_interior_space_allowed_wattage(
325-
self, interior_space: InteriorSpace, energy_code: str
331+
self,
332+
project: ComBuilding,
333+
area_description: str,
334+
energy_code: Optional[str] = None,
326335
) -> Any:
327336
"""Calculate allowed wattage for a single interior lighting space.
328337
338+
Sends the whole project; the space is selected by its
339+
``areaDescription`` and must exist in
340+
``project.lighting.wholeBldgUse[].activityUse[]``.
341+
329342
Args:
330-
interior_space: The interior space (``InteriorSpace``) to
331-
calculate allowed wattage for.
343+
project: The project containing the interior space.
344+
area_description: The ``areaDescription`` of the interior space
345+
(``InteriorSpace``) to calculate allowed wattage for.
332346
energy_code: The energy code for the api end point path.
347+
Defaults to ``project.control.code``.
333348
334349
Returns:
335350
A dict with the calculated wattage, e.g.
336351
``{"spaceAllowedWattage": 560}``.
337352
"""
338-
interior_space_data = interior_space.model_dump(mode="json")
353+
project_data = project.model_dump(mode="json")
339354
response = self._service.interior_space_allowed_wattage(
340-
interior_space_data, energy_code
355+
project_data,
356+
energy_code or str(project.control.code),
357+
area_description,
341358
)
342359
return response.get("data")
343360

344361
def calculate_interior_spaces_allowed_wattage(
345-
self, interior_spaces: List[InteriorSpace], energy_code: str
362+
self, project: ComBuilding, energy_code: Optional[str] = None
346363
) -> Any:
347-
"""Calculate allowed wattage for a list of interior lighting spaces.
364+
"""Calculate allowed wattage for every interior lighting space in a project.
365+
366+
Sends the whole project; allowed wattage is returned for every
367+
interior space in ``project.lighting.wholeBldgUse[].activityUse[]``.
348368
349369
Args:
350-
interior_spaces: The interior spaces (``InteriorSpace`` objects)
351-
to calculate allowed wattage for.
370+
project: The project containing the interior spaces.
352371
energy_code: The energy code for the api end point path.
372+
Defaults to ``project.control.code``.
353373
354374
Returns:
355375
A dict keyed by each interior space's ``areaDescription``, e.g.
356376
``{"Test Space": 610}``.
357377
"""
358-
interior_spaces_data = [
359-
interior_space.model_dump(mode="json") for interior_space in interior_spaces
360-
]
378+
project_data = project.model_dump(mode="json")
361379
response = self._service.interior_spaces_allowed_wattage(
362-
interior_spaces_data, energy_code
380+
project_data, energy_code or str(project.control.code)
363381
)
364382
return response.get("data")
365383

‎docs_site/api/operations/envelope.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,10 @@ thermal bridges on it.
173173

174174
## Calculating U-values (API)
175175

176-
`COMcheckClient.update_uvalues` sends the envelope to the COMcheck Web API.
177-
It writes the calculated U-values back onto the matching `agWall`, `bgWall`,
176+
`COMcheckClient.update_uvalues` sends the envelope and the project
177+
`location` to the COMcheck Web API. The location is required because the
178+
required U-values depend on the climate zone, so set `project.location`
179+
(`state`, `city`, `climateZone`) first. It writes the calculated U-values back onto the matching `agWall`, `bgWall`,
178180
`roof`, and `floor` components (matched by `assemblyType`). It updates the
179181
project in place and returns it:
180182

‎docs_site/api/operations/interior-lighting.md‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,27 +164,23 @@ keys = il_ops.get_interior_space_keys_from_project(project, area_key)
164164
## Calculating allowed wattage (API)
165165

166166
Allowed wattage is calculated server-side via two `COMcheckClient` methods,
167-
not the `il_ops` free functions above. Both take the energy code as an
168-
explicit string (there's no project to pull `control.code` from) — an
169-
`InteriorSpace` alone doesn't carry an energy code:
167+
not the `il_ops` free functions above. Both send the whole project, so add
168+
the interior spaces to the project first. The energy code defaults to
169+
`project.control.code`; pass `energy_code=` to override it:
170170

171171
```python
172-
energy_code = str(project.control.code)
173-
174-
# Single InteriorSpace
175-
result = client.calculate_interior_space_allowed_wattage(interior_space, energy_code)
172+
# One InteriorSpace, selected by its areaDescription
173+
result = client.calculate_interior_space_allowed_wattage(project, "Open Office")
176174
# {"spaceAllowedWattage": 560}
177175

178-
# A list of InteriorSpace objects
179-
results = client.calculate_interior_spaces_allowed_wattage(
180-
[interior_space, second_interior_space], energy_code
181-
)
176+
# Every InteriorSpace in the project
177+
results = client.calculate_interior_spaces_allowed_wattage(project)
182178
# {"Open Office": 560, "Conference Room": 610} — keyed by areaDescription
183179
```
184180

185-
These calls don't mutate the `InteriorSpace` objects passed in or write the
186-
result onto `allowedWattage` — they return the raw calculation payload for
187-
the caller to use as needed.
181+
These calls don't mutate the project or write the result onto
182+
`allowedWattage` — they return the raw calculation payload for the caller to
183+
use as needed.
188184

189185
See `examples/project_operations/interior_lighting_operations.py` and
190186
`examples/client/allowed_wattage.py` for full walkthroughs.

‎docs_site/api/simulation.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ session_id = client.start_run_simulation(project, project_id="your-project-id")
6666
## Envelope u-values
6767

6868
`start_run_simulation` always refreshes the calculated envelope u-values
69-
before submitting, by calling `update_uvalues(project)`. This fetches the
70-
proposed/effective u-values for the envelope assemblies and writes them
69+
before submitting, by calling `update_uvalues(project)`. This sends the
70+
envelope assemblies and the project `location` (required — the climate zone
71+
drives the required u-values), fetches the proposed/effective u-values, and
72+
writes them
7173
back onto the matching `agWall`, `bgWall`, `roof`, and `floor` components
7274
(matched by `assemblyType`). Only these assembly types receive calculated
7375
u-values, and `effectiveUFactor` applies to `agWall` only.

‎examples/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ python examples/client/compliance_and_report.py
6161
Demonstrates interior lighting allowed-wattage calculation.
6262

6363
**What it demonstrates:**
64-
- `calculate_interior_space_allowed_wattage()` - Calculating allowed wattage for a single InteriorSpace
65-
- `calculate_interior_spaces_allowed_wattage()` - Calculating allowed wattage for a list of InteriorSpace objects
64+
- `calculate_interior_space_allowed_wattage()` - Calculating allowed wattage for one InteriorSpace in a project, selected by `areaDescription`
65+
- `calculate_interior_spaces_allowed_wattage()` - Calculating allowed wattage for every InteriorSpace in a project
6666

6767
**Usage:**
6868
```bash

0 commit comments

Comments
 (0)