# 2.2. Shifts and Scheduled Operating Times of Workplaces¶

## 2.2.1. Domain-Specific Knowledge¶

### 2.2.1.1. Workplace Shifts¶

The term shift work describes a work structuring, in which employees work on the same job in succession, following a specific schedule, so that they have to do their job, within a specific timeframe at different times. Shift work is done in a plant, when it is necessary to work longer than the usual daily work hours or when operations or on-call duties are needed outside the usual daily work hours for other reasons.

Shifts are defined for workplaces; for instance in the three-shift operation these are usually morning shift, late shift and night shift. This concept describes a so-called shift model.

If one of the shifts shall be omitted on a certain day, the shift is marked as idle period or nonworking shift. The other shifts are working shifts, but so-called shift breaks, during which the production will be halted, can be defined within a working shift.

### 2.2.1.2. Scheduled Maintenance Times¶

These are times during which machine - but not manual - workplaces will be serviced. The scheduled maintenance has the goal to reduce disruptions, so that machines do not unexpectedly give out, which would consequently trigger an unscheduled maintenance. These times usually take place in regular maintenance intervals.

### 2.2.1.3. Scheduled Operating Times¶

The scheduled operating time is the period in which a workplace should be in production according to shift planning and maintenance planning. This includes all working shifts less shift breaks and planned maintenance.

## 2.2.2. The Digital Image in FORCE Bridge API¶

The above mentioned entities can be found in the sub-resources of workplaces or a specific workplace respectively.

GET workplaces/shifts
Request shifts of a workplace
GET workplaces/shifts/{shiftId}
Request details for a certain shift.
GET workplaces/{workplaceId}/scheduledOperatingTimes
Request workplace scheduled operating times.
GET workplace/{workplaceId}/scheduledMaintenanceTimes
Requests the scheduled maintenance times of a workplace.

## 2.2.3. Tutorials¶

Tutorial 1

Query the scheduled shifts and scheduled maintenance dates for the next two weeks. Then calculate the scheduled operating times. Afterwards compare your calculated times with the times from the scheduled operating times interface.

Solution: show/hide

Java

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84  IWorkplaceClient workplaceClient = api.getWorkplaceClient(); Interval nextTwoWeeks = Interval.getWeekInterval(2, 2); /* Retrieve all workplaces */ Page workplaceResponsePage = null; try { GetWorkplacesRequest workplacesRequest = new GetWorkplacesRequest(); workplaceResponsePage = workplaceClient.getWorkplaces(workplacesRequest); } catch (ForceAPIException e) { LOGGER.error(e.getMessage()); } List workplaceResponses = workplaceResponsePage .streamForward() .collect(Collectors.toList()); /* Cache the workplace UUIDs */ List workplaceIDs = workplaceResponses .stream() .map(WorkplaceResponse::getProperties) .map(WorkplacePropertiesWSModel::getId) .collect(Collectors.toList()); /* Get the shifts of all workplaces*/ GetWorkplaceShiftsRequest workplaceShiftsRequest = new GetWorkplaceShiftsRequest(); workplaceShiftsRequest.setStartDate(nextTwoWeeks.getStartDate()); workplaceShiftsRequest.setEndDate(nextTwoWeeks.getEndDate()); Page shiftResponsesPage = null; try { shiftResponsesPage = workplaceClient.getShifts(workplaceShiftsRequest); } catch (ForceAPIException e) { LOGGER.error(e.getMessage()); } final List shiftResponses = shiftResponsesPage .streamForward() .collect(Collectors.toList()); for (WorkplaceShiftResponse shiftResponse : shiftResponses) { } /* For each workplace get the scheduled maintenance dates */ final Map> collect = workplaceIDs .stream() .collect(Collectors.toMap(k -> k, v -> { GetWorkplaceScheduledTimesRequest scheduledTimesRequest = new GetWorkplaceScheduledTimesRequest(v); scheduledTimesRequest.setStartDate(nextTwoWeeks.getStartDate()); scheduledTimesRequest.setEndDate(nextTwoWeeks.getEndDate()); WorkplaceScheduledMaintenanceTimesCollectionPage scheduledMaintenanceTimesPage = null; try { scheduledMaintenanceTimesPage = workplaceClient.getWorkplaceScheduledMaintenanceTimes(scheduledTimesRequest); } catch (ForceAPIException e) { LOGGER.error(e.getMessage()); } return scheduledMaintenanceTimesPage .streamForward() .collect(Collectors.toList()); })); /* For each workplace get scheduled operating times */ Map> scheduledOperatingTimes = workplaceIDs .stream() .collect(Collectors.toMap(k -> k, v -> { GetWorkplaceScheduledTimesRequest scheduledTimesRequest = new GetWorkplaceScheduledTimesRequest(v); scheduledTimesRequest.setStartDate(nextTwoWeeks.getStartDate()); scheduledTimesRequest.setEndDate(nextTwoWeeks.getEndDate()); WorkplaceScheduledOperatingTimesCollectionPage scheduledOperatingTimesPage = null; try { scheduledOperatingTimesPage = workplaceClient.getScheduledOperatingTimes(scheduledTimesRequest); } catch (ForceAPIException e) { LOGGER.error(e.getMessage()); } return scheduledOperatingTimesPage .streamForward() .collect(Collectors.toList()); })); 

