Commit e6c166f7 authored by mohammed.akhib's avatar mohammed.akhib

UPDATED CCPP QUERIES

parent 11fd85f6
......@@ -5930,32 +5930,48 @@ class SterliteCCPPQuery:
class Lpg:
QUERY_1 = """
select
'lpg' as kpi,
'KG/MT' as unit,
lpg_consumption_total as metric_value
from
semantic_prod.ccpp_actual_production_2
WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
;
select tbl2.kpi, tbl2.unit, sum(lpg_consumption_total/production) as metric_value from
(select 'Production' as kpi, 'MT' as unit, a.date, (sum(anode_wt)*sum(total_anode))/1000 as production from
(select date(date) as date, production_value as anode_wt from semantic_prod.ccpp_production_plan
where lower(trim(production_anode))='anode weighment') a
inner join
(select date(date) as date, total_anode_accepted_a+total_anode_accepted_b+total_anode_accepted_c as total_anode
from semantic_prod.ccpp_actual_production_new) b
on a.date=b.date
group by 1,2,3
) tbl1
inner join
(select 'LPG' as kpi, 'KG/MT' as unit, date(date) as date, lpg_consumption_total
from semantic_prod.ccpp_actual_production_2) tbl2
on tbl1.date=tbl2.date
--where a.date between '{day_start_date}' AND '{day_end_date}'
group by 1,2;
"""
QUERY_2 = """
select
'lpg' as kpi,
'KG/MT' as unit,
lpg_consumption_total as metric_value
from
semantic_prod.ccpp_actual_production_2
WHERE DATE BETWEEN '{month_start_date}' AND '{month_end_date}'
;
select tbl2.kpi, tbl2.unit, sum(lpg_consumption_total/production) as metric_value from
(select 'Production' as kpi, 'MT' as unit, a.date, (sum(anode_wt)*sum(total_anode))/1000 as production from
(select date(date) as date, production_value as anode_wt from semantic_prod.ccpp_production_plan
where lower(trim(production_anode))='anode weighment') a
inner join
(select date(date) as date, total_anode_accepted_a+total_anode_accepted_b+total_anode_accepted_c as total_anode
from semantic_prod.ccpp_actual_production_new) b
on a.date=b.date
group by 1,2,3
) tbl1
inner join
(select 'LPG' as kpi, 'KG/MT' as unit, date(date) as date, lpg_consumption_total
from semantic_prod.ccpp_actual_production_2) tbl2
on tbl1.date=tbl2.date
--where a.date between '{month_start_date}' AND '{month_end_date}'
group by 1,2;
"""
class SodiumSilicate:
QUERY_1 = """
SELECT
kpi,
SUM(CAST(metric_value AS NUMERIC)) AS metric_value,
'KG/MT' as unit
kpi as particulars,
'KG/MT' as unit,
SUM(CAST(metric_value AS NUMERIC)) AS on_date
FROM
(
SELECT
......@@ -5996,9 +6012,10 @@ class SterliteCCPPQuery:
"""
QUERY_2 = """
SELECT
kpi,
SUM(CAST(metric_value AS NUMERIC)) AS metric_value,
'KG/MT' as unit
kpi as particulars,
'KG/MT' as unit,
SUM(CAST(metric_value AS NUMERIC)) AS mtd
FROM
(
SELECT
......@@ -6042,18 +6059,18 @@ class SterliteCCPPQuery:
class Power:
QUERY_1 = """
select
'power' as kpi,
'power' as particulars,
'KWH/MT' as unit,
power_consumption_total as metric_value
power_consumption_total as on_date
from
semantic_prod.ccpp_actual_production_2
WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}';
"""
QUERY_2 = """
select
'power' as kpi,
'power' as particulars,
'KWH/MT' as unit,
power_consumption_total as metric_value
power_consumption_total as mtd
from
semantic_prod.ccpp_actual_production_2
WHERE DATE BETWEEN '{month_start_date}' AND '{month_end_date}';
......@@ -6061,7 +6078,7 @@ class SterliteCCPPQuery:
class KanshakiBlister:
QUERY_1 = """
SELECT kpi, SUM(CAST(metric_value AS NUMERIC)) AS metric_value, 'MT' as unit
SELECT kpi as particulars,'MT' as unit, SUM(CAST(metric_value AS NUMERIC)) AS on_date
FROM (
SELECT date, 'Kanshashi Blister' AS kpi, shift, COALESCE(blister_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
......@@ -6083,7 +6100,7 @@ class SterliteCCPPQuery:
GROUP BY 1 ;
"""
QUERY_2 = """
SELECT kpi, SUM(CAST(metric_value AS NUMERIC)) AS metric_value, 'MT' as unit
SELECT kpi as particulars, 'MT' as unit, SUM(CAST(metric_value AS NUMERIC)) AS mtd
FROM (
SELECT date, 'Kanshashi Blister' AS kpi, shift, COALESCE(blister_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
......@@ -6107,7 +6124,7 @@ class SterliteCCPPQuery:
class RejectedCoil:
QUERY_1 = """
SELECT kpi, SUM(CAST(metric_value AS NUMERIC)) AS metric_value, 'MT' as unit
SELECT kpi as particulars, 'MT' as unit, SUM(CAST(metric_value AS NUMERIC)) AS on_date
FROM (
SELECT date, 'Rejected coils' AS kpi, shift, COALESCE(rejected_coil_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
......@@ -6128,7 +6145,7 @@ class SterliteCCPPQuery:
GROUP BY 1 ;
"""
QUERY_2 = """
SELECT kpi, SUM(CAST(metric_value AS NUMERIC)) AS metric_value, 'MT' as unit
SELECT kpi as particulars ,'MT' as unit, SUM(CAST(metric_value AS NUMERIC)) AS mtd
FROM (
SELECT date, 'Rejected coils' AS kpi, shift, COALESCE(rejected_coil_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
......@@ -6151,7 +6168,7 @@ class SterliteCCPPQuery:
class MasterAlloy:
QUERY_1 = """
SELECT kpi, SUM(CAST(metric_value AS NUMERIC)) AS metric_value, 'MT' as unit
SELECT kpi as particulars, 'MT' as unit, SUM(CAST(metric_value AS NUMERIC)) AS on_date
FROM (
SELECT date, 'Master Alloy' AS kpi, shift, COALESCE(master_alloy_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
......@@ -6172,7 +6189,7 @@ class SterliteCCPPQuery:
GROUP BY 1 ;
"""
QUERY_2 = """
SELECT kpi, SUM(CAST(metric_value AS NUMERIC)) AS metric_value, 'MT' as unit
SELECT kpi as particulars, 'MT' as unit, SUM(CAST(metric_value AS NUMERIC)) AS mtd
FROM (
SELECT date, 'Master Alloy' AS kpi, shift, COALESCE(master_alloy_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
......@@ -6195,7 +6212,7 @@ class SterliteCCPPQuery:
class CssBlister:
QUERY_1 = """
SELECT kpi, SUM(CAST(metric_value AS NUMERIC)) AS metric_value, 'MT' as unit
SELECT kpi as particulars, 'MT' as unit, SUM(CAST(metric_value AS NUMERIC)) AS on_date
FROM (
SELECT date, 'CSS Blister' AS kpi, shift, COALESCE(css_blister_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
......@@ -6216,7 +6233,7 @@ class SterliteCCPPQuery:
GROUP BY 1 ;
"""
QUERY_2 = """
SELECT kpi, SUM(CAST(metric_value AS NUMERIC)) AS metric_value, 'MT' as unit
SELECT kpi as particulars, 'MT' as unit, SUM(CAST(metric_value AS NUMERIC)) AS mtd
FROM (
SELECT date, 'CSS Blister' AS kpi, shift, COALESCE(css_blister_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
......@@ -6239,7 +6256,7 @@ class SterliteCCPPQuery:
class InternalRejectionAnode:
QUERY_1 = """
SELECT kpi, SUM(CAST(metric_value AS NUMERIC)) AS metric_value, 'MT' as unit
SELECT kpi as particulars, 'MT' as unit, SUM(CAST(metric_value AS NUMERIC)) AS on_date
FROM (
SELECT date, 'Internal Rejected Anode' AS kpi, shift, COALESCE(internal_reject_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
......@@ -6260,7 +6277,7 @@ class SterliteCCPPQuery:
GROUP BY 1 ;
"""
QUERY_2 = """
SELECT kpi, SUM(CAST(metric_value AS NUMERIC)) AS metric_value, 'MT' as unit
SELECT kpi as particulars, 'MT' as unit, SUM(CAST(metric_value AS NUMERIC)) AS mtd
FROM (
SELECT date, 'Internal Rejected Anode' AS kpi, shift, COALESCE(internal_reject_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
......@@ -6283,7 +6300,7 @@ class SterliteCCPPQuery:
class RefinerySpentAnode:
QUERY_1 = """
SELECT kpi, SUM(CAST(metric_value AS NUMERIC)) AS metric_value, 'MT' as unit
SELECT kpi as particulars, 'MT' as unit, SUM(CAST(metric_value AS NUMERIC)) AS on_date
FROM (
SELECT date, 'Refinery Spent Anode' AS kpi, shift, COALESCE(ref_spent_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
......@@ -6304,7 +6321,7 @@ class SterliteCCPPQuery:
GROUP BY 1 ;
"""
QUERY_2 = """
SELECT kpi, SUM(CAST(metric_value AS NUMERIC)) AS metric_value, 'MT' as unit
SELECT kpi as particulars, 'MT' as unit, SUM(CAST(metric_value AS NUMERIC)) AS mtd
FROM (
SELECT date, 'Refinery Spent Anode' AS kpi, shift, COALESCE(ref_spent_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
......@@ -6328,7 +6345,7 @@ class SterliteCCPPQuery:
class SapProduction:
QUERY_1 = """
select
kpi,
kpi as particulars,
sum(value) as Metric_Value
from
semantic_prod.acp_ccpc_ccpp_view
......@@ -6584,7 +6601,9 @@ class SterliteCCPPQuery:
group by
1;
"""
QUERY_2 = """
class TotalBreakdownDetails1:
QUERY_1 = """
select
'Total(Mins)' as kpi,
sum(breakdown_duration_hours * 60) as breakdown_duration_mins
......@@ -6611,20 +6630,15 @@ class SterliteCCPPQuery:
class MonthwiseProductionDetails:
QUERY_1 = """
select
kpi,
category,
sum(value) as Metric_Value
from
semantic_prod.acp_ccpc_ccpp_view
where
lower(kpi) in('production actual', 'production plan')
and lower(category) = 'ccpp' and
DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
group by
kpi,
category
;
select TO_CHAR(TO_DATE(month::text, 'MM'),'Mon') as month, max(target) as target, max(production) as production from
(select month,
case when lower(kpi)='production plan' then sum(value) else 0 end as target,
case when lower(kpi)='production actual' then sum(value) else 0 end as production
from semantic_prod.acp_ccpc_ccpp_view
where lower(kpi) in('production actual','production plan')
and lower(category) = 'ccpp'
and DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
group by 1,kpi) foo group by 1;
"""
class Paticulars:
......@@ -6713,7 +6727,7 @@ class SterliteCCPPQuery:
) foo WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
GROUP BY 1 ;
"""
QUERY_1 = """
QUERY_2 = """
SELECT kpi, SUM(CAST(metric_value AS NUMERIC)) AS metric_value, 'KG/MT' as unit
FROM (
SELECT date, 'BARIUM SULPHATE' AS kpi, shift, COALESCE(barium_sulphate_a, '0') AS metric_value
......@@ -6802,29 +6816,143 @@ class SterliteCCPPQuery:
"""
class Tbc:
QUERY_1 = """"
SELECT kpi, shift, value, CAST(date AS TIME) AS time
FROM (
SELECT date, lpg_param AS kpi, shift, COALESCE(lpg_value, '0') AS value
FROM semantic_prod.ccpp_lpg_vapouriser
WHERE LOWER(shift) = 'shift a'
UNION ALL
SELECT date, lpg_param2 AS kpi, shift, COALESCE(lpg_value2, '0') AS value
FROM semantic_prod.ccpp_lpg_vapouriser
WHERE LOWER(shift) = 'shift b'
UNION ALL
SELECT date, lpg_param3 AS kpi, shift, COALESCE(lpg_value3, '0') AS value
FROM semantic_prod.ccpp_lpg_vapouriser
WHERE LOWER(shift) = 'shift c'
) foo
where <date_filters>
select * from semantic_prod.ccpp_lpg_vapouriser"
QUERY_1 = """
SELECT kpi, shift, value, CAST(date AS TIME) AS time
FROM (
SELECT date, lpg_param AS kpi, shift, COALESCE(lpg_value, '0') AS value
FROM semantic_prod.ccpp_lpg_vapouriser
WHERE LOWER(shift) = 'shift a'
UNION ALL
SELECT date, lpg_param2 AS kpi, shift, COALESCE(lpg_value2, '0') AS value
FROM semantic_prod.ccpp_lpg_vapouriser
WHERE LOWER(shift) = 'shift b'
UNION ALL
SELECT date, lpg_param3 AS kpi, shift, COALESCE(lpg_value3, '0') AS value
FROM semantic_prod.ccpp_lpg_vapouriser
WHERE LOWER(shift) = 'shift c'
) foo
WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
"""
class Production:
QUERY_1 = """
select
'Production' as parameters,
'MT' as unit,
(sum(anode_wt) * sum(total_anode)) / 1000 as on_date
from
(
select
date(date) as date,
production_value as anode_wt
from
semantic_prod.ccpp_production_plan
where
lower(trim(production_anode)) = 'anode weighment'
) a
inner join (
select
date(date) as date,
total_anode_accepted_a + total_anode_accepted_b + total_anode_accepted_c as total_anode
from
semantic_prod.ccpp_actual_production_new
) b on a.date = b.date
where
a.date between '{day_start_date}' and '{day_end_date}';
"""
QUERY_2 = """
select
'Production' as parameters,
'MT' as unit,
(sum(anode_wt) * sum(total_anode)) / 1000 as mtd
from
(
select
date(date) as date,
production_value as anode_wt
from
semantic_prod.ccpp_production_plan
where
lower(trim(production_anode)) = 'anode weighment'
) a
inner join (
select
date(date) as date,
total_anode_accepted_a + total_anode_accepted_b + total_anode_accepted_c as total_anode
from
semantic_prod.ccpp_actual_production_new
) b on a.date = b.date
where
a.date between '{month_start_date}' and '{month_end_date}';
"""
"""
class BariumSulphate:
QUERY_1 = """
select tbl2.parameters, tbl2.unit, sum(barium_sulphate/production) as on_date from
(select 'Production' as kpi, 'MT' as unit, a.date, (sum(anode_wt)*sum(total_anode))/1000 as production from
(select date(date) as date, production_value as anode_wt from semantic_prod.ccpp_production_plan
where lower(trim(production_anode))='anode weighment') a
inner join
(select date(date) as date, total_anode_accepted_a+total_anode_accepted_b+total_anode_accepted_c as total_anode
from semantic_prod.ccpp_actual_production_new) b
on a.date=b.date
group by 1,2,3
) tbl1
left join
(SELECT kpi as parameters, 'KG/MT' as unit, date(date) as date, SUM(CAST(metric_value AS NUMERIC)) AS barium_sulphate
FROM (
SELECT date, 'BARIUM SULPHATE' AS kpi, shift, COALESCE(barium_sulphate_a, '0') AS metric_value
FROM semantic_prod.ccpp_actual_production_new
WHERE LOWER(shift) = 'shift a' and barium_sulphate_a != ''
UNION ALL
SELECT date, 'BARIUM SULPHATE' AS kpi, shift, COALESCE(barium_sulphate_b, '0') AS metric_value
FROM semantic_prod.ccpp_actual_production_new
WHERE LOWER(shift) = 'shift b' and barium_sulphate_b != ''
UNION ALL
SELECT date, 'BARIUM SULPHATE' AS kpi, shift, COALESCE(barium_sulphate_c, '0') AS metric_value
FROM semantic_prod.ccpp_actual_production_new
WHERE LOWER(shift) = 'shift c' and barium_sulphate_c != ''
)foo GROUP BY 1,2,3
) tbl2
on tbl1.date=tbl2.date
tbl1.date between '{day_start_date}' and '{day_end_date}'
group by 1,2
;
"""
QUERY_2 = """
select tbl2.parameters, tbl2.unit, sum(barium_sulphate/production) as mtd from
(select 'Production' as kpi, 'MT' as unit, a.date, (sum(anode_wt)*sum(total_anode))/1000 as production from
(select date(date) as date, production_value as anode_wt from semantic_prod.ccpp_production_plan
where lower(trim(production_anode))='anode weighment') a
inner join
(select date(date) as date, total_anode_accepted_a+total_anode_accepted_b+total_anode_accepted_c as total_anode
from semantic_prod.ccpp_actual_production_new) b
on a.date=b.date
group by 1,2,3
) tbl1
left join
(SELECT kpi as parameters, 'KG/MT' as unit, date(date) as date, SUM(CAST(metric_value AS NUMERIC)) AS barium_sulphate
FROM (
SELECT date, 'BARIUM SULPHATE' AS kpi, shift, COALESCE(barium_sulphate_a, '0') AS metric_value
FROM semantic_prod.ccpp_actual_production_new
WHERE LOWER(shift) = 'shift a' and barium_sulphate_a != ''
UNION ALL
SELECT date, 'BARIUM SULPHATE' AS kpi, shift, COALESCE(barium_sulphate_b, '0') AS metric_value
FROM semantic_prod.ccpp_actual_production_new
WHERE LOWER(shift) = 'shift b' and barium_sulphate_b != ''
UNION ALL
SELECT date, 'BARIUM SULPHATE' AS kpi, shift, COALESCE(barium_sulphate_c, '0') AS metric_value
FROM semantic_prod.ccpp_actual_production_new
WHERE LOWER(shift) = 'shift c' and barium_sulphate_c != ''
)foo GROUP BY 1,2,3
) tbl2
on tbl1.date=tbl2.date
tbl1.date between '{month_start_date}' and '{month_end_date}'
group by 1,2
;
"""
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment