Fixed the bug of seeing duplciate alarms in the historical alarms
This commit is contained in:
parent
543c430448
commit
76e026896d
@ -699,10 +699,10 @@
|
||||
},
|
||||
"value": {
|
||||
"Description": "MCM01 Hello world",
|
||||
"Duration": "00:01:14",
|
||||
"EventTimestamp": "2025-06-20 21:11:53",
|
||||
"Duration": "00:05:48",
|
||||
"EventTimestamp": "2025-06-23 13:10:26",
|
||||
"Location": "MCM01",
|
||||
"NumberID": 42,
|
||||
"NumberID": 60,
|
||||
"Priority": "Low",
|
||||
"Tag": "MCM01.HMI.Beacon_Light"
|
||||
}
|
||||
@ -1409,10 +1409,10 @@
|
||||
"data": [
|
||||
{
|
||||
"Description": "MCM01 Hello world",
|
||||
"Duration": "00:01:14",
|
||||
"EventTimestamp": "2025-06-20 21:11:53",
|
||||
"Duration": "00:03:48",
|
||||
"EventTimestamp": "2025-06-23 13:10:26",
|
||||
"Location": "MCM01",
|
||||
"NumberID": 42,
|
||||
"NumberID": 60,
|
||||
"Priority": "Low",
|
||||
"Tag": "MCM01.HMI.Beacon_Light"
|
||||
}
|
||||
@ -2731,7 +2731,7 @@
|
||||
"value": {
|
||||
"$": [
|
||||
"ts",
|
||||
192,
|
||||
201,
|
||||
1750436956149
|
||||
],
|
||||
"$ts": 1750436956149
|
||||
@ -2910,7 +2910,6 @@
|
||||
"children": [
|
||||
{
|
||||
"custom": {
|
||||
"initial_data": [],
|
||||
"max_duration": {
|
||||
"$": [
|
||||
"ts",
|
||||
@ -2924,7 +2923,7 @@
|
||||
"$": [
|
||||
"ts",
|
||||
192,
|
||||
1750436956154
|
||||
1750667761263
|
||||
],
|
||||
"$ts": 1750435156149
|
||||
},
|
||||
@ -2932,7 +2931,7 @@
|
||||
"$": [
|
||||
"ts",
|
||||
192,
|
||||
1750436956154
|
||||
1750667761263
|
||||
],
|
||||
"$ts": 1750436956149
|
||||
}
|
||||
@ -3872,7 +3871,7 @@
|
||||
"$": [
|
||||
"ts",
|
||||
192,
|
||||
1750436956154
|
||||
1750667761263
|
||||
],
|
||||
"$ts": 1750435156149
|
||||
},
|
||||
@ -3880,7 +3879,7 @@
|
||||
"$": [
|
||||
"ts",
|
||||
192,
|
||||
1750436956154
|
||||
1750667761263
|
||||
],
|
||||
"$ts": 1750436956149
|
||||
},
|
||||
@ -4139,6 +4138,7 @@
|
||||
"contentStyle": {
|
||||
"classes": "Background-Styles/Grey-Background"
|
||||
},
|
||||
"currentTabIndex": 2,
|
||||
"menuType": "modern",
|
||||
"style": {
|
||||
"classes": "Background-Styles/Grey-Background"
|
||||
|
||||
@ -1,13 +1,42 @@
|
||||
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
|
||||
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
|
||||
Active.id AS ID,
|
||||
Active.eventtime AS StartTimestamp,
|
||||
Clear.eventtime AS EndTimestamp,
|
||||
|
||||
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
|
||||
@ -27,25 +56,12 @@ SELECT
|
||||
|
||||
SUBSTRING_INDEX(SUBSTRING_INDEX(aed.strValue, '/', 2), '/', -1) AS Location
|
||||
|
||||
FROM (
|
||||
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
|
||||
) AS Active
|
||||
FROM Active
|
||||
|
||||
LEFT JOIN alarm_events Clear
|
||||
ON Active.eventid = Clear.eventid AND Clear.eventtype = 1
|
||||
LEFT JOIN SingleClear Clear
|
||||
ON Active.eventid = Clear.eventid
|
||||
|
||||
LEFT JOIN alarm_event_data aed
|
||||
ON aed.id = Active.id AND aed.propname = 'myTag'
|
||||
LEFT JOIN SingleMyTag aed
|
||||
ON aed.id = Active.id
|
||||
|
||||
ORDER BY Active.eventtime DESC;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user