modified the status query

This commit is contained in:
Salijoghli 2025-09-29 16:00:23 +04:00
parent 7eec6cd773
commit 2ae3e7087b
2 changed files with 62 additions and 130 deletions

View File

@ -633,7 +633,7 @@
"enabled": true, "enabled": true,
"rate": "3" "rate": "3"
}, },
"queryPath": "Alarms-autStand/GetActiveAlarms" "queryPath": "autStand/Alarms/GetActiveAlarms"
}, },
"transforms": [ "transforms": [
{ {
@ -1611,7 +1611,7 @@
"enabled": true, "enabled": true,
"rate": "3" "rate": "3"
}, },
"queryPath": "Alarms-autStand/GetAlarmsWithCount" "queryPath": "autStand/Alarms/GetAlarmsWithCount"
}, },
"transforms": [ "transforms": [
{ {
@ -3184,7 +3184,7 @@
"$": [ "$": [
"ts", "ts",
192, 192,
1759044922618 1759143973125
], ],
"$ts": 1755606669646 "$ts": 1755606669646
}, },
@ -3192,7 +3192,7 @@
"$": [ "$": [
"ts", "ts",
192, 192,
1759044922618 1759143973125
], ],
"$ts": 1755608469646 "$ts": 1755608469646
} }
@ -3256,7 +3256,7 @@
"enabled": true, "enabled": true,
"rate": "3" "rate": "3"
}, },
"queryPath": "Alarms-autStand/GetAlarms" "queryPath": "autStand/Alarms/GetAlarms"
}, },
"transforms": [ "transforms": [
{ {
@ -4334,7 +4334,7 @@
"$": [ "$": [
"ts", "ts",
192, 192,
1759044922619 1759143973124
], ],
"$ts": 1755606669646 "$ts": 1755606669646
}, },
@ -4342,7 +4342,7 @@
"$": [ "$": [
"ts", "ts",
192, 192,
1759044922618 1759143973124
], ],
"$ts": 1755608469646 "$ts": 1755608469646
}, },
@ -4601,6 +4601,7 @@
"contentStyle": { "contentStyle": {
"classes": "Background-Styles/Grey-Background" "classes": "Background-Styles/Grey-Background"
}, },
"currentTabIndex": 2,
"menuType": "modern", "menuType": "modern",
"style": { "style": {
"classes": "Background-Styles/Grey-Background" "classes": "Background-Styles/Grey-Background"

View File

@ -1,135 +1,66 @@
-- Generate all lanes 101-124 excluding 102, 104, 106
WITH DesiredLanes AS ( WITH DesiredLanes AS (
SELECT lane_number SELECT 101 + n AS lane_number
FROM ( FROM (
SELECT 101 + n AS lane_number SELECT a.N + b.N * 10 AS n
FROM ( FROM (SELECT 0 AS N UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4
SELECT a.N + b.N * 10 AS n UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) a,
FROM (SELECT 0 AS N UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION (SELECT 0 AS N UNION SELECT 1 UNION SELECT 2) b
SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) a, ) numbers
(SELECT 0 AS N UNION SELECT 1 UNION SELECT 2) b WHERE n <= 23 -- 101 to 124
) numbers AND (101 + n) NOT IN (102, 104, 106)
WHERE n <= 23 -- 101 to 124
) lanes
WHERE lane_number NOT IN (102, 104, 106) -- exclude these
), ),
AlarmData AS ( -- Aggregate Full alarms per lane
SELECT DISTINCT FullAlarms AS (
ae.id AS record_id,
ae.eventid AS event_uuid,
ae.source,
ae.eventtime AS active_time,
(SELECT MIN(eventtime)
FROM alarm_events ae2
WHERE ae2.eventid = ae.eventid
AND ae2.eventtype = 1
AND ae2.eventtime >= ae.eventtime
) AS clear_time
FROM alarm_events ae
WHERE
ae.eventtime BETWEEN :startDate AND :endDate
AND ae.eventtype = 0
AND (ae.source LIKE '%Chute%' OR ae.source LIKE '%ChuteStatus%')
),
LaneMapping AS (
SELECT SELECT
id AS record_id, aed.strValue AS myLocation,
strvalue AS tag_value, COUNT(*) AS FullCount,
CASE SUM(TIMESTAMPDIFF(SECOND, ae.eventtime, COALESCE(ae_clear.eventtime, NOW()))) AS FullDuration
WHEN strvalue LIKE '%Chute[%' THEN FROM alarm_events ae
CAST(SUBSTRING(strvalue, LOCATE('Chute[', strvalue) + 6, LEFT JOIN alarm_events ae_clear
LOCATE(']', strvalue, LOCATE('Chute[', strvalue)) - LOCATE('Chute[', strvalue) - 6) AS UNSIGNED) ON ae.eventid = ae_clear.eventid AND ae_clear.eventtype = 1
WHEN strvalue LIKE '%Chute[_%' THEN JOIN alarm_event_data aed
CAST(SUBSTRING(strvalue, LOCATE('Chute_', strvalue) + 6) AS UNSIGNED) ON aed.id = ae.id AND aed.propname = 'myLocation'
WHEN strvalue LIKE '%Chute%' THEN WHERE ae.eventtype = 0
CAST(REGEXP_SUBSTR(strvalue, '[0-9]+') AS UNSIGNED) AND ae.source LIKE '%Full%'
ELSE NULL AND ae.source LIKE '%Chute%'
END AS plc_index, AND ae.eventtime BETWEEN :startDate AND :endDate
CASE GROUP BY aed.strValue
WHEN strvalue LIKE '%Chute[%' THEN
CASE
WHEN CAST(SUBSTRING(strvalue, LOCATE('Chute[', strvalue) + 6,
LOCATE(']', strvalue, LOCATE('Chute[', strvalue)) - LOCATE('Chute[', strvalue) - 6) AS UNSIGNED) BETWEEN 1 AND 30
THEN 101 + (CAST(SUBSTRING(strvalue, LOCATE('Chute[', strvalue) + 6,
LOCATE(']', strvalue, LOCATE('Chute[', strvalue)) - LOCATE('Chute[', strvalue) - 6) AS UNSIGNED) - 1)
WHEN CAST(SUBSTRING(strvalue, LOCATE('Chute[', strvalue) + 6,
LOCATE(']', strvalue, LOCATE('Chute[', strvalue)) - LOCATE('Chute[', strvalue) - 6) AS UNSIGNED) BETWEEN 31 AND 60
THEN 201 + (CAST(SUBSTRING(strvalue, LOCATE('Chute[', strvalue) + 6,
LOCATE(']', strvalue, LOCATE('Chute[', strvalue)) - LOCATE('Chute[', strvalue) - 6) AS UNSIGNED) - 31)
ELSE NULL
END
WHEN strvalue LIKE '%Chute[_%' THEN
CASE
WHEN CAST(SUBSTRING(strvalue, LOCATE('Chute_', strvalue) + 6) AS UNSIGNED) BETWEEN 1 AND 30
THEN 101 + (CAST(SUBSTRING(strvalue, LOCATE('Chute_', strvalue) + 6) AS UNSIGNED) - 1)
WHEN CAST(SUBSTRING(strvalue, LOCATE('Chute_', strvalue) + 6) AS UNSIGNED) BETWEEN 31 AND 60
THEN 201 + (CAST(SUBSTRING(strvalue, LOCATE('Chute_', strvalue) + 6) AS UNSIGNED) - 31)
ELSE NULL
END
WHEN strvalue LIKE '%Chute%' THEN
CASE
WHEN CAST(REGEXP_SUBSTR(strvalue, '[0-9]+') AS UNSIGNED) BETWEEN 1 AND 30
THEN 101 + (CAST(REGEXP_SUBSTR(strvalue, '[0-9]+') AS UNSIGNED) - 1)
WHEN CAST(REGEXP_SUBSTR(strvalue, '[0-9]+') AS UNSIGNED) BETWEEN 31 AND 60
THEN 201 + (CAST(REGEXP_SUBSTR(strvalue, '[0-9]+') AS UNSIGNED) - 31)
ELSE NULL
END
ELSE NULL
END AS lane_number
FROM alarm_event_data
WHERE propname = 'Tag' AND strvalue LIKE '%Chute%'
), ),
JamEvents AS ( -- Aggregate Jammed alarms per lane
SELECT DISTINCT JammedAlarms AS (
lm.lane_number, SELECT
ad.event_uuid, aed.strValue AS myLocation,
ad.active_time, COUNT(*) AS JamCount,
ad.clear_time SUM(TIMESTAMPDIFF(SECOND, ae.eventtime, COALESCE(ae_clear.eventtime, NOW()))) AS JamDuration
FROM LaneMapping lm FROM alarm_events ae
INNER JOIN AlarmData ad ON lm.record_id = ad.record_id LEFT JOIN alarm_events ae_clear
INNER JOIN alarm_event_data aed ON ad.record_id = aed.id ON ae.eventid = ae_clear.eventid AND ae_clear.eventtype = 1
WHERE aed.propname = 'Jam' AND aed.strvalue = '1' JOIN alarm_event_data aed
), ON aed.id = ae.id AND aed.propname = 'myLocation'
FullEvents AS ( WHERE ae.eventtype = 0
SELECT DISTINCT AND ae.source LIKE '%Jammed%'
lm.lane_number, AND ae.source LIKE '%Chute%'
ad.event_uuid, AND ae.eventtime BETWEEN :startDate AND :endDate
ad.active_time, GROUP BY aed.strValue
ad.clear_time
FROM LaneMapping lm
INNER JOIN AlarmData ad ON lm.record_id = ad.record_id
INNER JOIN alarm_event_data aed ON ad.record_id = aed.id
WHERE aed.propname = 'Full' AND aed.strvalue = '1'
), ),
-- Combine Full and Jammed
Aggregated AS ( Aggregated AS (
SELECT SELECT
CONCAT('S03_', dl.lane_number, 'CH') AS lane, dl.lane_number,
COALESCE(j.jam_count, 0) AS jam_count, COALESCE(f.FullCount, 0) AS FullCount,
COALESCE(f.full_count, 0) AS full_count, COALESCE(j.JamCount, 0) AS JamCount,
COALESCE(j.jam_duration_seconds, 0) AS jam_duration_seconds, COALESCE(f.FullDuration, 0) AS FullDuration,
COALESCE(f.full_duration_seconds, 0) AS full_duration_seconds COALESCE(j.JamDuration, 0) AS JamDuration
FROM DesiredLanes dl FROM DesiredLanes dl
LEFT JOIN ( LEFT JOIN FullAlarms f ON f.myLocation = CONCAT('S03_CH', dl.lane_number)
SELECT LEFT JOIN JammedAlarms j ON j.myLocation = CONCAT('S03_CH', dl.lane_number)
lane_number,
COUNT(DISTINCT event_uuid) AS jam_count,
SUM(TIMESTAMPDIFF(SECOND, active_time, COALESCE(clear_time, NOW()))) AS jam_duration_seconds
FROM JamEvents
GROUP BY lane_number
) j ON dl.lane_number = j.lane_number
LEFT JOIN (
SELECT
lane_number,
COUNT(DISTINCT event_uuid) AS full_count,
SUM(TIMESTAMPDIFF(SECOND, active_time, COALESCE(clear_time, NOW()))) AS full_duration_seconds
FROM FullEvents
GROUP BY lane_number
) f ON dl.lane_number = f.lane_number
) )
SELECT SELECT
lane AS Lane, CONCAT('S03_CH', lane_number) AS Lane,
jam_count AS JamCount, FullCount,
full_count AS FullCount, JamCount,
COALESCE(SEC_TO_TIME(jam_duration_seconds), '00:00:00') AS JamDuration, FullDuration,
COALESCE(SEC_TO_TIME(full_duration_seconds), '00:00:00') AS FullDuration JamDuration
FROM Aggregated FROM Aggregated
ORDER BY lane; ORDER BY lane_number;