Skip to content

Rating

Ratings on machinery.

Rating dataclass

Bases: BaseMixin

A person's rating on a machine.

Attributes:

Name Type Description
person_id str

person identifier (in persons)

machine_id str

machine identifier (in machines)

certified bool

whether person is certified on machine

Source code in src/snailz/rating.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
@dataclass
class Rating(BaseMixin):
    """
    A person's rating on a machine.

    Attributes:
        person_id: person identifier (in persons)
        machine_id: machine identifier (in machines)
        certified: whether person is certified on machine
    """

    foreign_keys: ClassVar[ForeignKeysType] = [
        ("person_id", "person", "ident"),
        ("machine_id", "machine", "ident"),
    ]

    person_id: str = ""
    machine_id: str = ""
    certified: bool = False

    @classmethod
    def make(
        cls, params: Parameters, persons: list[Person], machines: list[Machine]
    ) -> list["Rating"]:
        """Construct multiple ratings.

        Args:
            params: Data generation parameters.
            persons: list of people who have ratings.
            machines: list of machines that people are rated for.

        Returns:
            List of ratings.
        """

        num = max(1, int(params.ratings_frac * len(persons) * len(machines)))
        possible = list(itertools.product(persons, machines))
        actual = random.sample(possible, k=num)
        return [
            Rating(
                person_id=p.ident,
                machine_id=m.ident,
                certified=(random.random() < params.p_certified),
            )
            for (p, m) in actual
        ]

    @classmethod
    def table_name(cls) -> str:
        """Database table name."""

        return "rating"

make(params, persons, machines) classmethod

Construct multiple ratings.

Parameters:

Name Type Description Default
params Parameters

Data generation parameters.

required
persons list[Person]

list of people who have ratings.

required
machines list[Machine]

list of machines that people are rated for.

required

Returns:

Type Description
list[Rating]

List of ratings.

Source code in src/snailz/rating.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
@classmethod
def make(
    cls, params: Parameters, persons: list[Person], machines: list[Machine]
) -> list["Rating"]:
    """Construct multiple ratings.

    Args:
        params: Data generation parameters.
        persons: list of people who have ratings.
        machines: list of machines that people are rated for.

    Returns:
        List of ratings.
    """

    num = max(1, int(params.ratings_frac * len(persons) * len(machines)))
    possible = list(itertools.product(persons, machines))
    actual = random.sample(possible, k=num)
    return [
        Rating(
            person_id=p.ident,
            machine_id=m.ident,
            certified=(random.random() < params.p_certified),
        )
        for (p, m) in actual
    ]

table_name() classmethod

Database table name.

Source code in src/snailz/rating.py
62
63
64
65
66
@classmethod
def table_name(cls) -> str:
    """Database table name."""

    return "rating"