Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change usages of datetime.date to tlo.Date in lifestyle module #944

Merged
merged 2 commits into from
Apr 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/tlo/methods/enhanced_lifestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
Lifestyle module
Documentation: 04 - Methods Repository/Method_Lifestyle.xlsx
"""
import datetime
from pathlib import Path

import numpy as np
import pandas as pd

from tlo import DateOffset, Module, Parameter, Property, Types, logging
from tlo import Date, DateOffset, Module, Parameter, Property, Types, logging
from tlo.events import PopulationScopeEventMixin, RegularEvent
from tlo.util import get_person_id_to_inherit_from

Expand Down Expand Up @@ -344,9 +343,9 @@ def read_parameters(self, data_folder):

self.load_parameters_from_dataframe(dfd)
# Manually set dates for campaign starts for now todo - fix this
p['start_date_campaign_exercise_increase'] = datetime.date(2010, 7, 1)
p['start_date_campaign_quit_smoking'] = datetime.date(2010, 7, 1)
p['start_date_campaign_alcohol_reduction'] = datetime.date(2010, 7, 1)
p['start_date_campaign_exercise_increase'] = Date(2010, 7, 1)
p['start_date_campaign_quit_smoking'] = Date(2010, 7, 1)
p['start_date_campaign_alcohol_reduction'] = Date(2010, 7, 1)

def initialise_population(self, population):
"""Set our property values for the initial population.
Expand Down Expand Up @@ -1286,7 +1285,7 @@ def apply(self, population):
newly_not_high_salt_idx = high_salt_idx[random_draw < eff_rate_not_high_salt]
df.loc[newly_not_high_salt_idx, 'li_high_salt'] = False

all_idx_campaign_salt_reduction = df.index[df.is_alive & (self.sim.date == datetime.date(2010, 7, 1))]
all_idx_campaign_salt_reduction = df.index[df.is_alive & (self.sim.date == Date(2010, 7, 1))]
df.loc[all_idx_campaign_salt_reduction, 'li_exposed_to_campaign_salt_reduction'] = True

# -------------------- HIGH SUGAR ----------------------------------------------------------
Expand All @@ -1307,7 +1306,7 @@ def apply(self, population):
newly_not_high_sugar_idx = high_sugar_idx[random_draw < eff_rate_not_high_sugar]
df.loc[newly_not_high_sugar_idx, 'li_high_sugar'] = False

all_idx_campaign_sugar_reduction = df.index[df.is_alive & (self.sim.date == datetime.date(2010, 7, 1))]
all_idx_campaign_sugar_reduction = df.index[df.is_alive & (self.sim.date == Date(2010, 7, 1))]
df.loc[all_idx_campaign_sugar_reduction, 'li_exposed_to_campaign_sugar_reduction'] = True

# -------------------- BMI ----------------------------------------------------------
Expand Down Expand Up @@ -1348,7 +1347,7 @@ def apply(self, population):
newly_decrease_bmi_cat_idx = bmi_cat_3_to_5_idx[random_draw < eff_rate_lower_bmi]
df.loc[newly_decrease_bmi_cat_idx, 'li_bmi'] = df['li_bmi'] - 1

all_idx_campaign_weight_reduction = df.index[df.is_alive & (self.sim.date == datetime.date(2010, 7, 1))]
all_idx_campaign_weight_reduction = df.index[df.is_alive & (self.sim.date == Date(2010, 7, 1))]
df.loc[all_idx_campaign_weight_reduction, 'li_exposed_to_campaign_weight_reduction'] = True

# --- FSW ---
Expand Down