Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 0 additions & 9 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ class RostremApp extends StatelessWidget {
return MaterialApp(
title: 'Rostrem',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.red,
),
home: const RosterHomePage(),
Expand Down
10 changes: 5 additions & 5 deletions lib/models/roster.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,20 @@ class Roster {
}
}

// Check if the doctor is not on call the previous night unless it's a weekend
// Check if the doctor is not on call on the previous two nights
// Weekends break this rule, but are automatically copied between Saturday and Sunday
DateTime prevDate = date.subtract(const Duration(days: 1));
// if (role != 'day') {
DateTime prevPrevDate = date.subtract(const Duration(days: 2));
for (Shift shift in shifts) {
if (shift.date == prevDate &&
if ((assigner.isSameDate(shift.date, prevDate) ||
assigner.isSameDate(shift.date, prevPrevDate)) &&
(shift.mainDoctor == doctor ||
shift.caesarCoverDoctor == doctor ||
shift.secondOnCallDoctor == doctor ||
shift.weekendDayDoctor == doctor)) {
// if (date.weekday != DateTime.saturday) return false;
return false;
}
}
// }

// Ensure the main doctor and caesar cover doctor are not the same
if (role == 'caesarCover' &&
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/roster_home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ class RosterHomePageState extends State<RosterHomePage> {
_buildYearMonthSelector(),
IconButton(
icon: const Icon(Icons.refresh),
onPressed: () => _retryAssignments(1000),
onPressed: () => _retryAssignments(10000),
tooltip: 'Regenerate Assignments',
),
],
Expand Down
30 changes: 19 additions & 11 deletions test/models/assignment_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ void main() {
];
shifts = [
Shift(
date: DateTime.now().subtract(const Duration(days: 1)),
date: DateTime(2024, 8, 6, 6), // a Tuesday
type: 'Weekday'),
Shift(date: DateTime.now(), type: 'Weekday'),
Shift(date: DateTime(2024, 8, 7, 6), type: 'Weekday'),
];
hoursPerShiftType = {
'Overnight Weekday': 12,
Expand Down Expand Up @@ -177,8 +177,9 @@ void main() {

test('assignShifts() assigns all shifts for single-shift weekend roster',
() {
roster.shifts = [shifts[0]];
roster.shifts[0].type = 'Weekend';
roster.shifts = [
Shift(date: DateTime(2024, 8, 3, 6), type: 'Weekend')
]; // a Saturday

assigner.assignShifts(roster);

Expand All @@ -196,8 +197,10 @@ void main() {
});

test('assignShifts() assigns all shifts for two-shift weekend roster', () {
roster.shifts[0].type = 'Weekend';
roster.shifts[1].type = 'Weekend';
roster.shifts = [
Shift(date: DateTime(2024, 8, 3, 6), type: 'Weekend'),
Shift(date: DateTime(2024, 8, 4, 6), type: 'Weekend')
]; // a Saturday and a Sunday

assigner.assignShifts(roster);

Expand Down Expand Up @@ -270,8 +273,9 @@ void main() {
test(
'assignShifts() updates the overtime correctly for the relevant doctors for a single weekend shift roster',
() {
roster.shifts = [shifts[0]];
roster.shifts[0].type = 'Weekend';
roster.shifts = [
Shift(date: DateTime(2024, 8, 3, 6), type: 'Weekend')
]; // a Saturday
assigner.assignShifts(roster);

double totalOvertimeAllocated = 0.0;
Expand All @@ -289,17 +293,21 @@ void main() {
test(
'assignShifts() updates the overtime correctly for the relevant doctors for a weekday & weekend shift roster',
() {
roster.shifts = [shifts[0], shifts[1]];
roster.shifts[1].type = 'Weekend';
roster.shifts = [
Shift(date: DateTime(2024, 8, 4, 6), type: 'Weekend'),
Shift(date: DateTime(2024, 8, 7, 6), type: 'Weekday')
]; // a Sunday and Wednesday
assigner.assignShifts(roster);

expect(roster.filled, isTrue, reason: 'Roster is not fully filled');

double totalOvertimeAllocated = 0.0;
for (var doctor in doctors) {
totalOvertimeAllocated += doctor.overtimeHours;
}

double totalOvertimeToAllocate = 0.0;
for (var shift in shifts) {
for (var shift in roster.shifts) {
if (shift.type == 'Weekday') {
totalOvertimeToAllocate += weekdayShiftHours;
}
Expand Down
19 changes: 12 additions & 7 deletions test/models/roster_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ void main() {
];
shifts = [
Shift(
date: DateTime.now().subtract(const Duration(days: 1)),
date: DateTime(2024, 8, 6, 6), // a Tuesday
type: 'Weekday'),
Shift(date: DateTime.now(), type: 'Weekday'),
Shift(date: DateTime(2024, 8, 7, 6), type: 'Weekday'),
];
hoursPerShiftType = {
'Overnight Weekday': 12,
Expand Down Expand Up @@ -199,8 +199,9 @@ void main() {
test(
'retryAssignments() updates the overtime correctly for the relevant doctors for a single weekend shift roster',
() async {
roster.shifts = [shifts[0]];
roster.shifts[0].type = 'Weekend';
roster.shifts = [
Shift(date: DateTime(2024, 8, 4, 6), type: 'Weekend'),
]; // a Sunday

ValueNotifier<double> progressNotifier = ValueNotifier<double>(0);
await roster.retryAssignments(100, progressNotifier);
Expand All @@ -220,19 +221,23 @@ void main() {
test(
'retryAssignments() updates the overtime correctly for the relevant doctors for a weekday & weekend shift roster',
() async {
roster.shifts = [shifts[0], shifts[1]];
roster.shifts[1].type = 'Weekend';
roster.shifts = [
Shift(date: DateTime(2024, 8, 4, 6), type: 'Weekend'),
Shift(date: DateTime(2024, 8, 7, 6), type: 'Weekday')
]; // a Sunday and Wednesday

ValueNotifier<double> progressNotifier = ValueNotifier<double>(0);
await roster.retryAssignments(100, progressNotifier);

expect(roster.filled, isTrue, reason: 'Roster should be filled');

double totalOvertimeAllocated = 0.0;
for (var doctor in doctors) {
totalOvertimeAllocated += doctor.overtimeHours;
}

double totalOvertimeToAllocate = 0.0;
for (var shift in shifts) {
for (var shift in roster.shifts) {
if (shift.type == 'Weekday') {
totalOvertimeToAllocate += weekdayShiftHours;
}
Expand Down