diff --git a/opt.py b/opt.py index 6ab2532..d3693d3 100644 --- a/opt.py +++ b/opt.py @@ -27,6 +27,19 @@ class Scheduler: print("Patient data not found") self.create_lists() + self.extend_data() + + def extend_data(self): + + # Date to integer all dates + # tasks date + newcol = [self.date2int(date) for date in self.df_tasks['date'].tolist()] + self.df_tasks.insert(7, "dateint", newcol) + + # block date + newcol2 = [self.date2int(date) for date in self.df_blocks['day'].tolist()] + self.df_blocks.insert(3, "dateint", newcol2) + return def create_lists(self): self.s = self.df_tasks['priority'].tolist() @@ -42,11 +55,14 @@ class Scheduler: return def convert_dates(self): - self.week_day = [self.date2int(date) for date in self.dates] - self.block_week_day = [self.date2int(date) for date in self.block_dates] + self.week_day = [self.date2week_day(date) for date in self.dates] + self.block_week_day = [self.date2week_day(date) for date in self.block_dates] - def date2int(self, date): - d0 = pd.to_datetime("25/11/2024", dayfirst=True) + def date2int(self, date, dzero="25/11/2024"): + return self.date2week_day(date)[0]*7 + self.date2week_day(date)[1] + + def date2week_day(self, date, dzero="25/11/2024"): + d0 = pd.to_datetime(dzero, dayfirst=True) delta = (pd.to_datetime(date, dayfirst=True) - d0).days day = delta%7 week = int((delta - day)/7) @@ -115,7 +131,7 @@ for i in range(n): print(tasks_blocks) -print(sc.dates) -print(sc.week_day) -print(sc.block_dates) -print(sc.block_week_day) +print(sc.df_tasks) +print(sc.df_patients) +print(sc.df_blocks) +print(type(sc.df_blocks))