Person - Snailz Docs

Skip to content

# Person

Represent scientific staff.

## `Person`

Bases: `BaseModel`

A single person.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`id` | `str` | unique identifier | required
`family` | `str` | family name | required
`personal` | `str` | personal name | required

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

    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    class Person(BaseModel):
        """A single person."""

        id_stem: ClassVar[str] = "P"
        id_digits: ClassVar[int] = 4

        id: str = Field(min_length=1, description="unique identifier")
        family: str = Field(min_length=1, description="family name")
        personal: str = Field(min_length=1, description="personal name")

        @staticmethod
        def make(params):
            """Make a person."""

            utils.ensure_id_generator(Person)
            if not hasattr(Person, "_fake"):
                Person._fake = faker.Faker(params.locale)
                Person._fake.seed_instance(random.randint(0, 1_000_000))

            return Person(
                id=next(Person._id_gen),
                family=Person._fake.last_name(),
                personal=Person._fake.first_name(),
            )

        @staticmethod
        def csv_header():
            """Generate header for CSV file."""

            return "id,family,personal"

        def __str__(self):
            """Convert to CSV string."""

            return f"{self.id},{self.family},{self.personal}"

### `make(params)` `staticmethod`

Make a person.

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

    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    @staticmethod
    def make(params):
        """Make a person."""

        utils.ensure_id_generator(Person)
        if not hasattr(Person, "_fake"):
            Person._fake = faker.Faker(params.locale)
            Person._fake.seed_instance(random.randint(0, 1_000_000))

        return Person(
            id=next(Person._id_gen),
            family=Person._fake.last_name(),
            personal=Person._fake.first_name(),
        )

### `csv_header()` `staticmethod`

Generate header for CSV file.

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

    37
    38
    39
    40
    41
    @staticmethod
    def csv_header():
        """Generate header for CSV file."""

        return "id,family,personal"

### `__str__()`

Convert to CSV string.

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

    43
    44
    45
    46
    def __str__(self):
        """Convert to CSV string."""

        return f"{self.id},{self.family},{self.personal}"