def __compute__(self): self.holidays = dict() for x in Database.team(): self.holidays[x.id] = x.__holidays__(self) # computing holidays for nephrologists for (yesterday, today) in self.iterate(): if yesterday is not None: yesterday_profile = self.daily_plannings[date(yesterday.year, yesterday.month, yesterday.day)].profile else: yesterday_profile = None current_daily_planning = self.daily_plannings[ date(today.year, today.month, today.day) ] # the daily planning for the current day if current_daily_planning.weekday == 0: # recomputing holidays to take obligation recovery into account self.holidays = dict() for x in Database.team(): self.holidays[x.id] = x.__holidays__(self) # computing holidays for nephrologists # if today_date is weekend day or today_date is holiday if current_daily_planning.weekday in [4, 5, 6] or not current_daily_planning.is_working_day: # allocate all damn day in the same time current_daily_planning.__allocate_whole_day__( ConstraintStrategy.ALLOCATE_WEEKEND_DAYS.value, yesterday_profile, self.holidays ) current_daily_planning.__allocate_whole_day__( ConstraintStrategy.ALLOCATE_HOLIDAYS.value, yesterday_profile, self.holidays ) # allocate all day's timeslots separately for current_timeslot in current_daily_planning.profile: if current_daily_planning.weekday in [0, 5, 6]: current_daily_planning.__allocate_timeslot__( ConstraintStrategy.ALLOCATE_MORNING_DIALYSIS.value, yesterday_profile, current_timeslot, self.holidays, ) current_daily_planning.__allocate_timeslot__( ConstraintStrategy.FOCUS_ON_PREFERENCES.value + ConstraintStrategy.DISCARD_COUNTERS.value, yesterday_profile, current_timeslot, self.holidays, ) current_daily_planning.__allocate_timeslot__( ConstraintStrategy.NONE.value, yesterday_profile, current_timeslot, self.holidays )
def __compute__(self): self.holidays = dict() for x in Database.team(): self.holidays[x.id] = x.__holidays__( self) # computing holidays for nephrologists for (yesterday, today) in self.iterate(): if yesterday is not None: yesterday_profile = self.daily_plannings[date( yesterday.year, yesterday.month, yesterday.day)].profile else: yesterday_profile = None current_daily_planning = self.daily_plannings[date( today.year, today.month, today.day)] # the daily planning for the current day if current_daily_planning.weekday == 0: # recomputing holidays to take obligation recovery into account self.holidays = dict() for x in Database.team(): self.holidays[x.id] = x.__holidays__( self) # computing holidays for nephrologists # if today_date is weekend day or today_date is holiday if current_daily_planning.weekday in [ 4, 5, 6 ] or not current_daily_planning.is_working_day: # allocate all damn day in the same time current_daily_planning.__allocate_whole_day__( ConstraintStrategy.ALLOCATE_WEEKEND_DAYS.value, yesterday_profile, self.holidays) current_daily_planning.__allocate_whole_day__( ConstraintStrategy.ALLOCATE_HOLIDAYS.value, yesterday_profile, self.holidays) # allocate all day's timeslots separately for current_timeslot in current_daily_planning.profile: if current_daily_planning.weekday in [0, 5, 6]: current_daily_planning.__allocate_timeslot__( ConstraintStrategy.ALLOCATE_MORNING_DIALYSIS.value, yesterday_profile, current_timeslot, self.holidays) current_daily_planning.__allocate_timeslot__( ConstraintStrategy.FOCUS_ON_PREFERENCES.value + ConstraintStrategy.DISCARD_COUNTERS.value, yesterday_profile, current_timeslot, self.holidays) current_daily_planning.__allocate_timeslot__( ConstraintStrategy.NONE.value, yesterday_profile, current_timeslot, self.holidays)
def __get__(cls, nephrologist_id): candidate = [x for x in Database.team() if x.id == nephrologist_id] if len(candidate) == 0: raise UserWarning( "nephrologist id provided does not match any existing nephrologist." ) else: return candidate[0]
def __team_problem__(self, current_timeslot, holidays, offset_range=[]): current_team = [x for x in Database.team() if x.id not in self.__currently_allocated_nephrologists__(current_timeslot)] ''' if yesterday_profile is not None: offset_range = range(1, 4) # The eligible nephrologist if TimeSlot.THIRD_SHIFT in yesterday_profile: yesterday_obligations = list(set(self.obligation_activities) & set([x for x in yesterday_profile[TimeSlot.THIRD_SHIFT]])) if len(yesterday_obligations) == 1 and yesterday_profile[TimeSlot.THIRD_SHIFT][yesterday_obligations[0]] is not None: current_team = [x for x in current_team if x.id is not yesterday_profile[TimeSlot.THIRD_SHIFT][yesterday_obligations[0]].id] else: offset_range = [] ''' # check whether nephrologist is scheduled for vacation for current day + days before/after in the offset range for offset in list(set([0]) | set(offset_range)): current_team = [x for x in current_team if not self.__is_in_holiday__(x, current_timeslot, holidays, offset)] current_activities = [x for x in self.profile[current_timeslot] if not self.__is_currently_allocated_activity__(current_timeslot, x)] problem = None if len(current_activities) > 0: ''' shuffle(current_team) shuffle(current_activities) ''' # get rid of nephrologist that have declared all current activities as aversions current_team = [x for x in current_team if any([x.score(self.weekday, current_timeslot, act) >= 0 for act in current_activities])] if len(current_team) > 0: # instantiate a new problem problem = Problem() # add the different activities to allocate problem.addVariable(self.nephrologist_key, current_team) # the whole nephrologists minus nephrologists in vacation on this specific day/shift problem.addVariable(self.activity_key, current_activities) # the whole nephrologists that can be allocated on this specific day/shift # constraints declaration problem.addConstraint(AllDifferentConstraint()) problem.addConstraint(lambda nep, act: act in nep.activities, (self.nephrologist_key, self.activity_key)) return current_team, problem
def __get__(cls, nephrologist_id): candidate = [x for x in Database.team() if x.id == nephrologist_id] if len(candidate) == 0: raise UserWarning("nephrologist id provided does not match any existing nephrologist.") else: return candidate[0]
def __team_problem__(self, current_timeslot, holidays, offset_range=[]): current_team = [ x for x in Database.team() if x.id not in self.__currently_allocated_nephrologists__(current_timeslot) ] ''' if yesterday_profile is not None: offset_range = range(1, 4) # The eligible nephrologist if TimeSlot.THIRD_SHIFT in yesterday_profile: yesterday_obligations = list(set(self.obligation_activities) & set([x for x in yesterday_profile[TimeSlot.THIRD_SHIFT]])) if len(yesterday_obligations) == 1 and yesterday_profile[TimeSlot.THIRD_SHIFT][yesterday_obligations[0]] is not None: current_team = [x for x in current_team if x.id is not yesterday_profile[TimeSlot.THIRD_SHIFT][yesterday_obligations[0]].id] else: offset_range = [] ''' # check whether nephrologist is scheduled for vacation for current day + days before/after in the offset range for offset in list(set([0]) | set(offset_range)): current_team = [ x for x in current_team if not self.__is_in_holiday__( x, current_timeslot, holidays, offset) ] current_activities = [ x for x in self.profile[current_timeslot] if not self.__is_currently_allocated_activity__(current_timeslot, x) ] problem = None if len(current_activities) > 0: ''' shuffle(current_team) shuffle(current_activities) ''' # get rid of nephrologist that have declared all current activities as aversions current_team = [ x for x in current_team if any([ x.score(self.weekday, current_timeslot, act) >= 0 for act in current_activities ]) ] if len(current_team) > 0: # instantiate a new problem problem = Problem() # add the different activities to allocate problem.addVariable( self.nephrologist_key, current_team ) # the whole nephrologists minus nephrologists in vacation on this specific day/shift problem.addVariable( self.activity_key, current_activities ) # the whole nephrologists that can be allocated on this specific day/shift # constraints declaration problem.addConstraint(AllDifferentConstraint()) problem.addConstraint( lambda nep, act: act in nep.activities, (self.nephrologist_key, self.activity_key)) return current_team, problem
def output(self): # from xlrd import open_workbook from xlwt import Workbook, XFStyle, Borders, Alignment, Font, Pattern, Style, easyxf # from xlutils.copy import copy """ rb = open_workbook(r"Templates\template.xls") wb = copy(rb) s = wb.get_sheet(0) s.write(0, 0, 'A1') wb.save(r"C:\Temp\nephro-planner\new.xls") """ book = Workbook(encoding="utf-8") sheet = book.add_sheet(r"Feuille1") style_title = XFStyle() font_title = Font() font_title.name = "Comic Sans MS" font_title.height = 280 style_title.font = font_title style_title.alignment.horz = Alignment.HORZ_CENTER style_title.alignment.vert = Alignment.VERT_CENTER style_cell_bottom = XFStyle() borders_cell_bottom = Borders() borders_cell_bottom.bottom = Borders.MEDIUM style_cell_bottom.borders = borders_cell_bottom style_header = XFStyle() font_header = Font() font_header.bold = 1 font_header.name = "Arial Narrow" font_header.height = 240 style_header.font = font_header style_header.alignment.horz = Alignment.HORZ_CENTER style_header.alignment.vert = Alignment.VERT_CENTER borders_header = Borders() borders_header.top = Borders.MEDIUM borders_header.left = Borders.MEDIUM borders_header.bottom = Borders.MEDIUM borders_header.right = Borders.MEDIUM style_header.borders = borders_header style_sub_header = XFStyle() font_sub_header = Font() font_sub_header.name = "Arial Narrow" font_sub_header.height = 240 style_sub_header.font = font_sub_header style_sub_header.alignment.horz = Alignment.HORZ_CENTER style_sub_header.alignment.vert = Alignment.VERT_CENTER borders_sub_header = Borders() borders_sub_header.top = Borders.MEDIUM borders_sub_header.left = Borders.MEDIUM borders_sub_header.bottom = Borders.MEDIUM borders_sub_header.right = Borders.MEDIUM style_sub_header.borders = borders_sub_header style_date = XFStyle() font_date = Font() font_date.name = "Arial Narrow" font_date.height = 240 style_date.font = font_date style_date.alignment.horz = Alignment.HORZ_RIGHT style_date.alignment.vert = Alignment.VERT_CENTER borders_date = Borders() borders_date.left = Borders.MEDIUM style_date.borders = borders_date style_date_status = XFStyle() font_date_status = Font() font_date_status.name = "Arial Narrow" font_date_status.height = 240 style_date_status.font = font_date_status style_date_status.alignment.horz = Alignment.HORZ_LEFT style_date_status.alignment.vert = Alignment.VERT_CENTER borders_date_status = Borders() borders_date_status.right = Borders.MEDIUM style_date_status.borders = borders_date_status style_cell_normal = XFStyle() font_cell_normal = Font() font_cell_normal.name = "Arial Narrow" font_cell_normal.height = 220 style_cell_normal.font = font_cell_normal style_cell_normal.alignment.horz = Alignment.HORZ_CENTER style_cell_normal.alignment.vert = Alignment.VERT_CENTER style_cell_right = XFStyle() font_cell_right = Font() font_cell_right.name = "Arial Narrow" font_cell_right.height = 220 style_cell_right.font = font_cell_right style_cell_right.alignment.horz = Alignment.HORZ_CENTER style_cell_right.alignment.vert = Alignment.VERT_CENTER borders_cell_right = Borders() borders_cell_right.right = Borders.MEDIUM style_cell_right.borders = borders_cell_right style_cell_top = XFStyle() borders_cell_top = Borders() borders_cell_top.top = Borders.MEDIUM style_cell_top.borders = borders_cell_top column_offset = 1 date_column_offset = 2 row_offset = 1 table_width = 1 + 3 * len(Database.team()) # build titles sheet.write_merge(row_offset, row_offset, column_offset, table_width + 1, "POLE MEDECINE INTERNE", style_title) sheet.write_merge( row_offset + 1, row_offset + 1, column_offset, table_width + 1, "Service NEPHROLOGIE – HEMODIALYSE", style_title, ) sheet.write_merge( row_offset + 2, row_offset + 2, column_offset, table_width + 1, "Planning de {0} {1}".format(self.human_readable_months[self.month - 1], self.year), style_title, ) # patch date columns top borders sheet.write(row_offset + 5, column_offset, "", style_cell_bottom) sheet.write(row_offset + 5, column_offset + 1, "", style_cell_bottom) # build header and sub header for x in Database.team(): sheet.write_merge( row_offset + 4, row_offset + 4, column_offset + date_column_offset + 3 * (x.id - 1), column_offset + date_column_offset + 3 * x.id - 1, x.name, style_header, ) sheet.write(row_offset + 5, column_offset + date_column_offset + 3 * (x.id - 1), "M", style_sub_header) sheet.write(row_offset + 5, column_offset + date_column_offset + 3 * (x.id - 1) + 1, "AM", style_sub_header) sheet.write(row_offset + 5, column_offset + date_column_offset + 3 * (x.id - 1) + 2, "N", style_sub_header) """ i = 40 for x in sorted(Style.colour_map): style = XFStyle() pattern = Pattern() pattern.pattern = Pattern.SOLID_PATTERN pattern.pattern_fore_colour = Style.colour_map[x] style.pattern = pattern sheet.write(i, 1, x, style) i += 1 """ pattern_pale_blue = Pattern() pattern_pale_blue.pattern = Pattern.SOLID_PATTERN pattern_pale_blue.pattern_fore_colour = Style.colour_map["pale_blue"] pattern_light_yellow = Pattern() pattern_light_yellow.pattern = Pattern.SOLID_PATTERN pattern_light_yellow.pattern_fore_colour = Style.colour_map["light_yellow"] pattern_ice_blue = Pattern() pattern_ice_blue.pattern = Pattern.SOLID_PATTERN pattern_ice_blue.pattern_fore_colour = Style.colour_map["ice_blue"] pattern_light_green = Pattern() pattern_light_green.pattern = Pattern.SOLID_PATTERN pattern_light_green.pattern_fore_colour = Style.colour_map["light_green"] pattern_ivory = Pattern() pattern_ivory.pattern = Pattern.SOLID_PATTERN pattern_ivory.pattern_fore_colour = Style.colour_map["ivory"] pattern_tan = Pattern() pattern_tan.pattern = Pattern.SOLID_PATTERN pattern_tan.pattern_fore_colour = Style.colour_map["tan"] pattern_gold = Pattern() pattern_gold.pattern = Pattern.SOLID_PATTERN pattern_gold.pattern_fore_colour = Style.colour_map["gold"] def __cell_colouration__(style, current_activity): if current_activity is Activity.CONSULTATION: style.pattern = pattern_pale_blue elif current_activity is Activity.DIALYSIS: style.pattern = pattern_ice_blue elif current_activity is Activity.NEPHROLOGY: style.pattern = pattern_light_green elif current_activity is Activity.OTHERS: style.pattern = pattern_tan elif current_activity is Activity.OBLIGATION: style.pattern = pattern_ivory elif current_activity is Activity.OBLIGATION_WEEKEND: style.pattern = pattern_light_yellow elif current_activity is Activity.OBLIGATION_HOLIDAY: style.pattern = pattern_gold else: style.pattern = Pattern() return style last_day = calendar.monthrange(self.year, self.month)[1] for x in range(1, last_day + 1): current_date = date(self.year, self.month, x) current_daily_planning = self.daily_plannings[current_date] # build date and date status columns sheet.write( row_offset + 5 + x, column_offset, "{0}. {1}".format(self.human_readable_days[current_daily_planning.weekday][0:3].lower(), x), style_date, ) if current_daily_planning.weekday in [5, 6]: sheet.write(row_offset + 5 + x, column_offset + 1, "WK", style_date_status) elif not current_daily_planning.is_working_day: sheet.write(row_offset + 5 + x, column_offset + 1, "Férié", style_date_status) else: sheet.write(row_offset + 5 + x, column_offset + 1, "", style_date_status) """ easyxf( 'font: bold 1, name Tahoma, height 160;' 'align: vertical center, horizontal center, wrap on;' 'borders: left thin, right thin, top thin, bottom thin;' 'pattern: pattern solid, pattern_fore_colour green, pattern_back_colour green' ) """ # fill in month planning for y in Database.team(): current_activity = current_daily_planning.__get_activity__(TimeSlot.FIRST_SHIFT, y) sheet.write( row_offset + 5 + x, column_offset + date_column_offset + 3 * (y.id - 1), self.human_readable_activities[current_activity] if current_activity else "", __cell_colouration__(style_cell_normal, current_activity), ) current_activity = current_daily_planning.__get_activity__(TimeSlot.SECOND_SHIFT, y) sheet.write( row_offset + 5 + x, column_offset + date_column_offset + 1 + 3 * (y.id - 1), self.human_readable_activities[current_activity] if current_activity else "", __cell_colouration__(style_cell_normal, current_activity), ) current_activity = current_daily_planning.__get_activity__(TimeSlot.THIRD_SHIFT, y) sheet.write( row_offset + 5 + x, column_offset + date_column_offset + 2 + 3 * (y.id - 1), self.human_readable_activities[current_activity] if current_activity else "", __cell_colouration__(style_cell_right, current_activity), ) # patch table bottom border for x in range(0, table_width + 1): sheet.write(row_offset + 5 + (last_day + 1), column_offset + x, "", style_cell_top) book.save(r"C:\Temp\nephro-planner\new.xls")
def output(self): # from xlrd import open_workbook from xlwt import Workbook, XFStyle, Borders, Alignment, Font, Pattern, Style, easyxf # from xlutils.copy import copy ''' rb = open_workbook(r"Templates\template.xls") wb = copy(rb) s = wb.get_sheet(0) s.write(0, 0, 'A1') wb.save(r"C:\Temp\nephro-planner\new.xls") ''' book = Workbook(encoding="utf-8") sheet = book.add_sheet(r"Feuille1") style_title = XFStyle() font_title = Font() font_title.name = "Comic Sans MS" font_title.height = 280 style_title.font = font_title style_title.alignment.horz = Alignment.HORZ_CENTER style_title.alignment.vert = Alignment.VERT_CENTER style_cell_bottom = XFStyle() borders_cell_bottom = Borders() borders_cell_bottom.bottom = Borders.MEDIUM style_cell_bottom.borders = borders_cell_bottom style_header = XFStyle() font_header = Font() font_header.bold = 1 font_header.name = "Arial Narrow" font_header.height = 240 style_header.font = font_header style_header.alignment.horz = Alignment.HORZ_CENTER style_header.alignment.vert = Alignment.VERT_CENTER borders_header = Borders() borders_header.top = Borders.MEDIUM borders_header.left = Borders.MEDIUM borders_header.bottom = Borders.MEDIUM borders_header.right = Borders.MEDIUM style_header.borders = borders_header style_sub_header = XFStyle() font_sub_header = Font() font_sub_header.name = "Arial Narrow" font_sub_header.height = 240 style_sub_header.font = font_sub_header style_sub_header.alignment.horz = Alignment.HORZ_CENTER style_sub_header.alignment.vert = Alignment.VERT_CENTER borders_sub_header = Borders() borders_sub_header.top = Borders.MEDIUM borders_sub_header.left = Borders.MEDIUM borders_sub_header.bottom = Borders.MEDIUM borders_sub_header.right = Borders.MEDIUM style_sub_header.borders = borders_sub_header style_date = XFStyle() font_date = Font() font_date.name = "Arial Narrow" font_date.height = 240 style_date.font = font_date style_date.alignment.horz = Alignment.HORZ_RIGHT style_date.alignment.vert = Alignment.VERT_CENTER borders_date = Borders() borders_date.left = Borders.MEDIUM style_date.borders = borders_date style_date_status = XFStyle() font_date_status = Font() font_date_status.name = "Arial Narrow" font_date_status.height = 240 style_date_status.font = font_date_status style_date_status.alignment.horz = Alignment.HORZ_LEFT style_date_status.alignment.vert = Alignment.VERT_CENTER borders_date_status = Borders() borders_date_status.right = Borders.MEDIUM style_date_status.borders = borders_date_status style_cell_normal = XFStyle() font_cell_normal = Font() font_cell_normal.name = "Arial Narrow" font_cell_normal.height = 220 style_cell_normal.font = font_cell_normal style_cell_normal.alignment.horz = Alignment.HORZ_CENTER style_cell_normal.alignment.vert = Alignment.VERT_CENTER style_cell_right = XFStyle() font_cell_right = Font() font_cell_right.name = "Arial Narrow" font_cell_right.height = 220 style_cell_right.font = font_cell_right style_cell_right.alignment.horz = Alignment.HORZ_CENTER style_cell_right.alignment.vert = Alignment.VERT_CENTER borders_cell_right = Borders() borders_cell_right.right = Borders.MEDIUM style_cell_right.borders = borders_cell_right style_cell_top = XFStyle() borders_cell_top = Borders() borders_cell_top.top = Borders.MEDIUM style_cell_top.borders = borders_cell_top column_offset = 1 date_column_offset = 2 row_offset = 1 table_width = 1 + 3 * len(Database.team()) # build titles sheet.write_merge(row_offset, row_offset, column_offset, table_width + 1, "POLE MEDECINE INTERNE", style_title) sheet.write_merge(row_offset + 1, row_offset + 1, column_offset, table_width + 1, "Service NEPHROLOGIE – HEMODIALYSE", style_title) sheet.write_merge( row_offset + 2, row_offset + 2, column_offset, table_width + 1, "Planning de {0} {1}".format( self.human_readable_months[self.month - 1], self.year), style_title) # patch date columns top borders sheet.write(row_offset + 5, column_offset, "", style_cell_bottom) sheet.write(row_offset + 5, column_offset + 1, "", style_cell_bottom) # build header and sub header for x in Database.team(): sheet.write_merge( row_offset + 4, row_offset + 4, column_offset + date_column_offset + 3 * (x.id - 1), column_offset + date_column_offset + 3 * x.id - 1, x.name, style_header) sheet.write(row_offset + 5, column_offset + date_column_offset + 3 * (x.id - 1), "M", style_sub_header) sheet.write( row_offset + 5, column_offset + date_column_offset + 3 * (x.id - 1) + 1, "AM", style_sub_header) sheet.write( row_offset + 5, column_offset + date_column_offset + 3 * (x.id - 1) + 2, "N", style_sub_header) ''' i = 40 for x in sorted(Style.colour_map): style = XFStyle() pattern = Pattern() pattern.pattern = Pattern.SOLID_PATTERN pattern.pattern_fore_colour = Style.colour_map[x] style.pattern = pattern sheet.write(i, 1, x, style) i += 1 ''' pattern_pale_blue = Pattern() pattern_pale_blue.pattern = Pattern.SOLID_PATTERN pattern_pale_blue.pattern_fore_colour = Style.colour_map['pale_blue'] pattern_light_yellow = Pattern() pattern_light_yellow.pattern = Pattern.SOLID_PATTERN pattern_light_yellow.pattern_fore_colour = Style.colour_map[ 'light_yellow'] pattern_ice_blue = Pattern() pattern_ice_blue.pattern = Pattern.SOLID_PATTERN pattern_ice_blue.pattern_fore_colour = Style.colour_map['ice_blue'] pattern_light_green = Pattern() pattern_light_green.pattern = Pattern.SOLID_PATTERN pattern_light_green.pattern_fore_colour = Style.colour_map[ 'light_green'] pattern_ivory = Pattern() pattern_ivory.pattern = Pattern.SOLID_PATTERN pattern_ivory.pattern_fore_colour = Style.colour_map['ivory'] pattern_tan = Pattern() pattern_tan.pattern = Pattern.SOLID_PATTERN pattern_tan.pattern_fore_colour = Style.colour_map['tan'] pattern_gold = Pattern() pattern_gold.pattern = Pattern.SOLID_PATTERN pattern_gold.pattern_fore_colour = Style.colour_map['gold'] def __cell_colouration__(style, current_activity): if current_activity is Activity.CONSULTATION: style.pattern = pattern_pale_blue elif current_activity is Activity.DIALYSIS: style.pattern = pattern_ice_blue elif current_activity is Activity.NEPHROLOGY: style.pattern = pattern_light_green elif current_activity is Activity.OTHERS: style.pattern = pattern_tan elif current_activity is Activity.OBLIGATION: style.pattern = pattern_ivory elif current_activity is Activity.OBLIGATION_WEEKEND: style.pattern = pattern_light_yellow elif current_activity is Activity.OBLIGATION_HOLIDAY: style.pattern = pattern_gold else: style.pattern = Pattern() return style last_day = calendar.monthrange(self.year, self.month)[1] for x in range(1, last_day + 1): current_date = date(self.year, self.month, x) current_daily_planning = self.daily_plannings[current_date] # build date and date status columns sheet.write( row_offset + 5 + x, column_offset, "{0}. {1}".format( self.human_readable_days[current_daily_planning.weekday] [0:3].lower(), x), style_date) if current_daily_planning.weekday in [5, 6]: sheet.write(row_offset + 5 + x, column_offset + 1, "WK", style_date_status) elif not current_daily_planning.is_working_day: sheet.write(row_offset + 5 + x, column_offset + 1, "Férié", style_date_status) else: sheet.write(row_offset + 5 + x, column_offset + 1, "", style_date_status) ''' easyxf( 'font: bold 1, name Tahoma, height 160;' 'align: vertical center, horizontal center, wrap on;' 'borders: left thin, right thin, top thin, bottom thin;' 'pattern: pattern solid, pattern_fore_colour green, pattern_back_colour green' ) ''' # fill in month planning for y in Database.team(): current_activity = current_daily_planning.__get_activity__( TimeSlot.FIRST_SHIFT, y) sheet.write( row_offset + 5 + x, column_offset + date_column_offset + 3 * (y.id - 1), self.human_readable_activities[current_activity] if current_activity else "", __cell_colouration__(style_cell_normal, current_activity)) current_activity = current_daily_planning.__get_activity__( TimeSlot.SECOND_SHIFT, y) sheet.write( row_offset + 5 + x, column_offset + date_column_offset + 1 + 3 * (y.id - 1), self.human_readable_activities[current_activity] if current_activity else "", __cell_colouration__(style_cell_normal, current_activity)) current_activity = current_daily_planning.__get_activity__( TimeSlot.THIRD_SHIFT, y) sheet.write( row_offset + 5 + x, column_offset + date_column_offset + 2 + 3 * (y.id - 1), self.human_readable_activities[current_activity] if current_activity else "", __cell_colouration__(style_cell_right, current_activity)) # patch table bottom border for x in range(0, table_width + 1): sheet.write(row_offset + 5 + (last_day + 1), column_offset + x, "", style_cell_top) book.save(r"C:\Temp\nephro-planner\new.xls")
def main(): try: # Database.__create__() # Nephrologist.__load__() import codecs import json from Utils.custom_encoder import CustomEncoder from Utils.python_object_encoder import PythonObjectEncoder from collections import Counter # print(json.dumps(Counter({Activity.OBLIGATION: 5}), cls=CustomEncoder, indent=4, sort_keys=True, ensure_ascii=False)) # from pprint import pprint import io with io.open("data.txt", "wb") as outfile: # with codecs.open("data.txt", "w", encoding="utf8") as outfile: s = json.dumps(Database.team(), cls=CustomEncoder, indent=4, sort_keys=True, encoding="latin-1") # print s # s2u = u"%s" % s # incorrect s2u = unicode(s, "latin-1") # print s2u sutf8 = s2u.encode("latin-1") # print sutf8 outfile.write(sutf8) ''' for n in Database.team(): print repr(n) ''' from Models.preferences import Preferences from Models.aversions import Aversions def __recursive_object_hook__(o): def __regular_t2a__(p): return dict([(int(key), dict([(TimeSlot.__from_string__(timeslot), [Activity.__from_string__(activity) for activity in activities]) for timeslot, activities in timeslot2activites.iteritems()])) for key, timeslot2activites in p.iteritems()]) if isinstance(o, list): return [__recursive_object_hook__(value) for value in o] elif "__nephrologist__" in o: nephrologist = o["__nephrologist__"] id = int(nephrologist["id"]) if "id" in nephrologist else None name = str(nephrologist["name"].encode("latin-1")) if "name" in nephrologist else None activities = [Activity.__from_string__(flag) for flag in nephrologist["activities"] if "activities" in nephrologist] holidays = [__recursive_object_hook__(value) for value in nephrologist["holidays"] if "holidays" in nephrologist] preferences = __recursive_object_hook__(nephrologist["preferences"]) if "preferences" in nephrologist else None aversions = __recursive_object_hook__(nephrologist["aversions"]) if "aversions" in nephrologist else None counters = __recursive_object_hook__(nephrologist["initial_counters"]) if "initial_counters" in nephrologist else None return Nephrologist(id, name, activities, holidays, preferences, aversions, counters) elif "__date__" in o: return datetime.strptime(o["__date__"], "%Y-%m-%d").date() elif "__preferences__" in o: return Preferences(__regular_t2a__(o["__preferences__"])) elif "__aversions__" in o: return Aversions(__regular_t2a__(o["__aversions__"])) elif "__counter__" in o: return Counter(dict([(Activity.__from_string__(key), value) for key, value in o["__counter__"].iteritems()])) else: return o from Utils.custom_decoder import CustomDecoder with io.open("data.txt", "rb") as infile: # reads = unicode(infile.read(), 'utf-8') r = infile.read().decode("unicode-escape") print("Séver") print(u"Séver") print(str("Séver")) print(r[3990:3995]) # r2u = unicode(r, "utf-8") # print(r) # print(reads) # data = CustomDecoder().decode(reads) data = json.loads(r, object_hook=__recursive_object_hook__) print(unicode(data[2].name, "utf-8")) print(unicode(Database.team()[2].name, "utf-8")) # print(type(data)) # print pprint(data) return year = 2015 month = 5 month_planning = MonthlyPlanning(year, month) month_planning.__compute__() ''' print("--------------------------------------------------") for x in Database.team(): print(repr(x) + ": " + str(x.counters())) ''' ''' for y in current_daily_planning.profile: print(str(today) + "|" + str(y) + ": " + "-".join([str(x) for x in sorted(current_daily_planning.currentlyAllocatedNephrologists(y))])) ''' ''' for x in Database.team(): print(repr(x) + ": ") for holiday in sorted(month_planning.holidays[x.id]): print("\t" + str(holiday) + ": " + "|".join([y.name[0] for y in month_planning.holidays[x.id][holiday]])) print("------------------------------------------------------------") ''' print(month_planning) month_planning.output() finally: pass