hertzforge.report¶
report
¶
Render a Report to one self-contained HTML file.
The reader opens the file in the browser they already have, with
nothing to install, no network, and no third-party code inside the file.
Everything interactive is JavaScript written for this package (about
2,200 lines, in page.py): an orthographic 3-D scene the reader can
turn, which animates mode shapes with the same phase arithmetic as the
desktop animator, and zoomable plots with the app's own axis labels.
The data is carried as one JSON payload, already converted to the
display unit system, so the file shows what the screen showed.
Functions:
| Name | Description |
|---|---|
render_html |
The report as one HTML document string. |
resolve_references |
Replace each {{Object Name.field}} in report text with the |
block_caption |
The caption block a plot block's first figure carries, or None. |
scalogram_channel_options |
The DOF names a scalogram block can draw, for the editor's |
export_html |
Write one interactive figure as a single self-contained HTML file. |
export_figure |
Write one interactive figure as a JSON data file, and optionally |
Classes¶
Functions:¶
render_html
¶
render_html(report: Report, objects: Mapping[str, Any], unit_system: UnitSystem | None = None, edit: bool = False, channel_js: str | None = None, object_groups: Sequence[Mapping[str, Any]] | None = None, selected: int | None = None, labels: list[tuple[str, str]] | None = None, fill: bool = False, theme: str | None = None) -> str
The report as one HTML document string.
objects maps names to the project's objects, and unit_system is
the display unit system (the default system when None).
object_groups is the project's object groups: symbolic bindings
such as '@basis:Frf' are resolved against them, so a report depends
on how the project is linked, not on what its objects are named.
The reading page (edit False) leaves out blocks whose references
cannot be resolved, since an unbound block in a template is a place
to fill, not an error to show a reader. The edit page (edit True)
shows them as cards to bind again, tags every block with its index,
frames the block at selected, and sends one message to the app over
Qt's web channel: which block was clicked. channel_js is the text
of Qt's qwebchannel.js to put inline in the edit page; without it the
page loads it from qrc:. All editing is done from the app's bar and
pane, and the page has no insert bars, block toolbars or editors.
Only the app loads the edit page; an exported file has none of it.
labels, when given, is filled with (label, caption) for every
numbered figure and table, in order: what the editor's Reference
menu offers, with the same numbering the page shows.
The report features enabled on report (report.features) act
here, each only as its description says; with none enabled the
document is the one this function has always written, byte for
byte.
fill makes the page one figure filling its frame, without a title,
marking or theme toggle (export_html). theme, 'light' or 'dark',
fixes the page's theme, which otherwise follows the reader's.
resolve_references
¶
resolve_references(text: str, objects: Mapping[str, Any], us: UnitSystem, object_groups: Sequence[Mapping[str, Any]] | None = None) -> str
Replace each {{Object Name.field}} in report text with the
object's current value, formatted in the unit system us.
This is what makes templates work: a summary that says how the data
was sampled fills itself in, in whatever project the template is
used. The name may be a symbolic selector, such as
{{@basis:TimeHistory.sample_rate}}, resolved against object_groups,
so the text does not depend on the objects' names either. A
reference that cannot be resolved (no such object, or a field the
object does not have) is left in the text as written, the same way
an unbound block is left as a place to fill.
block_caption
¶
block_caption(block: Mapping[str, Any], objects: Mapping[str, Any], object_groups: Sequence[Mapping[str, Any]] | None = None, unit_system: UnitSystem | None = None) -> Any
The caption block a plot block's first figure carries, or None.
What the report editor reads out beside a plot block: the caption
Project.caption_of reads for the records the figure opens on: the
channel the block names, else the first channel the block's
requirement names, else the records its filter keeps that the
first figure draws. None when the block draws no measured record a
caption reads (report_caption.caption_kind), draws a grid, or the
objects are not a project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block
|
mapping
|
The plot block. |
required |
objects
|
Project
|
The project the report reads. |
required |
object_groups
|
sequence of mapping
|
The project's object groups, for symbolic bindings. |
None
|
unit_system
|
UnitSystem
|
The display units. |
None
|
Returns:
| Type | Description |
|---|---|
(RecordCaption, SrsCaption, SineCaption, TimeCaption or None)
|
|
scalogram_channel_options
¶
scalogram_channel_options(block: Mapping[str, Any], objects: Mapping[str, Any], object_groups: Sequence[Mapping[str, Any]] = ()) -> list[str]
The DOF names a scalogram block can draw, for the editor's drop-down list. The figure shows one channel, so the person editing the report chooses which.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block
|
dict
|
The scalogram plot block. |
required |
objects
|
mapping
|
The report's objects, name to object. |
required |
object_groups
|
sequence
|
The project's object groups, for symbolic source bindings. |
()
|
Returns:
| Type | Description |
|---|---|
list of str
|
The response DOFs the block's |
export_html
¶
export_html(path: str | PathLike, data: Any = None, *, specification: Any = None, channel: str | None = None, mode: str = 'curves', geometry: Any = None, shapes: Any = None, dofs: tuple[Any, ...] | None = None, name: str | None = None, caption: str = '', theme: str | None = None, unit_system: UnitSystem | None = None, fill: bool = True, channels: Sequence[str] | None = None, max_points: int | None = None, component: str = 'magnitude', frame: Sequence[str] | None = None, node_dots: bool | None = None) -> str
Write one interactive figure as a single self-contained HTML file.
hertzforge.export_html('spec.html', psd, specification=spec,
channel='101Z+', theme='light')
hertzforge.export_html('modes.html', geometry=g, shapes=modes)
The figure is the one a report draws, with zoom, pan and the readout
on a plot, and turning and animation on a scene, and nothing else:
no title and no marking. With fill the figure fills whatever frame
holds it, such as an iframe or a box on a slide, and redraws when the
frame changes size. Everything the page needs is in the file, so it
opens offline.
Given a geometry, the figure is a scene of it, with its shapes
animating or, with dofs, the DOFs one object measures as a
quantity, ('acceleration', frf), drawn as labeled arrows; a
test's DOFs drawn on a model, ('acceleration', history, test),
are placed by position on it rather than by node id.
frame names element groups of the geometry the scene opens
framed on, the rest of it still drawn around them; the shapes
still swing by the whole model's size. Otherwise it is a plot of data, against specification and its
zones when one is given, of one channel when named, in mode
('curves', 'stage', 'cmif', 'mac' or 'map').
channels and max_points make the file smaller: the first keeps
only those records of data (and of specification), the second
thins every curve of a plot to that many points, keeping every
peak and dip, and says so under the figure. export_figure writes
the same figure as a data file and a script, for a page that cannot
carry an inline script.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or path - like
|
Where the .html goes. |
required |
data
|
DataArray or ShapeSet
|
What a plot draws. |
None
|
specification
|
Specification
|
What |
None
|
channel
|
str
|
The one control channel of a comparison to draw. |
None
|
mode
|
str
|
The plot's reading. |
'curves'
|
geometry
|
Geometry
|
Makes the figure a scene. |
None
|
shapes
|
ShapeSet
|
What the scene animates. |
None
|
dofs
|
(str, object) or (str, object, Geometry)
|
A quantity and an object: its DOFs of that quantity, as arrows.
Their node ids are |
None
|
name
|
str
|
What the legend calls |
None
|
caption
|
str
|
A line under the figure. |
''
|
theme
|
('light', 'dark')
|
Fixes the figure's theme; unset, it follows the reader's. |
'light'
|
unit_system
|
UnitSystem
|
The units it is drawn in. |
None
|
fill
|
bool
|
Fill the frame; False lays it out as the report page does. |
True
|
channels
|
sequence of str
|
The records of |
None
|
max_points
|
int
|
The most points a plot's curve keeps; at least 16. |
None
|
component
|
('magnitude', 'phase', 'real', 'imag')
|
How a plot of complex data reads, as the app's drop-down reads it. |
'magnitude'
|
frame
|
sequence of str
|
Element groups of |
None
|
node_dots
|
bool
|
Draw a dot at each node of the scene. Unset, the dots are drawn
on a geometry of at most |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The path written. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When neither |
export_figure
¶
export_figure(path: str | PathLike, data: Any = None, *, renderer: str | PathLike | None = None, specification: Any = None, channel: str | None = None, mode: str = 'curves', geometry: Any = None, shapes: Any = None, dofs: tuple[Any, ...] | None = None, name: str | None = None, caption: str = '', theme: str | None = None, unit_system: UnitSystem | None = None, fill: bool = False, channels: Sequence[str] | None = None, max_points: int | None = None, component: str = 'magnitude', frame: Sequence[str] | None = None, node_dots: bool | None = None) -> str
Write one interactive figure as a JSON data file, and optionally the script that draws it, for a page that mounts the figure itself.
hertzforge.export_figure('spec.json', psd, specification=spec,
channel='101Z+', theme='light',
renderer='hertzforge-figure.js')
The figure is the one export_html writes, split in two. The data
file holds this figure alone. The renderer is one script for every
figure, the same viewers the HTML file carries; a page loads it from
its own site and draws a figure into an element of its own:
<div id="spec"></div>
<script src="hertzforge-figure.js"></script>
<script src="page.js"></script> // HertzforgeFigure.load(
// element, 'spec.json')
So a page whose Content-Security-Policy allows no inline script and
no frames can still show the figure. HertzforgeFigure.mount(
element, data, options) draws data already fetched, and load(
element, url, options) fetches it first; with {pageScroll:
true} the figure leaves the wheel and a vertical swipe to the
page and zooms on Ctrl or Cmd with the wheel. The figure's styles
are scoped to that element. The renderer refuses data written for
another format (FIGURE_FORMAT), so a page never draws a figure it
would misread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or path - like
|
Where the .json goes. |
required |
data
|
DataArray or ShapeSet
|
What a plot draws. |
None
|
renderer
|
str or path - like
|
Where to write the renderer script as well. It is the same for every figure this version writes, so a page needs it once. |
None
|
specification
|
Specification
|
What |
None
|
channel
|
str
|
The one control channel of a comparison to draw. |
None
|
mode
|
str
|
The plot's reading. |
'curves'
|
geometry
|
Geometry
|
Makes the figure a scene. |
None
|
shapes
|
ShapeSet
|
What the scene animates. |
None
|
dofs
|
(str, object) or (str, object, Geometry)
|
A quantity and an object: its DOFs of that quantity, as arrows.
Their node ids are |
None
|
name
|
str
|
What the legend calls |
None
|
caption
|
str
|
A line under the figure. |
''
|
theme
|
('light', 'dark')
|
Fixes the figure's theme; unset, it follows the reader's. |
'light'
|
unit_system
|
UnitSystem
|
The units it is drawn in. |
None
|
fill
|
bool
|
Lay the figure out as the report page does, at its own height; True fills the element, which must then have a height. |
False
|
channels
|
sequence of str
|
The records of |
None
|
max_points
|
int
|
The most points a plot's curve keeps; at least 16. |
None
|
component
|
('magnitude', 'phase', 'real', 'imag')
|
How a plot of complex data reads, as the app's drop-down reads it. |
'magnitude'
|
frame
|
sequence of str
|
Element groups of |
None
|
node_dots
|
bool
|
Draw a dot at each node of the scene. Unset, the dots are drawn
on a geometry of at most |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The data file's path. |
Raises:
| Type | Description |
|---|---|
ValueError
|
As |