Пример #1
0
    def testWritePersonConfig(self):
        ws = self.ws
        pc1 = data_types.PersonConfig('간호사1', 5, 3, 25, 28)
        pc2 = data_types.PersonConfig('간호사2', 6, 4, 22, 26)
        excel_output.WritePersonConfigs(ws, [pc1, pc2])

        # Check header columns
        self.assertEqual(ws.cell(row=1, column=2).value, '최대 근무일 (연속)')
        self.assertEqual(ws.cell(row=1, column=3).value, '최대 나이트 (연속)')
        self.assertEqual(ws.cell(row=1, column=4).value, '최소 근무일 (전체)')
        self.assertEqual(ws.cell(row=1, column=5).value, '최대 근무일 (전체)')
        self.assertIsNone(ws.cell(
            row=1, column=6).value)  # Header columns should end here

        # Check header rows
        self.assertEqual(ws.cell(row=2, column=1).value, '간호사1')
        self.assertEqual(ws.cell(row=3, column=1).value, '간호사2')
        self.assertIsNone(ws.cell(
            row=4, column=1).value)  # Header rows should end here

        # Check all person constraint values are correct
        self.assertEqual(ws.cell(row=2, column=2).value, 5)
        self.assertEqual(ws.cell(row=2, column=3).value, 3)
        self.assertEqual(ws.cell(row=2, column=4).value, 25)
        self.assertEqual(ws.cell(row=2, column=5).value, 28)
        self.assertIsNone(ws.cell(row=2, column=6).value)

        self.assertEqual(ws.cell(row=3, column=2).value, 6)
        self.assertEqual(ws.cell(row=3, column=3).value, 4)
        self.assertEqual(ws.cell(row=3, column=4).value, 22)
        self.assertEqual(ws.cell(row=3, column=5).value, 26)
        self.assertIsNone(ws.cell(row=3, column=6).value)

        self.assertIsNone(ws.cell(row=4, column=2).value)
Пример #2
0
    def testConstraint4Error(self):
        # Working more than n nights
        config = data_types.PersonConfig('name4', 3, 2, 5, 5)
        assignment_dict = {
            (_DAY1, 'name4'): _NIGHT_SHIFT,
            (_DAY2, 'name4'): _NIGHT_SHIFT,
            (_DAY3, 'name4'): _NIGHT_SHIFT,
            (_DAY4, 'name4'): _NIGHT_SHIFT
        }
        all_dates = [_DAY1, _DAY2, _DAY3, _DAY4]
        vt.ValidateConstraint4(config, all_dates, assignment_dict, self.errors)
        self.assertEqual(len(self.errors), 1)
        self.assertEqual(
            self.errors[0],
            'Worker name4 should work no more than 2 consecutive nights, but worked for 4 nights from 2020-04-01'
        )

        # Working 3 consecutive nights in the middle
        assignment_dict = {
            (_DAY1, 'name4'): _DAY_SHIFT,
            (_DAY2, 'name4'): _DAY_SHIFT,
            (_DAY3, 'name4'): _NIGHT_SHIFT,
            (_DAY4, 'name4'): _NIGHT_SHIFT,
            (_DAY5, 'name4'): _NIGHT_SHIFT,
            (_DAY6, 'name4'): _OFF_SHIFT
        }
        all_dates = [_DAY1, _DAY2, _DAY3, _DAY4, _DAY5, _DAY6]
        errors = []
        vt.ValidateConstraint4(config, all_dates, assignment_dict, errors)
        self.assertEqual(len(errors), 1)
        self.assertEqual(
            errors[0],
            'Worker name4 should work no more than 2 consecutive nights, but worked for 3 nights from 2020-04-03'
        )
Пример #3
0
 def setUp(self):
     self.assignment_dict = {
         (_START_DATE, 'name1'): _DAY_SHIFT,
         (_END_DATE, 'name1'): _EVENING_SHIFT,
         (_START_DATE, 'name2'): _OFF_SHIFT,
         (_END_DATE, 'name2'): _NIGHT_SHIFT
     }
     self.person_configs = [
         data_types.PersonConfig('name1', 5, 3, 1, 30),
         data_types.PersonConfig('name2', 6, 4, 2, 20)
     ]
     self.date_configs = [
         data_types.DateConfig(_START_DATE, 1, 1, 1),
         data_types.DateConfig(_END_DATE, 1, 2, 1)
     ]
     self.all_dates = [_START_DATE, _END_DATE]
     self.errors = []
