Machines - Snailz Docs

Skip to content

# Machines

Laboratory machinery.

## `Machine`

Bases: `BaseModel`

A piece of experimental machinery.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`ident` | `str` | machine ID | required
`name` | `str` | machine name | required
`brightness` | `float` | brightness amplification | `1.0`

Source code in `src/snailz/machines.py`

    68
    69
    70
    71
    72
    73
    class Machine(BaseModel):
        """A piece of experimental machinery."""

        ident: str = Field(description="machine ID")
        name: str = Field(description="machine name")
        brightness: float = Field(default=1.0, ge=0, description="brightness amplification")

## `AllMachines`

Bases: `BaseModel`

A set of generated machines.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`items` | `list[Machine]` | all machinery | required

Source code in `src/snailz/machines.py`

     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    class AllMachines(BaseModel):
        """A set of generated machines."""

        items: list[Machine] = Field(description="all machinery")

        def to_csv(self) -> str:
            """Return a CSV string representation of the machines.

            Returns:
                A CSV-formatted string.
            """
            return utils.to_csv(
                self.items,
                ["ident", "name"],
                lambda m: [m.ident, m.name],
            )

        @staticmethod
        def generate(params: MachineParams) -> "AllMachines":
            """Generate laboratory machinery.

            Parameters:
                params: machine generation parameters

            Returns:
                A set of equipment.
            """
            name_gen = utils.unique_id("machine", _machine_name_generator)
            return AllMachines(
                items=[
                    Machine(
                        ident=f"M000{i + 1}",
                        name=next(name_gen),
                        brightness=model.machine_brightness(params),
                    )
                    for i in range(params.number)
                ]
            )

### `to_csv()`

Return a CSV string representation of the machines.

Returns:

Type | Description
--- | ---
`str` | A CSV-formatted string.

Source code in `src/snailz/machines.py`

    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    def to_csv(self) -> str:
        """Return a CSV string representation of the machines.

        Returns:
            A CSV-formatted string.
        """
        return utils.to_csv(
            self.items,
            ["ident", "name"],
            lambda m: [m.ident, m.name],
        )

### `generate(params)` `staticmethod`

Generate laboratory machinery.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`params` | `MachineParams` | machine generation parameters | required

Returns:

Type | Description
--- | ---
`AllMachines` | A set of equipment.

Source code in `src/snailz/machines.py`

     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    @staticmethod
    def generate(params: MachineParams) -> "AllMachines":
        """Generate laboratory machinery.

        Parameters:
            params: machine generation parameters

        Returns:
            A set of equipment.
        """
        name_gen = utils.unique_id("machine", _machine_name_generator)
        return AllMachines(
            items=[
                Machine(
                    ident=f"M000{i + 1}",
                    name=next(name_gen),
                    brightness=model.machine_brightness(params),
                )
                for i in range(params.number)
            ]
        )

## `_machine_name_generator()`

Generate random name for a machine.

Source code in `src/snailz/machines.py`

    116
    117
    118
    119
    120
    121
    def _machine_name_generator():
        """Generate random name for a machine."""
        name = f"{utils.choose_one(PREFIX)}{utils.choose_one(MAIN)}"
        if random.uniform(0.0, 1.0) < PROB_SUFFIX:
            name = f"{name} {utils.choose_one(SUFFIX)}"
        return name