Compare commits
No commits in common. "ce9bba6ae97f65313a517ba18768ec43eb0d78d6" and "afafd1034d6d42856df862f1d090fc5c30a5ce22" have entirely different histories.
ce9bba6ae9
...
afafd1034d
File diff suppressed because it is too large
Load Diff
@ -1,60 +0,0 @@
|
|||||||
WITH Active AS (
|
|
||||||
SELECT
|
|
||||||
ae.id,
|
|
||||||
ae.eventtime,
|
|
||||||
ae.eventid,
|
|
||||||
ae.source,
|
|
||||||
ae.priority,
|
|
||||||
ae.displaypath,
|
|
||||||
TIMESTAMPDIFF(SECOND, ae.eventtime, NOW()) AS duration_seconds
|
|
||||||
FROM alarm_events ae
|
|
||||||
WHERE ae.eventtype = 0
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1 FROM alarm_events ae_clear
|
|
||||||
WHERE ae_clear.eventid = ae.eventid
|
|
||||||
AND ae_clear.eventtype = 1
|
|
||||||
)
|
|
||||||
AND ae.displaypath NOT LIKE '%System Startup%'
|
|
||||||
AND ae.source NOT LIKE '%System Startup%'
|
|
||||||
-- Priority filter using FIND_IN_SET for comma-separated values
|
|
||||||
AND (
|
|
||||||
:priorityList IS NULL
|
|
||||||
OR :priorityList = ''
|
|
||||||
OR FIND_IN_SET(ae.priority, :priorityList) > 0
|
|
||||||
)
|
|
||||||
GROUP BY ae.id
|
|
||||||
),
|
|
||||||
SingleMyTag AS (
|
|
||||||
SELECT aed.id, aed.strValue
|
|
||||||
FROM alarm_event_data aed
|
|
||||||
WHERE aed.propname = 'myTag'
|
|
||||||
GROUP BY aed.id
|
|
||||||
)
|
|
||||||
SELECT
|
|
||||||
Active.id AS ID,
|
|
||||||
Active.eventtime AS StartTimestamp,
|
|
||||||
NULL AS EndTimestamp, -- no end time since it's still active
|
|
||||||
CONCAT(
|
|
||||||
LPAD(FLOOR(Active.duration_seconds / 3600), 2, '0'), ':',
|
|
||||||
LPAD(FLOOR((Active.duration_seconds % 3600) / 60), 2, '0'), ':',
|
|
||||||
LPAD(Active.duration_seconds % 60, 2, '0')
|
|
||||||
) AS Duration,
|
|
||||||
CONCAT(Active.displaypath, ' - ', SUBSTRING_INDEX(Active.source, ':/alm:', -1)) AS Description,
|
|
||||||
CASE Active.priority
|
|
||||||
WHEN 0 THEN 'Diagnostic'
|
|
||||||
WHEN 1 THEN 'Low'
|
|
||||||
WHEN 2 THEN 'Medium'
|
|
||||||
WHEN 3 THEN 'High'
|
|
||||||
WHEN 4 THEN 'Critical'
|
|
||||||
ELSE 'Unknown'
|
|
||||||
END AS Priority,
|
|
||||||
CONCAT(
|
|
||||||
Active.displaypath,
|
|
||||||
'.HMI.',
|
|
||||||
SUBSTRING_INDEX(aed.strValue, '/', -1)
|
|
||||||
) AS Tag,
|
|
||||||
SUBSTRING_INDEX(SUBSTRING_INDEX(aed.strValue, '/', 2), '/', -1) AS Location
|
|
||||||
FROM Active
|
|
||||||
LEFT JOIN SingleMyTag aed
|
|
||||||
ON aed.id = Active.id
|
|
||||||
ORDER BY Active.eventtime DESC;
|
|
||||||
@ -1,40 +0,0 @@
|
|||||||
{
|
|
||||||
"scope": "DG",
|
|
||||||
"version": 2,
|
|
||||||
"restricted": false,
|
|
||||||
"overridable": true,
|
|
||||||
"files": [
|
|
||||||
"query.sql"
|
|
||||||
],
|
|
||||||
"attributes": {
|
|
||||||
"useMaxReturnSize": false,
|
|
||||||
"autoBatchEnabled": false,
|
|
||||||
"fallbackValue": "",
|
|
||||||
"maxReturnSize": 100,
|
|
||||||
"cacheUnit": "SEC",
|
|
||||||
"type": "Query",
|
|
||||||
"enabled": true,
|
|
||||||
"cacheAmount": 1,
|
|
||||||
"cacheEnabled": false,
|
|
||||||
"database": "MariaDB",
|
|
||||||
"fallbackEnabled": false,
|
|
||||||
"lastModificationSignature": "d4eef6a8194fc16fb2061c0ffe057909fb37ddedbe4fd6e4f2416cc6050f6209",
|
|
||||||
"permissions": [
|
|
||||||
{
|
|
||||||
"zone": "default",
|
|
||||||
"role": ""
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"lastModification": {
|
|
||||||
"actor": "admin",
|
|
||||||
"timestamp": "2025-06-23T10:38:45Z"
|
|
||||||
},
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"type": "Parameter",
|
|
||||||
"identifier": "priorityList",
|
|
||||||
"sqlType": 7
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,46 +1,17 @@
|
|||||||
WITH Active AS (
|
|
||||||
SELECT
|
|
||||||
ae.id,
|
|
||||||
ae.eventtime,
|
|
||||||
ae.eventid,
|
|
||||||
ae.source,
|
|
||||||
ae.priority,
|
|
||||||
ae.displaypath,
|
|
||||||
TIMESTAMPDIFF(SECOND, ae.eventtime, COALESCE(ae_clear.eventtime, NOW())) AS duration_seconds
|
|
||||||
FROM alarm_events ae
|
|
||||||
LEFT JOIN alarm_events ae_clear
|
|
||||||
ON ae.eventid = ae_clear.eventid AND ae_clear.eventtype = 1
|
|
||||||
WHERE ae.eventtype = 0
|
|
||||||
AND ae.displaypath NOT LIKE '%System Startup%'
|
|
||||||
AND ae.source NOT LIKE '%System Startup%'
|
|
||||||
GROUP BY ae.id -- Ensure one row per alarm
|
|
||||||
),
|
|
||||||
SingleMyTag AS (
|
|
||||||
SELECT aed.id, aed.strValue
|
|
||||||
FROM alarm_event_data aed
|
|
||||||
WHERE aed.propname = 'myTag'
|
|
||||||
GROUP BY aed.id -- Collapse duplicates by id
|
|
||||||
),
|
|
||||||
SingleClear AS (
|
|
||||||
SELECT eventid, MIN(eventtime) AS eventtime
|
|
||||||
FROM alarm_events
|
|
||||||
WHERE eventtype = 1
|
|
||||||
GROUP BY eventid
|
|
||||||
)
|
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
Active.id AS ID,
|
Active.id AS ID,
|
||||||
Active.eventtime AS StartTimestamp,
|
Active.eventtime AS `StartTimestamp`,
|
||||||
Clear.eventtime AS EndTimestamp,
|
Clear.eventtime AS `EndTimestamp`,
|
||||||
|
|
||||||
CONCAT(
|
CONCAT(
|
||||||
LPAD(FLOOR(Active.duration_seconds / 3600), 2, '0'), ':',
|
LPAD(FLOOR(duration_seconds / 3600), 2, '0'), ':',
|
||||||
LPAD(FLOOR((Active.duration_seconds % 3600) / 60), 2, '0'), ':',
|
LPAD(FLOOR((duration_seconds % 3600) / 60), 2, '0'), ':',
|
||||||
LPAD(Active.duration_seconds % 60, 2, '0')
|
LPAD(duration_seconds % 60, 2, '0')
|
||||||
) AS Duration,
|
) AS Duration,
|
||||||
|
CONCAT(
|
||||||
CONCAT(Active.displaypath, ' - ', SUBSTRING_INDEX(Active.source, ':/alm:', -1)) AS Description,
|
SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(Active.source, '/HMI/ALARMST', 1), ':/tag:', -1), '/', -1),
|
||||||
|
' - ',
|
||||||
|
SUBSTRING_INDEX(Active.source, ':/alm:', -1)
|
||||||
|
) AS Description,
|
||||||
CASE Active.priority
|
CASE Active.priority
|
||||||
WHEN 0 THEN 'Diagnostic'
|
WHEN 0 THEN 'Diagnostic'
|
||||||
WHEN 1 THEN 'Low'
|
WHEN 1 THEN 'Low'
|
||||||
@ -49,21 +20,21 @@ SELECT
|
|||||||
WHEN 4 THEN 'Critical'
|
WHEN 4 THEN 'Critical'
|
||||||
ELSE 'Unknown'
|
ELSE 'Unknown'
|
||||||
END AS Priority,
|
END AS Priority,
|
||||||
|
SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(Active.source, '/HMI/ALARMST', 1), ':/tag:', -1), '/', -1) AS Tag,
|
||||||
CONCAT(
|
SUBSTRING_INDEX(SUBSTRING_INDEX(Active.source, '/tag:', -1), '/', 1) AS MCM
|
||||||
Active.displaypath,
|
FROM (
|
||||||
'.HMI.',
|
SELECT
|
||||||
SUBSTRING_INDEX(aed.strValue, '/', -1)
|
ae.id,
|
||||||
) AS Tag,
|
ae.eventtime,
|
||||||
|
ae.eventid,
|
||||||
SUBSTRING_INDEX(SUBSTRING_INDEX(aed.strValue, '/', 2), '/', -1) AS Location
|
ae.source,
|
||||||
|
ae.priority,
|
||||||
FROM Active
|
TIMESTAMPDIFF(SECOND, ae.eventtime, COALESCE(ae_clear.eventtime, NOW())) AS duration_seconds
|
||||||
|
FROM alarm_events ae
|
||||||
LEFT JOIN SingleClear Clear
|
LEFT JOIN alarm_events ae_clear
|
||||||
ON Active.eventid = Clear.eventid
|
ON ae.eventid = ae_clear.eventid AND ae_clear.eventtype = 1
|
||||||
|
WHERE ae.eventtype = 0
|
||||||
LEFT JOIN SingleMyTag aed
|
) AS Active
|
||||||
ON aed.id = Active.id
|
LEFT JOIN alarm_events Clear
|
||||||
|
ON Active.eventid = Clear.eventid AND Clear.eventtype = 1
|
||||||
ORDER BY Active.eventtime DESC;
|
ORDER BY Active.eventtime DESC;
|
||||||
|
|||||||
@ -1,60 +0,0 @@
|
|||||||
SELECT
|
|
||||||
CONCAT(Active.displaypath, ' - ', SUBSTRING_INDEX(Active.source, ':/alm:', -1)) AS Description,
|
|
||||||
|
|
||||||
SUBSTRING_INDEX(SUBSTRING_INDEX(aed.strValue, '/', 2), '/', -1) AS Location,
|
|
||||||
|
|
||||||
-- Formatted OPC-style tag
|
|
||||||
CONCAT(
|
|
||||||
Active.displaypath,
|
|
||||||
'.HMI.',
|
|
||||||
SUBSTRING_INDEX(aed.strValue, '/', -1)
|
|
||||||
) AS Tag,
|
|
||||||
|
|
||||||
CASE Active.priority
|
|
||||||
WHEN 0 THEN 'Diagnostic'
|
|
||||||
WHEN 1 THEN 'Low'
|
|
||||||
WHEN 2 THEN 'Medium'
|
|
||||||
WHEN 3 THEN 'High'
|
|
||||||
WHEN 4 THEN 'Critical'
|
|
||||||
ELSE 'Unknown'
|
|
||||||
END AS Priority,
|
|
||||||
|
|
||||||
-- First and last seen times for this alarm
|
|
||||||
MIN(Active.eventtime) AS FirstTimestamp,
|
|
||||||
MAX(Active.eventtime) AS LastTimestamp,
|
|
||||||
|
|
||||||
-- Total duration summed from each active-clear pair
|
|
||||||
CONCAT(
|
|
||||||
LPAD(FLOOR(SUM(Active.duration_seconds) / 3600), 2, '0'), ':',
|
|
||||||
LPAD(FLOOR((SUM(Active.duration_seconds) % 3600) / 60), 2, '0'), ':',
|
|
||||||
LPAD(SUM(Active.duration_seconds) % 60, 2, '0')
|
|
||||||
) AS Duration,
|
|
||||||
|
|
||||||
-- Total number of activations
|
|
||||||
COUNT(*) AS Count
|
|
||||||
|
|
||||||
FROM (
|
|
||||||
SELECT
|
|
||||||
ae.id,
|
|
||||||
ae.source,
|
|
||||||
ae.eventid,
|
|
||||||
ae.eventtime,
|
|
||||||
ae.priority,
|
|
||||||
ae.displaypath,
|
|
||||||
TIMESTAMPDIFF(SECOND, ae.eventtime, COALESCE(ae_clear.eventtime, NOW())) AS duration_seconds
|
|
||||||
FROM alarm_events ae
|
|
||||||
LEFT JOIN alarm_events ae_clear
|
|
||||||
ON ae.eventid = ae_clear.eventid AND ae_clear.eventtype = 1
|
|
||||||
WHERE ae.eventtype = 0
|
|
||||||
AND ae.displaypath NOT LIKE '%System Startup%'
|
|
||||||
AND ae.source NOT LIKE '%System Startup%'
|
|
||||||
) AS Active
|
|
||||||
|
|
||||||
-- OPC tag path for building .hmi.Tag output
|
|
||||||
LEFT JOIN alarm_event_data aed
|
|
||||||
ON aed.id = Active.id AND aed.propname = 'myTag'
|
|
||||||
|
|
||||||
-- 🔹 Group by the full unique alarm key (tag + alarm name)
|
|
||||||
GROUP BY Active.source, Active.displaypath, aed.strValue
|
|
||||||
|
|
||||||
ORDER BY FirstTimestamp DESC;
|
|
||||||
Loading…
x
Reference in New Issue
Block a user