pypdevsbbl.generic.transformers module¶
Set of PythonPDEVS building blocks for transforming data.
The classes in this file concern themselves with message transformations throughout a system and can come in useful in numerous situations.
-
class
pypdevsbbl.generic.transformers.Transformer(name: str, T=<function Transformer.<lambda>>)[source]¶ Bases:
pypdevs.DEVS.AtomicDEVSTransforms data w.r.t. a function.
Note
The transformation itself happens upon arrival of a new item. The more expensive the transformation function, the more expensive the usage of this block. Keep this in mind when modeling for real-time simulations.
Parameters: - name (str) – The name of the block.
- T (def) – Function that defines the transformation. It takes 3 arguments: i (the item), e (the elapsed time) and t (the total time). And it will return the transformed item. Defaults to the item itself.
State: - time (numeric) – The total elapsed time.
- transformed (any) – The transformed item.
- original (any) – The original item (before transformation).
Input Ports: input (any) – The item to transform.
Output Ports: - transformed (any) – The transformed item.
- original (any) – The original item (before transformation).
-
class
pypdevsbbl.generic.transformers.LookupTable(name: str, table: dict, default=None)[source]¶ Bases:
pypdevsbbl.generic.transformers.TransformerFinds the value in a lookup table.
Parameters: - name (str) – The name of the block.
- table (dict) – The lookup table. Each input is mapped on a key in this table, which is outputted.
- default (any) – The default value if no mapping exists.
Defaults to
None.
State: - time (numeric) – The total elapsed time.
- transformed (any) – The transformed item.
- original (any) – The original item (before transformation).
Input Ports: input (any) – The item to look up.
Output Ports: - transformed (any) – The looked up item.
- original (any) – The original item (before lookup).
-
class
pypdevsbbl.generic.transformers.Pack(name: str, package=<class 'pypdevsbbl.extra.packaging.Package'>, *args)[source]¶ Bases:
pypdevs.DEVS.AtomicDEVSCollects all input in a generic package.
A group of items is captured on this block’s input. Based on a predefined package (see
pypdevsbbl.extra.packagingsubmodule), the elapsed time and the simulation time, there can be deduced how the items can be combined.As soon as a message arrives on the release input, the package is released on the out port and the state is reset. Additionally, if the
pypdevsbbl.extra.packaging.Package.finished()function of evaluatesTrueafter packing, the package will be released automatically.Parameters: - name (str) – The name of the block.
- package – The package class in which to combine all input.
Defaults to a generic
pypdevsbbl.extra.packaging.Package. - *args – Additional list of arguments to be passed to the Package class upon construction. This is empty by default.
State: - package (Package) – See
pypdevsbbl.extra.packaging.Package. - release (bool) – Whether or not a release was requested.
- time (numeric) – The total simulation time.
Input Ports: - input (any) – The object to add to the package.
- release (any) – When the package needs to be released.
Output Ports: output (Package) – A package.
-
class
pypdevsbbl.generic.transformers.Unpack(name: str)[source]¶ Bases:
pypdevs.DEVS.AtomicDEVSReleases the contents of a package.
When a
pypdevsbbl.extra.packaging.Packagearrives on the input, it is unpacked and the list of contents is afterwards outputted on the out port.Parameters: name (str) – The name of the block. State: contents (list) – The list of contents of the package. Input Ports: input (Package) – The package to unpack. Output Ports: output (list) – All contents of the package.