Skip to content

Commit c1e6096

Browse files
committed
Summarise checks on whether to collect event changes
1 parent 474a1e5 commit c1e6096

File tree

3 files changed

+30
-33
lines changed

3 files changed

+30
-33
lines changed

src/tlo/events.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@ def apply(self, target):
6565
def run(self):
6666
"""Make the event happen."""
6767

68-
6968
# Dispatch notification that event is about to run
70-
notifier.dispatch("event.about_to_run", data={"target": self.target, "link_info" : {"EventName": type(self).__name__}})
69+
notifier.dispatch("event.about_to_run", data={"target": self.target, "module" : self.module, "link_info" : {"EventName": type(self).__name__}})
7170

7271
self.apply(self.target)
7372
self.post_apply_hook()

src/tlo/methods/collect_event_chains.py

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def read_parameters(self, resourcefilepath: Optional[Path] = None):
5050
#print("resource file path", resourcefilepath)
5151
#self.load_parameters_from_dataframe(pd.read_csv(resourcefilepath/"ResourceFile_GenerateEventChains/parameter_values.csv"))
5252
self.parameters["generate_event_chains"] = True
53-
self.parameters["modules_of_interest"] = self.sim.modules
53+
self.parameters["modules_of_interest"] = self.sim.modules.values()
5454

5555
self.parameters["events_to_ignore"] =["AgeUpdateEvent","HealthSystemScheduler","SimplifiedBirthsPoll","DirectBirth","LifestyleEvent","TbActiveCasePollGenerateData","HivPollingEventForDataGeneration","RTIPollingEvent"]
5656

@@ -96,9 +96,13 @@ def on_notification_event_about_to_run(self, data):
9696
"""Do this when notified that an event is about to run. This function checks whether this event should be logged as part of the event chains, and if so stored required information before the event has occurred. """
9797

9898
p = self.parameters
99-
100-
if p['generate_event_chains']:
10199

100+
# Only log event if
101+
# 1) generate_event_chains is set to True
102+
# 2) the event belongs to modules of interest and
103+
# 3) the event is not in the list of events to ignore
104+
if p['generate_event_chains'] and (data['module'] in p['modules_of_interest']) and (data['link_info']['EventName'] not in p['events_to_ignore']):
105+
102106
# Initialise these variables
103107
self.print_chains = False
104108
self.df_before = []
@@ -107,38 +111,32 @@ def on_notification_event_about_to_run(self, data):
107111
self.mni_row_before = {}
108112
self.entire_mni_before = {}
109113

110-
# Only print event if it belongs to modules of interest and if it is not in the list of events to ignore
111-
if all(sub not in str(data['link_info']['EventName']) for sub in p['events_to_ignore']):
114+
self.print_chains = True
112115

113-
# Will eventually use this once I can actually GET THE NAME OF THE SELF
114-
#if not set(self.sim.generate_event_chains_ignore_events).intersection(str(self)):
116+
# Target is single individual
117+
if not isinstance(data['target'], Population):
115118

116-
self.print_chains = True
119+
# Save row for comparison after event has occurred
120+
self.row_before = self.sim.population.props.loc[abs(data['target'])].copy().fillna(-99999)
117121

118-
# Target is single individual
119-
if not isinstance(data['target'], Population):
120-
121-
# Save row for comparison after event has occurred
122-
self.row_before = self.sim.population.props.loc[abs(data['target'])].copy().fillna(-99999)
123-
124-
# Check if individual is already in mni dictionary, if so copy her original status
125-
if 'PregnancySupervisor' in self.sim.modules:
126-
mni = self.sim.modules['PregnancySupervisor'].mother_and_newborn_info
127-
if data['target'] in mni:
128-
self.mni_instances_before = True
129-
self.mni_row_before = mni[data['target']].copy()
130-
else:
131-
self.mni_row_before = None
132-
122+
# Check if individual is already in mni dictionary, if so copy her original status
123+
if 'PregnancySupervisor' in self.sim.modules:
124+
mni = self.sim.modules['PregnancySupervisor'].mother_and_newborn_info
125+
if data['target'] in mni:
126+
self.mni_instances_before = True
127+
self.mni_row_before = mni[data['target']].copy()
133128
else:
129+
self.mni_row_before = None
130+
131+
else:
134132

135-
# This will be a population-wide event. In order to find individuals for which this led to
136-
# a meaningful change, make a copy of the while pop dataframe/mni before the event has occurred.
137-
self.df_before = self.sim.population.props.copy()
138-
if 'PregnancySupervisor' in self.sim.modules:
139-
self.entire_mni_before = copy.deepcopy(self.sim.modules['PregnancySupervisor'].mother_and_newborn_info)
140-
else:
141-
self.entire_mni_before = None
133+
# This will be a population-wide event. In order to find individuals for which this led to
134+
# a meaningful change, make a copy of the while pop dataframe/mni before the event has occurred.
135+
self.df_before = self.sim.population.props.copy()
136+
if 'PregnancySupervisor' in self.sim.modules:
137+
self.entire_mni_before = copy.deepcopy(self.sim.modules['PregnancySupervisor'].mother_and_newborn_info)
138+
else:
139+
self.entire_mni_before = None
142140

143141
return
144142

src/tlo/methods/hsi_event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def run(self, squeeze_factor):
201201
"""Make the event happen."""
202202

203203
# Dispatch notification that HSI event is about to run
204-
notifier.dispatch("event.about_to_run", data={"target": self.target, "link_info" : {"EventName": type(self).__name__}})
204+
notifier.dispatch("event.about_to_run", data={"target": self.target, "module" : self.module, "link_info" : {"EventName": type(self).__name__}})
205205

206206
updated_appt_footprint = self.apply(self.target, squeeze_factor)
207207
self.post_apply_hook()

0 commit comments

Comments
 (0)