Skip to content

Domestic care

DomesticCare

Bases: Event

This event models people taking care of their elderly who live alone or in couples. The logic is that at the beginning of each leisure time-step, people who have caring responsibilites go to their relatives household for the duration of their time-step.

Source code in june/event/domestic_care.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
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
class DomesticCare(Event):
    """This event models people taking care of their elderly who live
    alone or in couples. The logic is that at the beginning of each
    leisure time-step, people who have caring responsibilites go
    to their relatives household for the duration of their time-step.

    """

    def __init__(
        self,
        start_time: Union[str, datetime.datetime],
        end_time: Union[str, datetime.datetime],
        needs_care_probabilities: Dict[str, float],
        daily_going_probability=1.0,
    ):
        super().__init__(start_time=start_time, end_time=end_time)
        self.needs_care_probabilities = parse_age_probabilities(
            needs_care_probabilities
        )
        self.daily_going_probability = daily_going_probability

    def initialise(self, world):
        """

        Args:
            world: 

        """
        self._link_carers_to_households(world=world)

    def apply(self, world, activities, day_type, simulator=None):
        """When a household is reponsible for caring of another housheold,
        a random person is sent during leisure to take care of that household.
        We checked that the person is not at hospital when we send them.

        Args:
            world: 
            activities: 
            day_type: 
            simulator: (Default value = None)

        """
        if (
            "leisure" not in activities
            or day_type == "weekend"
            or "primary_activity" in activities
        ):
            return
        for household in world.households:
            if household.household_to_care is not None:
                household_to_care = household.household_to_care
                carers = list(household.residents)
                shuffle(carers)
                receives_care = False
                for person in carers:
                    if person.age > 18 and person.available:
                        household_to_care.add(person, activity="leisure")
                        receives_care = True
                        break
                if receives_care:
                    household_to_care.receiving_care = True
                    # make residents stay at home
                    for person in household_to_care.residents:
                        if person.available:
                            person.residence.append(person)

    def _link_carers_to_households(self, world):
        """Links old people households to other households that provide them with care aid.
        All linking is restricted to the super area level.

        Args:
            world: 

        """
        total_need_care = 0
        unlinked_needers = []
        unlinked_providers = []

        for super_area in world.super_areas:
            need_care = []
            can_provide_care = []
            linked_pairs = []

            # Collect households needing and providing care
            for area in super_area.areas:
                for household in area.households:
                    if self._check_household_needs_care(household):  # Assuming this method exists
                        need_care.append(household)
                    if self._check_household_can_provide_care(household):  # Assuming this method exists
                        can_provide_care.append(household)

            # Shuffle the lists and create pairs
            shuffle(need_care)
            shuffle(can_provide_care)

            for needer, provider in zip(need_care, can_provide_care):
                total_need_care += 1
                linked_pairs.append((provider, needer))
                provider.household_to_care = needer  # Link provider to needer

            # Track unlinked households
            unlinked_needers.extend(need_care[len(linked_pairs):])
            unlinked_providers.extend(can_provide_care[len(linked_pairs):])

    def _check_household_needs_care(self, household):
        """Check if a household needs care. We take the oldest
        person in the household to be representative of the risk
        for needing care.

        Args:
            household: 

        """
        if household.type == "old":
            for person in household.residents:
                care_probability = self.needs_care_probabilities[person.age]
                if random() < care_probability:
                    return True
        return False

    def _check_household_can_provide_care(self, household):
        """We limit care providers to non-student households.

        Args:
            household: 

        """
        if household.type in ["student", "old"]:
            return False
        return True

apply(world, activities, day_type, simulator=None)

When a household is reponsible for caring of another housheold, a random person is sent during leisure to take care of that household. We checked that the person is not at hospital when we send them.

Parameters:

Name Type Description Default
world
required
activities
required
day_type
required
simulator

(Default value = None)

None
Source code in june/event/domestic_care.py
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
67
68
69
70
71
72
73
74
75
76
def apply(self, world, activities, day_type, simulator=None):
    """When a household is reponsible for caring of another housheold,
    a random person is sent during leisure to take care of that household.
    We checked that the person is not at hospital when we send them.

    Args:
        world: 
        activities: 
        day_type: 
        simulator: (Default value = None)

    """
    if (
        "leisure" not in activities
        or day_type == "weekend"
        or "primary_activity" in activities
    ):
        return
    for household in world.households:
        if household.household_to_care is not None:
            household_to_care = household.household_to_care
            carers = list(household.residents)
            shuffle(carers)
            receives_care = False
            for person in carers:
                if person.age > 18 and person.available:
                    household_to_care.add(person, activity="leisure")
                    receives_care = True
                    break
            if receives_care:
                household_to_care.receiving_care = True
                # make residents stay at home
                for person in household_to_care.residents:
                    if person.available:
                        person.residence.append(person)

initialise(world)

Parameters:

Name Type Description Default
world
required
Source code in june/event/domestic_care.py
33
34
35
36
37
38
39
40
def initialise(self, world):
    """

    Args:
        world: 

    """
    self._link_carers_to_households(world=world)