Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions docs/selection-keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,15 @@ The payload is the exchange format between the client and every consumer (sequen

A sequence document covers one project. The sequence endpoint rejects a payload that does not contain exactly one project, until generating documents for several projects is specified, and a payload whose `schemaVersion` is not supported (HTTP 400, `checkPayload`). The pipeline checks the same (`sequence_payload.py`, on top of `ctrlflow.payload`, which checks the schema version for any consumer).

### Aggregation
### Evaluation

Toggles evaluate over the values of a project, gathered across its configurations:
A toggle is evaluated on each configuration of the project, and a section is kept if its toggle is true on at least one configuration, see "Evaluation" in [sequence-doc.md](sequence-doc.md). The values of a configuration are (`sequence_payload.configuration_values`):

- **System type** (e.g. `VAV` → `Buildings.Templates.ZoneEquipment`): the set of `template`s of the configurations with that `systemType`.
- **Key pattern** (see Mappings): the union of the `value`s of the matching keys in all configurations. Both origins are used, as on `main`. A `redeclare` is not read (see Mappings).
- **Project-level setting**: the `value` in `project.values`.
- **System type** (e.g. `VAV` → `Buildings.Templates.ZoneEquipment`): the `template` of the configuration, if it has that `systemType`.
- **Key pattern** (see Mappings): the `value` of the key of the template of the configuration. Both origins are used, as on `main`. A `redeclare` is not read (see Mappings).
- **Project-level setting**: the `value` in `project.values`, which is read on every configuration.

This reproduces the merge done by the client before #650. Merging now happens in the mogrifier (`sequence_payload.project_selections`, then `aggregate_patterns`). Which templates a toggle reads is set by the mappings: a section of a single system type uses short IDs of its template, and a section shared by several system types a key pattern or a combination of short IDs (see "Sections of System Types" in [sequence-doc.md](sequence-doc.md), #654).
Before #666, values were merged across the configurations, which lost the values that belong to the same configuration. Which templates a toggle reads is set by the mappings: a section of a single system type uses short IDs of its template, and a section shared by several system types a key pattern or a combination of short IDs (see "Sections of System Types" in [sequence-doc.md](sequence-doc.md), #654).

### Mappings

Expand All @@ -251,11 +251,11 @@ alternatives = className { "|" className }

A pattern is shorthand for the set of keys obtained by expanding the alternatives, e.g. `P.{A|B}-c.p` stands for `P.A-c.p` and `P.B-c.p`. Each expanded `rootClass` is a class where `elementPath` is declared (a template, or `Buildings.Templates.Data.AllSystems`), never an enclosing package. `{`, `|` and `}` cannot occur in a class name (no quoted class identifiers), so the expansion is unambiguous (`ctrlflow.keys`). Keys are then matched by equality. A test checks that every expanded key is the key under which the client stores the value of the element, with the default selections (`client/tests/sequence/mappings.test.ts`).

The mogrifier evaluates a toggle against the union of the values of all keys of the pattern. A condition on a subset of templates is expressed by the alternatives, or by a new mapping entry.
On a configuration, a toggle reads the key of the pattern whose `rootClass` is the template of the configuration. The alternatives of a pattern are templates of one system type (`server/scripts/sequence-doc/tests/test_section_scope.py`). A condition on a subset of templates is expressed by the alternatives, or by a new mapping entry.

The `Current G36 Decisions` mappings are rewritten so that the generated document is unchanged:

- Each pattern lists the templates whose values are merged today.
- Each pattern lists the templates whose values were merged at the time.
- Project-level settings use the keys of rule 1.
- The five entries that read the class of a replaceable component (`PREHEAT`, `REHEAT`, `COOL`, `OA`, `TERM_HT`) read its `typ` parameter instead, and their value rows (`Modelica Path` column) use the enumeration literals, which match the classes one to one (`Coils.WaterBasedCooling` → `Types.Coil.WaterBasedCooling`). The mogrifier then reads `value` only, and the mappings test checks that every mapped element is not replaceable.

Expand Down Expand Up @@ -283,7 +283,7 @@ Both are stored in `server/scripts/sequence-doc/tests/static/golden` and are reg
- `ctrlflow.keys`: `parse_key`, and the key patterns of mappings files (`expand_pattern`, `is_pattern`).
- `ctrlflow.payload`: `SCHEMA_VERSION`, `PayloadError`, `check_schema_version`.

How the values are gathered is left to each consumer: the sequence document takes the union of the values of a project across its configurations (`sequence_payload.py`), which an XLS editor of the values of each configuration must not do.
How the values are read is left to each consumer: the sequence document evaluates its toggles on each configuration of a project, and keeps a section if one configuration needs it (`sequence_payload.py`, `toggles.py`).

## Prerequisites

Expand Down Expand Up @@ -311,7 +311,7 @@ Issues found by the probe, unrelated to quoted identifiers:

## Known limitations

- **Configurations of the same template.** The sequence document has one section per system type: the values of the configurations of the same template are merged, and a section is kept if any configuration of that type needs it (see "Sections of System Types" in [sequence-doc.md](sequence-doc.md)).
- **Configurations of the same template.** The sequence document has one section per system type: a section is kept if any configuration of that type needs it (see "Evaluation" and "Sections of System Types" in [sequence-doc.md](sequence-doc.md)).

- **Replaceable short classes.** Before #620, short-class choices were written under one key (`…ShortClass-ShortClass`) and read under another (`…ShortClass-.FirstComponent`). The choice is now written and read at the short class element (rule 4, `T-ShortClass`). The parameters of the selected class are still displayed and keyed under the class name (`T-ShortClass.container`) rather than under the instance, and selecting another class does not change how the instance resolves. No template in `templates.json` uses a replaceable short class in the configuration panel. The display and resolution of short class instances are tracked separately.
- **Spellings of quoted identifiers.** A source that spells a quoted identifier with and without a redundant escape (`'a\?'` and `'a?'`, `'a\"'` and `'a"'`) is not supported: ctrl-flow keeps identifiers as written, like Dymola and OCT, which reject such a source, although MLS §2.3.1 makes both spellings the same identifier.
52 changes: 36 additions & 16 deletions docs/sequence-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,46 @@ The annotation text and ONLY the annotation text (which includes the brackets) h

### Example Annotations:

+ `[YES CO2]` – Keep this section if a CO2 sensor is present. Otherwise remove.
+ `[NO CO2]` – Keep this section if a CO2 sensor is not present. Otherwise remove.
+ `[EQUALS BSP RELIEFDMPR]` – Keep this section if the type of building pressure control system is an actuated relief damper, with relief fan(s). Otherwise remove.
+ `[NOT_EQUALS BSP RELIEFDMPR]` - Keep this section if the type of building pressure control system is *not* an actuated relief damper, with relief fans(s). Otherwise remove.
+ `[ANY BSP RETURNTRACK]` – Keep this section if the type of building pressure control system is a return fan, tracking measured supply and return airflow or a return fan, tracking calculated supply and return airflow. Otherwise remove.
+ `[AND [any toggle] [any toggle]]` - Keep this section if both nested toggles would keep the section. The nested toggles can be any of these toggles including AND or OR. Otherwise remove.
+ `[OR [any toggle] [any toggle]]` - Keep this section if one of the nested toggles would keep the section. The nested toggles can be any of these toggles including AND or OR. Otherwise remove.
+ `[YES CO2]` – Keep this section if a configuration has a CO2 sensor. Otherwise remove.
+ `[NO CO2]` – Keep this section if a configuration has no CO2 sensor. Otherwise remove.
+ `[EQUALS BSP RELIEFDMPR]` – Keep this section if the type of building pressure control system of a configuration is an actuated relief damper, with relief fan(s). Otherwise remove.
+ `[NOT_EQUALS BSP RELIEFDMPR]` - Keep this section if the type of building pressure control system of a configuration is *not* an actuated relief damper, with relief fans(s). Otherwise remove.
+ `[ANY BSP RETURNTRACK]` – Keep this section if the type of building pressure control system of a configuration is a return fan, tracking measured supply and return airflow or a return fan, tracking calculated supply and return airflow. Otherwise remove.
+ `[AND [any toggle] [any toggle]]` - Keep this section if both nested toggles are true on the same configuration. The nested toggles can be any of these toggles including AND, OR or NONE. Otherwise remove.
+ `[OR [any toggle] [any toggle]]` - Keep this section if one of the nested toggles is true on a configuration. The nested toggles can be any of these toggles including AND, OR or NONE. Otherwise remove.
+ `[NONE [any toggle]]` - Keep this section if the nested toggle is true on no configuration. Otherwise remove.
+ `[DELETE]` - Remove this section.

Table annotations

Example table toggles:
+ `[TABLE YES CO2]` - Keep the whole table if a CO2 sensor is present. Otherwise remove.
+ `[ROW YES CO2]` - Keep this row if a CO2 sensor is present. Otherwise remove.
+ `[ROW YES CO2]` or `[ROW [YES CO2]]` - Keep this row if a CO2 sensor is present. Otherwise remove.
+ `[COLUMN YES CO2]` - Keep this column if a CO2 sensor is present. Otherwise remove.
+ `[COLUMN AND [any toggle] [any toggle]]` - Keep this column if both nested toggles would keep the column. Otherwise remove.

### Evaluation

An annotation is evaluated on each configuration of the project, with the values of the configuration, the project settings, and for a system type, the template of the configuration if it has that system type. **A section is kept if its annotation is true on at least one configuration.** A project without configurations is evaluated on the project settings alone.

- Each key has one value on a configuration, so `NO` is the negation of `YES`, and `NOT_EQUALS` the negation of `EQUALS`.
- A key that a configuration does not have satisfies no annotation on it, including `NO` and `NOT_EQUALS`. Otherwise an AHU, which has no `have_CO2Sen`, would satisfy `[NO CO2]`. A system type that the project doesn't use has no keys: `YES`, `NO`, `EQUALS`, `NOT_EQUALS` and `ANY` are then false. In `[OR [YES CO2_PFBCV] [YES CO2_SFBCV]]`, a missing system type therefore doesn't delete the section.
- `AND` is true on a configuration if both operands are true on that configuration: two configurations that each satisfy one operand do not keep the section. For the same reason, an `AND` cannot combine keys of two system types, which no configuration has: `tests/test_section_scope.py` rejects it. A `NONE` operand is allowed, as it has the same value on all configurations.
- An invalid annotation or an unknown short ID is an error, and no document is generated. Otherwise a misspelled `NONE` operand would be false, and keep the section.

**`NONE`.** `[NO CO2]` and `[NONE [YES CO2]]` differ when the configurations differ:

| Zones | `[NO CO2]` | `[NONE [YES CO2]]` |
|---|---|---|
| All with a CO2 sensor | removed | removed |
| Some with a CO2 sensor | kept | removed |
| None with a CO2 sensor | kept | kept |
| No zone | removed | kept |

`[NO CO2]` is for a section that applies to each zone without a sensor. `NONE` is for a section that one configuration is enough to rule out. This is the case of a section of a system that depends on the systems it serves: `[NONE [YES CO2]]` for the setpoint of an AHU that no zone resets, and `[NONE [ANY VAV DDDIS]]` for a totalization of the airflow of the boxes that needs all boxes to measure it. `[NONE [AND [YES A] [YES B]]]` is true if no configuration satisfies both operands.

**Enclosing headings.** A section is removed with its heading, and otherwise only depends on its own annotation. A heading and a section it encloses can therefore be satisfied by different configurations. If they must be the same one, the annotation of the section states it with `AND`: under `[OR [OR [YES WIN] [YES OCC]] [YES CO2]]`, `[AND [OR [YES OCC] [YES CO2]] [NO WIN]]` needs a zone with a sensor and no window switch, whereas `[NO WIN]` would be satisfied by another zone than the one that keeps the heading.

### Scope of an Annotation

The section removed by an annotation depends on the style of the paragraph that starts with the annotation:
Expand Down Expand Up @@ -95,21 +118,18 @@ Going back to the example annotation:

These long paths can then be used to resolve the annotation in the script.

A key is `<template>-<elementPath>`, see [selection-keys.md](selection-keys.md). A key pattern lists several templates, e.g. `CO2` maps to `Buildings.Templates.ZoneEquipment.{VAVBoxCoolingOnly|VAVBoxReheat}-ctl.have_CO2Sen`: the annotation is evaluated against the values of `ctl.have_CO2Sen` in all configurations of both templates (see the "Mappings" section of [selection-keys.md](selection-keys.md)).
A key is `<template>-<elementPath>`, see [selection-keys.md](selection-keys.md). A key pattern lists several templates of one system type, e.g. `CO2` maps to `Buildings.Templates.ZoneEquipment.{VAVBoxCoolingOnly|VAVBoxReheat}-ctl.have_CO2Sen`: on a configuration of either template, the annotation reads `ctl.have_CO2Sen` of that template (see the "Mappings" section of [selection-keys.md](selection-keys.md)).

### Sections of System Types

A short ID maps to one key or key pattern, wherever it is used in the source document. Which one to use depends on the section:

- A section of a single system type (toggled by a system type, e.g. `[EQUALS VAV RH]`) uses short IDs of the template of that system type, e.g. `TERM_HT_RH` → `Buildings.Templates.ZoneEquipment.VAVBoxReheat-coiHea.typ`. Otherwise the values of another template would keep or delete the section. A section toggled by several templates of a system type, e.g. `[ANY VAV PFBCV SFBCV]`, combines short IDs of these templates, e.g. `[OR [YES NC_PFBCV] [YES NC_SFBCV]]`. `tests/test_section_scope.py` checks that such sections read no key of another template of the same system type, and that the sections of the templates listed for the default version are found. Keys of other system types are not restricted: e.g. a section of the AHU reads the CO2 sensors of all zones.
- A section shared by several system types uses a key pattern, whose values are merged across the templates (e.g. `CO2`: kept if any zone has a CO2 sensor), or combines short IDs of each template, e.g. `[OR [YES CO2_PFBCV] [YES CO2_SFBCV]]`.

Combined toggles have the following limits:
- A section shared by several system types uses a key pattern, read on each configuration of its templates (e.g. `CO2`: kept if any zone has a CO2 sensor), or combines short IDs of each template, e.g. `[OR [YES CO2_PFBCV] [YES CO2_SFBCV]]`.

- `AND` and `OR` take exactly two operands, and a nested toggle is only parsed as the first operand: `[AND [YES C] [OR [YES A] [YES B]]]` is mis-split. Write `[AND [OR [YES A] [YES B]] [YES C]]` instead.
- A system type the project doesn't use has no keys: `YES`, `NO`, `EQUALS` and `ANY` then delete the section, and `NOT_EQUALS` keeps it. In `[OR [YES CO2_PFBCV] [YES CO2_SFBCV]]`, a missing system type therefore doesn't delete the section.
`AND` and `OR` take exactly two operands, each of which can be a nested toggle.

The configurations of the same template are merged: a section of a system type is kept if any configuration of that type needs it.
A section of a system type is kept if any configuration of that type needs it (see Evaluation).

TODO: add info about each column

Expand All @@ -128,7 +148,7 @@ The source document and the mappings file are in `server/scripts/sequence-doc/sr
- Write the `Modelica Parameter` column with selection keys or key patterns of elements that hold a value (see Mappings).
- Run the tests:
- `client/tests/sequence/mappings.test.ts` checks that every key of the mappings is the key under which ctrl-flow stores the value of the element, and that the element is not replaceable: otherwise the key has no value in the payload, and the toggle treats the value as missing.
- `server/scripts/sequence-doc/tests/test_section_scope.py` checks that every toggle has a valid format and uses short IDs of the mappings, that every heading is numbered by a list (see Heading Numbering), and that the sections of system types read the keys of their templates only (see Sections of System Types). Add the templates of a new version to `SECTIONS`. Typed heading numbers cannot be told apart from a title that starts with a number, e.g. `1.5 minutes`: check them in Word.
- `server/scripts/sequence-doc/tests/test_section_scope.py` checks that every toggle has a valid format and uses short IDs of the mappings, that an `AND` or a key pattern reads one system type (see Evaluation), that every heading is numbered by a list (see Heading Numbering), and that the sections of system types read the keys of their templates only (see Sections of System Types). Add the templates of a new version to `SECTIONS`. Typed heading numbers cannot be told apart from a title that starts with a number, e.g. `1.5 minutes`: check them in Word.
- `server/scripts/sequence-doc/tests/test_golden.py` compares the generated documents to the expected texts. If the changes of the document are intended, regenerate the expected texts with `UPDATE_GOLDEN=1` and review their diff.

Always update both the mappings and source file.
7 changes: 4 additions & 3 deletions server/scripts/sequence-doc/src/generate_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
import csv
from mogrifier import mogrify_doc
from sequence_payload import project_selections, delete_info_box
from sequence_payload import configuration_values, delete_info_box, project_values


DEFAULT_DOC_VERSION = 'Current G36 Decisions'
Expand Down Expand Up @@ -62,7 +62,8 @@ def generate_doc(payload, version) -> Document:

This is separated from main for easier testing
'''
selections = project_selections(payload)
project = project_values(payload)
configurations = configuration_values(payload)
local_file_prefix = get_local_path_prefix(version)

# load source document starting point
Expand All @@ -73,7 +74,7 @@ def generate_doc(payload, version) -> Document:
short_code_path = local_file_prefix / MAPPING_FILE_PATH
name_map = generate_name_map(short_code_path)

return mogrify_doc(document, name_map, selections, delete_info_box(payload))
return mogrify_doc(document, name_map, project, configurations, delete_info_box(payload))

def main():
'''
Expand Down
Loading