Tutorial 2

Query the scheduled shifts and scheduled maintenance dates of the previous two weeks. Then calculate the scheduled operating times based on the retrieved values. Afterwards compare your results with the values in the scheduled operating times interface.

Hint

The scheduled operating times should be always identical!

Solution: show/hide

Java

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45  final IWorkplaceClient workplaceClient = api.getWorkplaceClient(); try { final Interval previousTwoWeeks = Interval.getWeekInterval(2, -1); final GetWorkplacesRequest workplacesRequest = new GetWorkplacesRequest(); final Page workplaceResponsePage = workplaceClient.getWorkplaces(workplacesRequest); workplaceResponsePage .streamForward() .map(WorkplaceResponse::getProperties) .map(WorkplacePropertiesWSModel::getId) .forEach(workplaceId -> { try { /* Retrieve the scheduled shifts*/ final GetWorkplaceShiftsRequest workplaceShiftsRequest = new GetWorkplaceShiftsRequest(); workplaceShiftsRequest.setWorkplaceId(workplaceId); workplaceShiftsRequest.setPaginationTimestamp(previousTwoWeeks.getEndDate()); workplaceShiftsRequest.setPaginationDirection(PaginationDirection.PREVIOUS); final Page shifts = workplaceClient.getShifts(workplaceShiftsRequest); final Map workplaceScheduledShifts = shifts .streamForward() .map(WorkplaceShiftResponse::getProperties) .collect(Collectors.toMap(p -> workplaceId, CreateWorkplaceShiftPropertiesWSModel::getShift)); /* Retrieve the scheduled maintenance dates */ final GetWorkplaceScheduledTimesRequest scheduledTimesRequest = new GetWorkplaceScheduledTimesRequest(workplaceId); scheduledTimesRequest.setStartDate(previousTwoWeeks.getStartDate()); scheduledTimesRequest.setEndDate(previousTwoWeeks.getEndDate()); final WorkplaceScheduledMaintenanceTimesCollectionPage scheduledMaintenancePages = workplaceClient.getWorkplaceScheduledMaintenanceTimes( scheduledTimesRequest); final Map workplaceScheduledMaintenance = scheduledMaintenancePages .streamForward() .collect(Collectors.toMap(k -> workplaceId, v -> v)); } catch (ForceAPIException e) { LOGGER.error(e.getMessage()); } }); } catch (ForceAPIException e) { LOGGER.error(e.getMessage()); }