diff --git a/client/package-lock.json b/client/package-lock.json index ac38fbcb..e7b23898 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -48,7 +48,7 @@ "ts-jest": "^29.0.3", "ts-node": "^10.9.1", "uuid": "^14.0.0", - "vite": "^6.3.5" + "vite": "^6.4.5" } }, "node_modules/@adobe/css-tools": { @@ -14442,9 +14442,9 @@ } }, "node_modules/vite": { - "version": "6.4.3", - "resolved": "https://registry.npmjs.org/vite/-/vite-6.4.3.tgz", - "integrity": "sha512-NTKlcQjlAK7MlQoyb6LgaqHc8sso/pVyUJYWMws3jg21uTJw/LddqIFPcPqP6PzpgbIcZyKI85sFE4HBrQDA8A==", + "version": "6.4.5", + "resolved": "https://registry.npmjs.org/vite/-/vite-6.4.5.tgz", + "integrity": "sha512-4enwjFfi4IwtEh0w+jPzpLVOFQiPHmmzPxcHXQOyEur47o6u0jE573DmGpjA+7irXoMLYRZD5ZaFUEneS3abPg==", "dev": true, "license": "MIT", "dependencies": { diff --git a/client/package.json b/client/package.json index 59bc7094..44b0d9d7 100644 --- a/client/package.json +++ b/client/package.json @@ -71,6 +71,6 @@ "ts-jest": "^29.0.3", "ts-node": "^10.9.1", "uuid": "^14.0.0", - "vite": "^6.3.5" + "vite": "^6.4.5" } } diff --git a/client/src/data/templates.json b/client/src/data/templates.json index 53a772a5..ecc79746 100644 --- a/client/src/data/templates.json +++ b/client/src/data/templates.json @@ -1,6 +1,6 @@ { "libraries": { - "Buildings": "14.0.0" + "Buildings": "15.0.0" }, "templates": [ { @@ -241,6 +241,7 @@ "replaceable": false, "options": [ "Buildings.Templates.Components.Actuators.Valve.typ", + "Buildings.Templates.Components.Actuators.Valve.l", "Buildings.Templates.Components.Actuators.Valve.is_twoWay", "Buildings.Templates.Components.Actuators.Valve.is_thrWay", "Buildings.Templates.Components.Actuators.Valve.is_actTwo", @@ -390,6 +391,20 @@ "Buildings.Templates.Components.Types.Valve" ] }, + { + "modelicaPath": "Buildings.Templates.Components.Actuators.Valve.l", + "type": "Real", + "name": "Valve leakage, l=Kv(y=0)/Kv(y=1)", + "group": "Configuration", + "tab": "", + "visible": true, + "enable": false, + "modifiers": {}, + "replaceable": false, + "options": [], + "definition": false, + "shortExclType": false + }, { "modelicaPath": "Buildings.Templates.Components.Actuators.Valve.is_twoWay", "type": "Boolean", @@ -794,13 +809,7 @@ { "operator": "if", "operands": [ - { - "operator": "==", - "operands": [ - "typ", - "Buildings.Templates.Components.Types.Valve.TwoWayModulating" - ] - }, + "is_twoWay", { "operator": "!=", "operands": [ @@ -930,13 +939,13 @@ "tab": "", "visible": false, "modifiers": { - "realTrue": { - "expression": 1, - "final": true - }, "realFalse": { "expression": 0, "final": true + }, + "realTrue": { + "expression": 1, + "final": true } }, "replaceable": false, @@ -1062,13 +1071,13 @@ "tab": "", "visible": false, "modifiers": { - "t": { - "expression": 0.99, - "final": false - }, "h": { "expression": 0.005, "final": false + }, + "t": { + "expression": 0.99, + "final": false } }, "replaceable": false, @@ -1183,13 +1192,13 @@ "tab": "", "visible": false, "modifiers": { - "t": { - "expression": 0.01, - "final": false - }, "h": { "expression": 0.005, "final": false + }, + "t": { + "expression": 0.01, + "final": false } }, "replaceable": false, @@ -1308,20 +1317,12 @@ "final": true, "redeclare": "Buildings.Fluid.Interfaces.PartialTwoPort.Medium" }, - "m_flow_nominal": { - "expression": "m_flow_nominal", - "final": true - }, - "dp_nominal": { - "expression": "dpFixed_nominal", - "final": true - }, "allowFlowReversal": { "expression": "allowFlowReversal", "final": true }, - "show_T": { - "expression": "show_T", + "dp_nominal": { + "expression": "dpFixed_nominal", "final": true }, "from_dp": { @@ -1331,6 +1332,14 @@ "linearized": { "expression": "linearized", "final": true + }, + "m_flow_nominal": { + "expression": "m_flow_nominal", + "final": true + }, + "show_T": { + "expression": "show_T", + "final": true } }, "replaceable": false, @@ -2171,6 +2180,7 @@ "kindOfClass": "model", "options": [ "Buildings.Templates.Components.Actuators.Valve.typ", + "Buildings.Templates.Components.Actuators.Valve.l", "Buildings.Templates.Components.Actuators.Valve.is_twoWay", "Buildings.Templates.Components.Actuators.Valve.is_thrWay", "Buildings.Templates.Components.Actuators.Valve.is_actTwo", @@ -13190,7 +13200,7 @@ { "modelicaPath": "Buildings.Templates.ZoneEquipment.Components.Controls.G36VAVBoxReheat.have_reqNeeHea", "type": "Boolean", - "value": false, + "value": true, "name": "Set to true if the controller generates a 'Need Heat' request", "group": "Configuration", "tab": "", @@ -13235,7 +13245,7 @@ { "modelicaPath": "Buildings.Templates.ZoneEquipment.Components.Interfaces.ControllerG36VAVBox.have_reqNeeCoo", "type": "Boolean", - "value": false, + "value": true, "name": "Set to true if the controller generates a 'Need Cool' request", "group": "Configuration", "tab": "", @@ -14531,7 +14541,7 @@ "value": 120, "name": "Sample period of component, set to the same value as the trim and respond that process static pressure reset", "group": "", - "tab": "Time-based suppresion", + "tab": "Time-based suppression", "visible": true, "enable": true, "modifiers": {}, @@ -14546,7 +14556,7 @@ "value": 540, "name": "Gain factor to calculate suppression time based on the change of the setpoint, seconds per Kelvin", "group": "", - "tab": "Time-based suppresion", + "tab": "Time-based suppression", "visible": true, "enable": true, "modifiers": {}, @@ -14561,7 +14571,7 @@ "value": 1800, "name": "Maximum suppression time", "group": "", - "tab": "Time-based suppresion", + "tab": "Time-based suppression", "visible": true, "enable": true, "modifiers": {}, @@ -16151,7 +16161,7 @@ "value": 120, "name": "Sample period of component, set to the same value as the trim and respond that process static pressure reset", "group": "", - "tab": "Time-based suppresion", + "tab": "Time-based suppression", "visible": true, "enable": true, "modifiers": {}, @@ -16166,7 +16176,7 @@ "value": 540, "name": "Gain factor to calculate suppression time based on the change of the setpoint, seconds per Kelvin", "group": "", - "tab": "Time-based suppresion", + "tab": "Time-based suppression", "visible": true, "enable": true, "modifiers": {}, @@ -16181,7 +16191,7 @@ "value": 1800, "name": "Maximum suppression time", "group": "", - "tab": "Time-based suppresion", + "tab": "Time-based suppression", "visible": true, "enable": true, "modifiers": {}, @@ -21131,7 +21141,7 @@ { "modelicaPath": "Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Controller.timSup", "type": "Buildings.Controls.OBC.ASHRAE.G36.Generic.TimeSuppression", - "name": "Specify suppresion time due to the setpoint change and check if it has passed the suppresion period", + "name": "Specify suppression time due to the setpoint change and check if it has passed the suppression period", "group": "", "tab": "", "visible": false, diff --git a/docs/sequence-doc.md b/docs/sequence-doc.md index 7f872792..20c94fdd 100644 --- a/docs/sequence-doc.md +++ b/docs/sequence-doc.md @@ -24,6 +24,8 @@ The annotation is enclosed in square brackets `[]` The annotation text and ONLY the annotation text (which includes the brackets) has a style applied: `Toggle`. This style is used as an identifier by the sequence document generation script to find annotations. +An annotation is a continuous stretch of text with the `Toggle` style within one paragraph: text with another style ends it. A Word comment anchored on an annotation, e.g. on a short ID, does not split it. A section removed by an annotation is removed with the comments anchored in it. + ### Example Annotations: + `[YES CO2]` – Keep this section if a configuration has a CO2 sensor. Otherwise remove. diff --git a/server/package-lock.json b/server/package-lock.json index 2dc96eec..bb4fdefd 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -2125,18 +2125,18 @@ "license": "MIT" }, "node_modules/body-parser": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.3.0.tgz", - "integrity": "sha512-2cGmJupaNgg+QUwVLAucDuWuoMZ6EX9iHDRswZ5lsNYEmwPaRknMPCLZz07yTzVq/83p4o/wzbDZbBrTvGGTIw==", + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.4.0.tgz", + "integrity": "sha512-Ifk1KcLrxaGt1occQagQNFNNOqRt1LFuehEnHHzB8Z6cRgIxRU1TBaiIsUiCdA+gy5PL7Y1IX31DNKkRmxtXjQ==", "license": "MIT", "dependencies": { "bytes": "^3.1.2", - "content-type": "^2.0.0", + "content-type": "^2.1.0", "debug": "^4.4.3", "http-errors": "^2.0.1", - "iconv-lite": "^0.7.2", + "iconv-lite": "^0.7.3", "on-finished": "^2.4.1", - "qs": "^6.15.2", + "qs": "^6.16.1", "raw-body": "^3.0.2", "type-is": "^2.1.0" }, @@ -5756,9 +5756,9 @@ "license": "MIT" }, "node_modules/qs": { - "version": "6.16.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.16.0.tgz", - "integrity": "sha512-h6fhOIaRrID2CbEY2fqs+7t+UXZo+MLAnU5gRIq85uFtdiUPCdsApMlHhXogKVM4HM2DVbIjGNTTYH2OcmP1vA==", + "version": "6.17.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.17.1.tgz", + "integrity": "sha512-jd3COkaKVgGUW+ZHyEHCG9bH7RoaaiWuMgzsIBjUMVjLAaWGWpoUAVwljVvBHxRu/2qEHnadLGZrkutYUBPQJA==", "license": "BSD-3-Clause", "dependencies": { "es-define-property": "^1.0.1", diff --git a/server/scripts/sequence-doc/src/mogrifier.py b/server/scripts/sequence-doc/src/mogrifier.py index 77b575e4..9f0c86a4 100644 --- a/server/scripts/sequence-doc/src/mogrifier.py +++ b/server/scripts/sequence-doc/src/mogrifier.py @@ -17,6 +17,9 @@ BOOKMARK_TAGS = ['{http://schemas.openxmlformats.org/wordprocessingml/2006/main}bookmarkEnd', "{http://schemas.openxmlformats.org/wordprocessingml/2006/main}bookmarkStart"] SECTION_TAG = ["{http://schemas.openxmlformats.org/wordprocessingml/2006/main}sectPr"] TABLE_TAG = '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}tbl' +W_NS = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main' +RUN_PROPERTIES_TAG = f'{{{W_NS}}}rPr' +COMMENT_REFERENCE_TAG = f'{{{W_NS}}}commentReference' ANNOTATION_STYLE = 'Toggle' UNITS_SHORT_NAME = 'UNITS' @@ -161,26 +164,40 @@ def get_column(table: Table, table_cell): if cell.text == table_cell.text: return column +def is_comment_reference(run): + ''' True if the run only holds the reference mark of a comment, which is + not text of the document (docs/sequence-doc.md, "Annotations") + ''' + content = [child for child in run.element if child.tag != RUN_PROPERTIES_TAG] + return len(content) == 1 and content[0].tag == COMMENT_REFERENCE_TAG + def create_control_structures(doc): ''' Sets up the control structure for Sections and Tables ''' control_structures = [] run_op_lookup = {} + def close(annotation): + ''' Adds an annotation once its last run is read ''' + if annotation: + annotation['text'] = annotation['text'].strip() + if annotation['text']: + control_structures.append(annotation) + current = None ## Sections for para in doc.paragraphs: for run in para.runs: + if is_comment_reference(run): + continue run_style_name = get_run_style_name(run) if ( (current and run_style_name != ANNOTATION_STYLE) or (current and para is not current['paragraph']) ): - current['text'] = current['text'].strip() - if current['text']: - control_structures.append(current) + close(current) current = None if not current and run_style_name == ANNOTATION_STYLE: @@ -195,6 +212,8 @@ def create_control_structures(doc): run_op_lookup[run.element] = current current['runs'].append(run) current['text'] += run.text + close(current) + current = None ## Tables for table in doc.tables: @@ -202,15 +221,15 @@ def create_control_structures(doc): for cell in row.cells: for para in cell.paragraphs: for run in para.runs: + if is_comment_reference(run): + continue run_style_name = get_run_style_name(run) if ( (current and run_style_name != ANNOTATION_STYLE) or (current and para is not current['paragraph']) ): - current['text'] = current['text'].strip() - if current['text']: - control_structures.append(current) + close(current) current = None if not current and run_style_name == ANNOTATION_STYLE: @@ -229,6 +248,7 @@ def create_control_structures(doc): run.op = current current['runs'].append(run) current['text'] += run.text + close(current) for op in control_structures: tokens = utils.remove_empty_strings(re.split(r'\W+', op['text'])) diff --git a/server/scripts/sequence-doc/src/version/DOD_20260828/sequenceWithTags.docx b/server/scripts/sequence-doc/src/version/DOD_20260828/sequenceWithTags.docx index 49bce997..898b2567 100644 Binary files a/server/scripts/sequence-doc/src/version/DOD_20260828/sequenceWithTags.docx and b/server/scripts/sequence-doc/src/version/DOD_20260828/sequenceWithTags.docx differ diff --git a/server/scripts/sequence-doc/tests/test_comments.py b/server/scripts/sequence-doc/tests/test_comments.py new file mode 100644 index 00000000..7d41a750 --- /dev/null +++ b/server/scripts/sequence-doc/tests/test_comments.py @@ -0,0 +1,140 @@ +''' +Comments anchored on annotations (docs/sequence-doc.md, "Annotations") + +Word places the reference mark of a comment right after the end of its range. +A comment anchored on part of an annotation puts that mark inside the +annotation. The mark is not text of the document, so it must not split the +annotation. An annotation is read up to its last run, even if no run +follows it. +''' +import pytest +from docx import Document +from docx.enum.style import WD_STYLE_TYPE +import mogrifier +import toggles + +NAME_MAP = { + 'A': 'P.A-c.p', + 'B': 'P.Types.B', + 'UNITS': 'P.AllSystems-sysUni', + 'SI': 'P.Units.SI', + 'IP': 'P.Units.IP', +} +SI_PROJECT = {'P.AllSystems-sysUni': 'P.Units.SI'} +IP_PROJECT = {'P.AllSystems-sysUni': 'P.Units.IP'} + + +def new_document(): + doc = Document() + doc.styles.add_style(mogrifier.ANNOTATION_STYLE, WD_STYLE_TYPE.CHARACTER) + return doc + + +def new_paragraph(doc, location): + ''' Empty paragraph in the body or in a table cell ''' + if location == 'body': + return doc.add_paragraph() + return doc.add_table(rows=1, cols=1).cell(0, 0).paragraphs[0] + + +def annotate(paragraph, parts, commented, style=mogrifier.ANNOTATION_STYLE): + ''' Adds the parts of an annotation as runs of the given style, with a + comment on the parts of index `commented`, and text after it + ''' + runs = [paragraph.add_run(part, style) for part in parts] + paragraph.part.document.add_comment( + [runs[i] for i in commented], text='Review', author='Reviewer') + paragraph.add_run(' Text') + return runs + + +def annotation_texts(doc): + control_structures, _ = mogrifier.create_control_structures(doc) + return [op['text'] for op in control_structures] + + +LOCATIONS = ['body', 'table'] + + +@pytest.mark.parametrize('location', LOCATIONS) +def test_comment_reference_does_not_split_an_annotation(location): + doc = new_document() + paragraph = new_paragraph(doc, location) + annotate(paragraph, ['[EQUALS A ', 'B', ']'], commented=[1]) + assert any(mogrifier.is_comment_reference(run) for run in paragraph.runs) + assert annotation_texts(doc) == ['[EQUALS A B]'] + + +@pytest.mark.parametrize('location', LOCATIONS) +@pytest.mark.parametrize('commented', [[0], [1], [2], [0, 1, 2]]) +def test_annotation_is_read_wherever_the_comment_is(location, commented): + doc = new_document() + annotate(new_paragraph(doc, location), ['[YES ', 'A', ']'], commented) + assert annotation_texts(doc) == ['[YES A]'] + + +@pytest.mark.parametrize('location', LOCATIONS) +def test_another_style_still_ends_an_annotation(location): + doc = new_document() + paragraph = new_paragraph(doc, location) + paragraph.add_run('[EQUALS A ', mogrifier.ANNOTATION_STYLE) + paragraph.add_run('B', mogrifier.ANNOTATION_STYLE) + paragraph.add_run(' ') + paragraph.add_run(']', mogrifier.ANNOTATION_STYLE) + paragraph.add_run(' Text') + texts = annotation_texts(doc) + assert texts == ['[EQUALS A B', ']'] + with pytest.raises(toggles.ToggleError, match='unbalanced brackets'): + toggles.parse(texts[0], NAME_MAP) + + +@pytest.mark.parametrize('location', LOCATIONS) +@pytest.mark.parametrize('project, text', [(SI_PROJECT, 'Setpoint 12 Pa Text'), (IP_PROJECT, 'Setpoint 0.05 in. Text')]) +def test_units_with_a_comment_reference_is_replaced(location, project, text): + doc = new_document() + paragraph = new_paragraph(doc, location) + paragraph.add_run('Setpoint ') + annotate(paragraph, ['[UNITS [12 Pa] ', '[0.05 in.]]'], commented=[0]) + mogrifier.mogrify_doc(doc, NAME_MAP, project, [project]) + assert paragraph.text == text + + +def comment_markers(doc): + ''' Comment IDs of each kind of marker of the body ''' + body = doc.element.body + return { + kind: sorted(element.get(f'{{{mogrifier.W_NS}}}id') for element in body.iter(f'{{{mogrifier.W_NS}}}{kind}')) + for kind in ('commentRangeStart', 'commentRangeEnd', 'commentReference') + } + + +@pytest.mark.parametrize('location', LOCATIONS) +def test_removed_sections_leave_complete_comments(location): + ''' A removed section takes the markers of its comments with it, and the + comments of a kept section keep all of their markers + ''' + doc = new_document() + annotate(new_paragraph(doc, location), ['[NO ', 'A', ']'], commented=[1]) + removed = doc.add_paragraph(style='Heading 1') + annotate(removed, ['[YES ', 'A', ']'], commented=[1]) + doc.add_paragraph('Removed') + kept_id = str(next(iter(doc.comments)).comment_id) + mogrifier.mogrify_doc(doc, NAME_MAP, {}, [{'P.A-c.p': False}]) + assert 'Removed' not in [paragraph.text for paragraph in doc.paragraphs] + markers = comment_markers(doc) + assert markers == {kind: [kept_id] for kind in markers} + + +@pytest.mark.parametrize('location', LOCATIONS) +def test_annotation_in_the_last_run_is_read(location): + ''' No run follows the annotation that ends the body or the last table ''' + doc = new_document() + new_paragraph(doc, location).add_run('[YES A]', mogrifier.ANNOTATION_STYLE) + assert annotation_texts(doc) == ['[YES A]'] + + +def test_annotation_that_ends_the_body_is_not_extended_by_a_table(): + doc = new_document() + doc.add_paragraph().add_run('[YES A]', mogrifier.ANNOTATION_STYLE) + new_paragraph(doc, 'table').add_run('[NO A]', mogrifier.ANNOTATION_STYLE) + assert annotation_texts(doc) == ['[YES A]', '[NO A]']