Пример #4
0
 def testConstraint4OffInTheMiddle(self):
     # Constraint4. Work not for more than n consecutive nights, because OFF in the middle
     config = data_types.PersonConfig('name4', 2, 2, 5, 5)
     assignment_dict = {  # Person works on 1st & 2nd day, takes a break on 3rd day and works again
         (_DAY1, 'name4'): _NIGHT_SHIFT,
         (_DAY2, 'name4'): _NIGHT_SHIFT,
         (_DAY3, 'name4'): _OFF_SHIFT,
         (_DAY4, 'name4'): _NIGHT_SHIFT
     }
     all_dates = [_DAY1, _DAY2, _DAY3, _DAY4]
     vt.ValidateConstraint4(config, all_dates, assignment_dict, self.errors)
     self.assertEqual(len(self.errors), 0)
Пример #5
0
 def testConstraint4Exact(self):
     # Working exactly n nights
     config = data_types.PersonConfig('name4', 3, 2, 5, 5)
     assignment_dict = {
         (_DAY1, 'name4'): _DAY_SHIFT,
         (_DAY2, 'name4'): _NIGHT_SHIFT,
         (_DAY3, 'name4'): _NIGHT_SHIFT,
         (_DAY4, 'name4'): _OFF_SHIFT
     }
     all_dates = [_DAY1, _DAY2, _DAY3, _DAY4]
     vt.ValidateConstraint4(config, all_dates, assignment_dict, self.errors)
     self.assertEqual(len(self.errors), 0)
Пример #6
0
def ReadPersonConfig(ws, config, start_row=1, start_col=1):
    person_constraints = []
    for row_index in range(start_row + 1, start_row + config.num_person + 1):
        name_cell = ws.cell(row=row_index, column=start_col)
        mcw_cell = ws.cell(row=row_index,
                           column=start_col + 1)  # Max consecutive workdays
        mcn_cell = ws.cell(row=row_index,
                           column=start_col + 2)  # Max consecutive nights
        min_tw_cell = ws.cell(row=row_index,
                              column=start_col + 3)  # Min total workdays
        max_tw_cell = ws.cell(row=row_index,
                              column=start_col + 4)  # Max total workdays

        person_constraint = data_types.PersonConfig(name_cell.value,
                                                    mcw_cell.value,
                                                    mcn_cell.value,
                                                    min_tw_cell.value,
                                                    max_tw_cell.value)
        person_constraints.append(person_constraint)

    return person_constraints
Пример #7
0
    def testWritePersonConfigEmptyConstraints(self):
        ws = self.ws
        pc1 = data_types.PersonConfig('간호사1', None, None, None, None)
        excel_output.WritePersonConfigs(ws, [pc1])

        # Check header columns
        self.assertEqual(ws.cell(row=1, column=2).value, '최대 근무일 (연속)')
        self.assertEqual(ws.cell(row=1, column=3).value, '최대 나이트 (연속)')
        self.assertEqual(ws.cell(row=1, column=4).value, '최소 근무일 (전체)')
        self.assertEqual(ws.cell(row=1, column=5).value, '최대 근무일 (전체)')
        self.assertIsNone(ws.cell(
            row=1, column=6).value)  # Header columns should end here

        # Check header rows
        self.assertEqual(ws.cell(row=2, column=1).value, '간호사1')
        self.assertIsNone(ws.cell(
            row=3, column=1).value)  # Header rows should end here

        # Check all person constraint values are empty
        self.assertIsNone(ws.cell(row=2, column=2).value)
        self.assertIsNone(ws.cell(row=2, column=3).value)
        self.assertIsNone(ws.cell(row=2, column=4).value)
        self.assertIsNone(ws.cell(row=2, column=5).value)
Пример #8
0
    def testConstraint4MultipleErrors(self):
        # Constraint4. Multiple errors
        config = data_types.PersonConfig('name4', 1, 1, 5,
                                         5)  # Can work max 1 night at a time
        assignment_dict = {  # 2 nights from 04-01, 3 nights from 04-04
            (_DAY1, 'name4'): _NIGHT_SHIFT,
            (_DAY2, 'name4'): _NIGHT_SHIFT,
            (_DAY3, 'name4'): _OFF_SHIFT,
            (_DAY4, 'name4'): _NIGHT_SHIFT,
            (_DAY5, 'name4'): _NIGHT_SHIFT,
            (_DAY6, 'name4'): _NIGHT_SHIFT
        }
        all_dates = [_DAY1, _DAY2, _DAY3, _DAY4, _DAY5, _DAY6]
        vt.ValidateConstraint4(config, all_dates, assignment_dict, self.errors)
        self.assertEqual(len(self.errors), 2)

        self.assertEqual(
            self.errors[0],
            'Worker name4 should work no more than 1 consecutive nights, but worked for 2 nights from 2020-04-01'
        )
        self.assertEqual(
            self.errors[1],
            'Worker name4 should work no more than 1 consecutive nights, but worked for 3 nights from 2020-04-04'
        )