[]()
The shift selector allows you to adjust the time range of your grafana dashboard to one specific shift or a range of shifts. On this page we'll show you how it works and how you can adjust the displayed shifts to a specific season or production line.
With this new feature, you can enable the shift selector to track shifts automatically based on the local time. So you don't need to change shifts manually. To use this new feature, you need to enable it through the panel options.
"Real-time shift auto-select"
refresh interval
(these should be according to the time interval pattern of Grafana. Eg. for 5 seconds -> 5s
, 1 hour -> 1h
)group_uuid
Be aware that enabling real-time will hide the date and range selectors
var_query_map
"Start-End"
, "Start"
and, "End"
labels.With this plugin you are able to choose between dynamic (from a datasource
) and static.
To start quickly, set shifts (groups) in the Data Mapper
panel:
Shifts from a data source to false
{
"static": {
"shifts": [
{
"group": "Group 1",
"group_uuid": "group_uuid_1",
"uuid": "shift_uuid_1",
"label": "Morning Custom",
"startTime": "06:00:00",
"endTime": "14:00:00",
"order": 1
},
{
"group": "Group 2",
"group_uuid": "group_uuid_2",
"uuid": "shift_uuid_2",
"label": "Afternoon Custom",
"startTime": "14:00:00",
"endTime": "22:00:00",
"order": 1
},
{
"group": "Group 2",
"group_uuid": "group_uuid_2",
"uuid": "shift_uuid_3",
"label": "Night Custom",
"startTime": "22:00:00",
"endTime": "06:00:00",
"order": 2
}
]
}
}
Now you are able to see the shifts in two groups. Group 1
and Group 2
. This could for example be summer or winter time.
In order to set you shifts from a datasource please continue to read.
The options you can choose are: (from left to right)
The shift selector can also handle multiple shift groups, to distinguish between them, the names of these groups are added in front of the buttons. However, if there is only one shift group available, that name will disappear, as in the example above.
When you click a button, the selected time will change to the selected shift time. In this example we have chosen two seasonal shift groups: one for the summer and one for the winter.
Group name | Shift name | Shift order | Start time | End time |
---|---|---|---|---|
Summer | Morning | 1 | 8:00 | 14:00 |
Summer | Afternoon | 2 | 14:00 | 22:00 |
Summer | Night | 3 | 22:00 | 8:00 |
Winter | Night | 1 | 22:30 | 10:30 |
Winter | Day | 2 | 10:30 | 22:30 |
In this example we have selected the day May 17th 2021 which leads to the following shift times:
Group name | Shift name | Updated start time | Updated end time |
---|---|---|---|
Summer | 1. Morning | May 17th 8:00 | May 17th 14:00 |
Summer | 2. Afternoon | May 17th 14:00 | May 17th 22:00 |
Summer | 3. Night | May 17th 22:00 | May 18th 8:00 |
Winter | 1. Night | May 16th 22:30 | May 17th 10:30 |
Winter | 2. Day | May 17th 10:30 | May 17th 22:30 |
The dates in bold are the dates that belong to a shift that passes midnight. The dates are updated accordingly.
Warning: the shift selector only works well when your computer is in the right timezone. Changing the timezone in Grafana does not affect the behavior of the shift selector.
In order to add the shift selector, you'll have to do two things:
Create a hidden variable with the names of the shifts you want to display. To do so, go to 'dashboard settings' -> 'variables' -> 'add new variable'. Then use the following settings to create the variable:
Database
var_shifts_dataModel
This will result in:
Shifts data model mapper
var_query_map
var_query_map.example.js
file. You can remove the static
values because you will be fetching them from your datasource.
shift_groups
table fields. You can change the name
, uuid
, site_uuid
fields according to your database scheme.shifts
table fields. Change the uuid
, start_time
, end_time
, order
, group_uuid
according to your databse scheme.Options
var_shifts_options
SELECT
S.name AS '__text',
S.uuid AS '__value'
FROM shifts S
This will result in:
*Note that when you have multiple shift groups with shifts with the same name, the names of the shifts should be unique.
If both shift groups have a shift named 'morning', it is easiest to make the name of the shift unique by adding the shift order or the shift group name to the AS '__text'
in the query, two examples:
CONCAT(S.shift_order, '. ', S.name) AS '__text', -- to add the number of the order of the shift
CONCAT(SG.name, ' - ', S.name) AS '__text', -- to add the shift group name
sites
CREATE TABLE `sites` (
`uuid` varchar(22) NOT NULL,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`uuid`),
UNIQUE KEY `name_UNIQUE` (`name`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
shift_groups
CREATE TABLE `shift_groups` (
`uuid` varchar(22) NOT NULL,
`name` varchar(255) NOT NULL,
`site_uuid` varchar(22) NOT NULL,
PRIMARY KEY (`uuid`),
UNIQUE KEY `site_uuid_name_UNIQUE` (`site_uuid`,`name`),
KEY `shift_group_site_uuid_idx` (`site_uuid`),
CONSTRAINT `shift_group_site_uuid` FOREIGN KEY (`site_uuid`) REFERENCES `sites` (`uuid`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
shifts
CREATE TABLE `shifts` (
`uuid` varchar(22) NOT NULL,
`name` varchar(255) NOT NULL COMMENT 'Name or description of shift',
`shift_order` int NOT NULL COMMENT 'Order of the shifts on a operational day for the shift_group_uuid as referenced by shift_group_uuid',
`start_time` time NOT NULL COMMENT 'The time that the shift starts (local timezone)',
`end_time` time NOT NULL COMMENT 'The time that the shift ends (local timezone)',
`shift_group_uuid` varchar(22) NOT NULL COMMENT 'Uuid of the shift group',
PRIMARY KEY (`uuid`),
UNIQUE KEY `name_group_uuid_UNIQUE` (`shift_group_uuid`,`name`),
UNIQUE KEY `order_group_uuid_UNIQUE` (`shift_group_uuid`,`shift_order`),
UNIQUE KEY `start_time_group_uuid_UNIQUE` (`shift_group_uuid`,`start_time`),
UNIQUE KEY `end_time_group_uuid_UNIQUE` (`shift_group_uuid`,`end_time`),
KEY `shifts_group_uuid_idx` (`shift_group_uuid`),
CONSTRAINT `shifts_shift_group_uuid_fk` FOREIGN KEY (`shift_group_uuid`) REFERENCES `shift_groups` (`uuid`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
If you want to filter the shifts that are displayed to for instance a certain shift group or belonging to a production line, you can add extra variables to your dashboard and implement them in the variable _shiftsoptions. Two examples are described below, of which the production line example has been implemented in a couple of global dashboards.
Create a variable to select the production line (or work center):
Variable name: work center
Query: (update example01
to your factory code)
SELECT
WC.name AS '__text',
WC.uuid AS '__value'
FROM work_centers WC
LEFT JOIN sites SI ON SI.uuid = WC.site_uuid
WHERE SI.code = 'example01'
Update the query for the _shiftsoptions to:
SELECT
S.name AS '__text',
S.uuid AS '__value'
FROM shifts S
LEFT JOIN shift_groups SG ON SG.uuid = S.shift_group_uuid
LEFT JOIN work_center_has_shift_groups WCHSG ON WCHSG.work_center_uuid = ${work_center}
Create a variable to select the shift group:
Variable name: _shiftsgroup
Query: (update example01
to your factory site code)
SELECT
SG.name AS '__text',
SG.uuid AS '__value'
FROM shift_groups SG
LEFT JOIN sites SI ON SI.uuid = SG.site_uuid
WHERE SI.code = 'example01'
Update the query for the _shiftsoptions to:
SELECT
S.name AS '__text',
S.uuid AS '__value'
FROM shifts S
LEFT JOIN shift_groups SG ON SG.uuid = S.shift_group_uuid
WHERE SG.uuid = ${shift_group}