Ejemplo n.º 1
0
    def openBareboneExcel(self):
        filepath = filedialog.askopenfilename(
            title=_('Load barebone Excel file'),
            filetypes=constants.EXCEL_FILE_TYPE)
        if not filepath:
            return

        base_schedule = excel_input.ReadFromExcelFile(filepath)

        # Update labels
        start_date = base_schedule.software_config.start_date
        end_date = base_schedule.software_config.end_date
        self.updateLabels(filepath, start_date, end_date)

        # Validate
        errors = validator.ValidateTotalScheduleFormat(base_schedule,
                                                       barebone=True)

        if errors:
            self.addToTextArea('\n'.join(errors))
        else:
            self.addToTextArea(_('Starting..\n'))
            solver, var_dict = solver_input.FromTotalSchedule(base_schedule)
            self.addToTextArea(_('Starting the solver'))

            max_time_ms = self.max_time_var.get() * 60 * 1000
            solver.set_time_limit(max_time_ms)
            status = solver.Solve()
            self.addToTextArea(
                _('The solver stopped. Result: {status}\n').format(
                    status=status))

            if status == solver.INFEASIBLE:
                messagebox.showerror(message=_(
                    'No solution is found. Please check the conditions'))
                return
            else:
                messagebox.showinfo(message=_(
                    'Completed the schedule. Please choose the location to save it'
                ))

            new_schedule = solver_output.ToTotalSchedule(
                base_schedule.software_config, base_schedule.person_configs,
                base_schedule.date_configs, var_dict)

            errors = validator.ValidateTotalScheduleFormat(new_schedule,
                                                           barebone=False)
            if errors:
                self.addToTextArea('\n'.join(errors))
                return

            # Save to Excel file
            filepath = filedialog.asksaveasfilename(
                title=_('Save to..'), filetypes=constants.EXCEL_FILE_TYPE)
            if filepath:
                excel_output.FromTotalSchedule(new_schedule, filepath)
Ejemplo n.º 2
0
    def validateExcel(self):
        filepath = self.filepath
        if not filepath:
            return

        util.SetGrid(self.recheck_error_button, 4, 0)

        base_schedule = excel_input.ReadFromExcelFile(filepath)

        # Update labels
        start_date = base_schedule.software_config.start_date
        end_date = base_schedule.software_config.end_date
        self.updateLabels(filepath, start_date, end_date)

        # Validate
        errors = validator.ValidateTotalScheduleFormat(base_schedule, barebone=False)
        
        if errors:
            self.addToTextArea('\n'.join(errors))
        else:
            self.addToTextArea(_('No error is found.\n'))  # TODO: Add output time
Ejemplo n.º 3
0
    def openExcelToUpdate(self):
        filepath = filedialog.askopenfilename(
            title=_('Open schedule file to update'),
            filetypes=constants.EXCEL_FILE_TYPE)
        if not filepath:
            return

        self.base_schedule = excel_input.ReadFromExcelFile(filepath)

        # Update labels
        start_date = self.base_schedule.software_config.start_date
        end_date = self.base_schedule.software_config.end_date
        self.updateLabels(filepath, start_date, end_date)

        # Validate
        errors = validator.ValidateTotalScheduleFormat(self.base_schedule,
                                                       barebone=True)

        if errors:
            self.addToTextArea('\n'.join(errors))
        else:
            self.addToTextArea(
                _('No error is found. Please click Start button\n'))
Ejemplo n.º 4
0
from shiftscheduler.solver import input as solver_input
from shiftscheduler.solver import output as solver_output
from shiftscheduler.validation import validator


_INPUT_FILE_PATH = 'shiftscheduler/tmp/sample.xlsx'
_OUTPUT_FILE_PATH = 'shiftscheduler/tmp/updated.xlsx'


# 1. Read input Excel file (pre-configured with values)
# 2. Validate the input file
# 3. Run the solver
# 4. Validate solver output (just to make sure)
# 5. Write to the output file
if __name__ == '__main__':
    base_schedule = excel_input.ReadFromExcelFile(_INPUT_FILE_PATH)
    errors = validator.ValidateTotalScheduleFormat(base_schedule, barebone=True)
    print('errors', errors)
    if errors:
        sys.exit(0)
    solver, var_dict = solver_input.FromTotalSchedule(base_schedule)

    status = solver.Solve()
    print('Status:', status)

    new_schedule = solver_output.ToTotalSchedule(
        base_schedule.software_config, base_schedule.person_configs, base_schedule.date_configs, var_dict)
    
    errors = validator.ValidateTotalScheduleFormat(new_schedule, barebone=False)
    print('new errors', errors)
    if errors: