Commit 848762b9 authored by mohammed.akhib's avatar mohammed.akhib

UPDATED CCPP QUERIES and CCPC

parent cf93420f
...@@ -4191,6 +4191,44 @@ class SterliteCCPCQuery: ...@@ -4191,6 +4191,44 @@ class SterliteCCPCQuery:
CCPC report queries CCPC report queries
""" """
class Lpg:
QUERY_1 = """
select tbl2.kpi as particulars, tbl2.unit, sum(lpg_consumption)/sum(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.ccpc_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.ccpc_actual_production_data) 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
from semantic_prod.ccpc_actual_production_2) tbl2
on tbl1.date=tbl2.date
where tbl1.date BETWEEN '{day_start_date}' AND '{day_end_date}'
group by 1,2
;"""
QUERY_2 = """
select tbl2.kpi as particulars, tbl2.unit, sum(lpg_consumption)/sum(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.ccpc_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.ccpc_actual_production_data) 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
from semantic_prod.ccpc_actual_production_2) tbl2
on tbl1.date=tbl2.date
where tbl1.date BETWEEN '{month_start_date}' AND '{month_end_date}'
group by 1,2
;"""
class Production: class Production:
QUERY_1 = """ QUERY_1 = """
select select
...@@ -4393,6 +4431,42 @@ class SterliteCCPCQuery: ...@@ -4393,6 +4431,42 @@ class SterliteCCPCQuery:
group by 1,2; group by 1,2;
""" """
class Power1:
QUERY_1 = """
select tbl2.kpi as particulars, tbl2.unit, sum(power_consumption1)/sum(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.ccpc_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.ccpc_actual_production_data) b
on a.date=b.date
group by 1,2,3
) tbl1
inner join
(select 'power' as kpi, 'KWH/MT' as unit, date(date) as date, power_consumption1
from semantic_prod.ccpc_actual_production_2) tbl2
on tbl1.date=tbl2.date
where tbl1.date BETWEEN '{day_start_date}' AND '{day_end_date}'
group by 1,2"""
QUERY_2 = """
select tbl2.kpi as particulars, tbl2.unit, sum(power_consumption1)/sum(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.ccpc_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.ccpc_actual_production_data) b
on a.date=b.date
group by 1,2,3
) tbl1
inner join
(select 'power' as kpi, 'KWH/MT' as unit, date(date) as date, power_consumption1
from semantic_prod.ccpc_actual_production_2) tbl2
on tbl1.date=tbl2.date
where tbl1.date BETWEEN '{month_start_date}' AND '{month_end_date}'
group by 1,2"""
class BLISTER: class BLISTER:
""" PARTICULARS """ """ PARTICULARS """
QUERY_1 = """ SELECT QUERY_1 = """ SELECT
...@@ -5514,7 +5588,6 @@ class SterliteCCPCQuery: ...@@ -5514,7 +5588,6 @@ class SterliteCCPCQuery:
WHERE WHERE
LOWER(shift) = 'shift c' LOWER(shift) = 'shift c'
) foo WHERE DATE BETWEEN '{month_start_date}' AND '{month_end_date}' ) foo WHERE DATE BETWEEN '{month_start_date}' AND '{month_end_date}'
GROUP BY GROUP BY
1;""" 1;"""
...@@ -5598,84 +5671,152 @@ class SterliteCCPCQuery: ...@@ -5598,84 +5671,152 @@ class SterliteCCPCQuery:
1;""" 1;"""
class ANODEREJECTION: class ANODEREJECTION:
QUERY_1 = """SELECT QUERY_1 = """
kpi as particulars, select tbl2.kpi as particulars, tbl2.unit, (sum(rejection)/sum(production))*100 as on_date from
ROUND(SUM(CAST(metric_value AS NUMERIC)), 2) AS ondate, (select 'Production' as kpi, 'MT' as unit, a.date, (sum(anode_wt)*sum(total_anode))/1000 as production from
'MT' as unit (select date(date) as date, production_value as anode_wt from semantic_prod.ccpc_production_plan
FROM where lower(trim(production_anode))='anode weighment') a
( inner join
SELECT (select date(date) as date, total_anode_accepted_a+total_anode_accepted_b+total_anode_accepted_c as total_anode
date, from semantic_prod.ccpc_actual_production_data) b
'Anode rejection' AS kpi, on a.date=b.date
shift, group by 1,2,3
COALESCE(acp_reject_a, '0') AS metric_value ) tbl1
FROM left join
semantic_prod.charging_details_ccpc_new (
WHERE SELECT kpi, '%' as unit, date, SUM(CAST(metric_value AS NUMERIC)) AS rejection
LOWER(shift) = 'shift a' FROM (
UNION ALL SELECT date(date) as date, 'Anode rejection' AS kpi, shift, COALESCE(internal_reject_a, '0') AS metric_value
SELECT FROM semantic_prod.charging_details_ccpc_new
date, WHERE LOWER(shift) = 'shift a'
'Anode rejection' AS kpi, UNION ALL
shift, SELECT date(date) as date, 'Anode rejection' AS kpi, shift, COALESCE(internal_reject_b, '0') AS metric_value
COALESCE(acp_reject_b, '0') AS metric_value FROM semantic_prod.charging_details_ccpc_new
FROM WHERE LOWER(shift) = 'shift b'
semantic_prod.charging_details_ccpc_new UNION ALL
WHERE SELECT date(date) as date, 'Anode rejection' AS kpi, shift, COALESCE(internal_reject_c, '0') AS metric_value
LOWER(shift) = 'shift b' FROM semantic_prod.charging_details_ccpc_new
UNION ALL WHERE LOWER(shift) = 'shift c'
SELECT ) foo group by 1,2,3) tbl2
date, on tbl1.date=tbl2.date
'Anode rejection' AS kpi, where tbl1.date BETWEEN '{day_start_date}' AND '{day_end_date}'
shift, GROUP BY 1,2;"""
COALESCE(acp_reject_c, '0') AS metric_value QUERY_2 = """
FROM select tbl2.kpi as particulars, tbl2.unit, (sum(rejection)/sum(production))*100 as mtd from
semantic_prod.charging_details_ccpc_new (select 'Production' as kpi, 'MT' as unit, a.date, (sum(anode_wt)*sum(total_anode))/1000 as production from
WHERE (select date(date) as date, production_value as anode_wt from semantic_prod.ccpc_production_plan
LOWER(shift) = 'shift c' where lower(trim(production_anode))='anode weighment') a
) foo WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}' 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.ccpc_actual_production_data) b
on a.date=b.date
group by 1,2,3
) tbl1
left join
(
SELECT kpi, '%' as unit, date, SUM(CAST(metric_value AS NUMERIC)) AS rejection
FROM (
SELECT date(date) as date, 'Anode rejection' AS kpi, shift, COALESCE(internal_reject_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpc_new
WHERE LOWER(shift) = 'shift a'
UNION ALL
SELECT date(date) as date, 'Anode rejection' AS kpi, shift, COALESCE(internal_reject_b, '0') AS metric_value
FROM semantic_prod.charging_details_ccpc_new
WHERE LOWER(shift) = 'shift b'
UNION ALL
SELECT date(date) as date, 'Anode rejection' AS kpi, shift, COALESCE(internal_reject_c, '0') AS metric_value
FROM semantic_prod.charging_details_ccpc_new
WHERE LOWER(shift) = 'shift c'
) foo group by 1,2,3) tbl2
on tbl1.date=tbl2.date
where tbl1.date BETWEEN '{month_start_date}' AND '{month_end_date}'
GROUP BY 1,2; """
class AnodeInCCPCYard:
QUERY_1 = """
select
'Anodes in CCPC Yard' as particulars,
'MT' as unit,
sum(bookedanode_a) as on_date
from
semantic_prod.ccpc_daily_data_prod_3
where
date(date) BETWEEN '{day_start_date}' AND '{day_end_date}'
group by
1,
2;
"""
QUERY_2 = """
select
'Anodes in CCPC Yard' as particulars,
'MT' as unit,
sum(bookedanode_a) as mtd
from
semantic_prod.ccpc_daily_data_prod_3
where
date(date) BETWEEN '{month_start_date}' AND '{month_end_date}'
group by
1,
2;
"""
GROUP BY class Day02:
1;""" QUERY_1 = """
QUERY_2 = """SELECT select
kpi as particulars, 'Day O2' as particulars,
ROUND(SUM(CAST(metric_value AS NUMERIC)), 2) AS mtd, 'ppm' as unit,
'MT' as unit sum(refinary_labdata_oxygen) as on_date
FROM from
( semantic_prod.anode_refinery_lab
SELECT where
date, lower(trim(refinary_labdata_plant)) = 'ccpc'
'Anode rejection' AS kpi, and date(date) BETWEEN '{day_start_date}' AND '{day_end_date}'
shift, group by
COALESCE(acp_reject_a, '0') AS metric_value 1,
FROM 2;"""
semantic_prod.charging_details_ccpc_new QUERY_2 = """
WHERE select
LOWER(shift) = 'shift a' 'Day O2' as particulars,
UNION ALL 'ppm' as unit,
SELECT sum(refinary_labdata_oxygen) as mtd
date, from
'Anode rejection' AS kpi, semantic_prod.anode_refinery_lab
shift, where
COALESCE(acp_reject_b, '0') AS metric_value lower(trim(refinary_labdata_plant)) = 'ccpc'
FROM and date(date) BETWEEN '{month_start_date}' AND '{month_end_date}'
semantic_prod.charging_details_ccpc_new group by
WHERE 1,
LOWER(shift) = 'shift b' 2;"""
UNION ALL
SELECT
date,
'Anode rejection' AS kpi,
shift,
COALESCE(acp_reject_c, '0') AS metric_value
FROM
semantic_prod.charging_details_ccpc_new
WHERE
LOWER(shift) = 'shift c'
) foo WHERE DATE BETWEEN '{month_start_date}' AND '{month_end_date}'
GROUP BY class DayAs:
1;""" QUERY_1 = """
select
'Day As' as particulars,
'ppm' as unit,
sum(refinary_labdata_arsenic) as on_date
from
semantic_prod.anode_refinery_lab
where
lower(trim(refinary_labdata_plant)) = 'ccpc'
and date(date) BETWEEN '{day_start_date}' AND '{day_end_date}'
group by
1,
2;
"""
QUERY_2 = """
select
'Day As' as particulars,
'ppm' as unit,
sum(refinary_labdata_arsenic) as mtd
from
semantic_prod.anode_refinery_lab
where
lower(trim(refinary_labdata_plant)) = 'ccpc'
and date(date) BETWEEN '{month_start_date}' AND '{month_end_date}'
group by
1,
2;
"""
class TotalBreakdownDetails: class TotalBreakdownDetails:
""" TOTAL BREAKDOWN DETAILS """ """ TOTAL BREAKDOWN DETAILS """
...@@ -6178,7 +6319,7 @@ class SterliteCCPPQuery: ...@@ -6178,7 +6319,7 @@ class SterliteCCPPQuery:
(select 'LPG' as kpi, 'KG/MT' as unit, date(date) as date, lpg_consumption_total (select 'LPG' as kpi, 'KG/MT' as unit, date(date) as date, lpg_consumption_total
from semantic_prod.ccpp_actual_production_2) tbl2 from semantic_prod.ccpp_actual_production_2) tbl2
on tbl1.date=tbl2.date on tbl1.date=tbl2.date
where a.date between '{day_start_date}' AND '{day_end_date}' where tbl1.date.date between '{day_start_date}' AND '{day_end_date}'
group by 1,2; group by 1,2;
""" """
QUERY_2 = """ QUERY_2 = """
...@@ -6196,7 +6337,7 @@ class SterliteCCPPQuery: ...@@ -6196,7 +6337,7 @@ class SterliteCCPPQuery:
(select 'LPG' as kpi, 'KG/MT' as unit, date(date) as date, lpg_consumption_total (select 'LPG' as kpi, 'KG/MT' as unit, date(date) as date, lpg_consumption_total
from semantic_prod.ccpp_actual_production_2) tbl2 from semantic_prod.ccpp_actual_production_2) tbl2
on tbl1.date=tbl2.date on tbl1.date=tbl2.date
where a.date between '{month_start_date}' AND '{month_end_date}' where tbl1.date.date between '{month_start_date}' AND '{month_end_date}'
group by 1,2; group by 1,2;
""" """
...@@ -6282,7 +6423,7 @@ class SterliteCCPPQuery: ...@@ -6282,7 +6423,7 @@ class SterliteCCPPQuery:
(select 'power' as parameters, 'KWH/MT' as unit, date(date) as date, power_consumption_total (select 'power' as parameters, 'KWH/MT' as unit, date(date) as date, power_consumption_total
from semantic_prod.ccpp_actual_production_2) tbl2 from semantic_prod.ccpp_actual_production_2) tbl2
on tbl1.date=tbl2.date on tbl1.date=tbl2.date
WHERE a.date BETWEEN '{day_start_date}' AND '{day_end_date}' WHERE tbl1.date.date BETWEEN '{day_start_date}' AND '{day_end_date}'
group by 1,2; group by 1,2;
""" """
...@@ -6301,7 +6442,7 @@ class SterliteCCPPQuery: ...@@ -6301,7 +6442,7 @@ class SterliteCCPPQuery:
(select 'power' as parameters, 'KWH/MT' as unit, date(date) as date, power_consumption_total (select 'power' as parameters, 'KWH/MT' as unit, date(date) as date, power_consumption_total
from semantic_prod.ccpp_actual_production_2) tbl2 from semantic_prod.ccpp_actual_production_2) tbl2
on tbl1.date=tbl2.date on tbl1.date=tbl2.date
WHERE a.date BETWEEN '{month_start_date}' AND '{month_end_date}' WHERE tbl1.date.date BETWEEN '{month_start_date}' AND '{month_end_date}'
group by 1,2; group by 1,2;
""" """
......
...@@ -25,10 +25,15 @@ class CCPCReportTemplate: ...@@ -25,10 +25,15 @@ class CCPCReportTemplate:
"MTD", "MTD",
], ],
"query": { "query": {
"Production":[ "Production":[
SterliteCCPCQuery.Production.QUERY_1, SterliteCCPCQuery.Production.QUERY_1,
SterliteCCPCQuery.Production.QUERY_2 SterliteCCPCQuery.Production.QUERY_2
], ],
"Lpg": [
SterliteCCPCQuery.Lpg.QUERY_1,
SterliteCCPCQuery.Lpg.QUERY_2
],
"BariumSulphateP":[ "BariumSulphateP":[
SterliteCCPCQuery.BariumSulphateP.QUERY_1, SterliteCCPCQuery.BariumSulphateP.QUERY_1,
SterliteCCPCQuery.BariumSulphateP.QUERY_2 SterliteCCPCQuery.BariumSulphateP.QUERY_2
...@@ -37,6 +42,10 @@ class CCPCReportTemplate: ...@@ -37,6 +42,10 @@ class CCPCReportTemplate:
SterliteCCPCQuery.Sodiumsilicate.QUERY_1, SterliteCCPCQuery.Sodiumsilicate.QUERY_1,
SterliteCCPCQuery.Sodiumsilicate.QUERY_2 SterliteCCPCQuery.Sodiumsilicate.QUERY_2
], ],
"Power":[
SterliteCCPCQuery.Power1.QUERY_1,
SterliteCCPCQuery.Power1.QUERY_2
],
"BLISTER": [ "BLISTER": [
SterliteCCPCQuery.BLISTER.QUERY_1, SterliteCCPCQuery.BLISTER.QUERY_1,
SterliteCCPCQuery.BLISTER.QUERY_2, SterliteCCPCQuery.BLISTER.QUERY_2,
...@@ -109,6 +118,18 @@ class CCPCReportTemplate: ...@@ -109,6 +118,18 @@ class CCPCReportTemplate:
SterliteCCPCQuery.ANODEREJECTION.QUERY_1, SterliteCCPCQuery.ANODEREJECTION.QUERY_1,
SterliteCCPCQuery.ANODEREJECTION.QUERY_2, SterliteCCPCQuery.ANODEREJECTION.QUERY_2,
], ],
"AnodeInCCPCYard":[
SterliteCCPCQuery.AnodeInCCPCYard.QUERY_1,
SterliteCCPCQuery.AnodeInCCPCYard.QUERY_2
],
"Day02":[
SterliteCCPCQuery.Day02.QUERY_1,
SterliteCCPCQuery.Day02.QUERY_2
],
"DayAs":[
SterliteCCPCQuery.DayAs.QUERY_1,
SterliteCCPCQuery.DayAs.QUERY_2
]
}, },
"data": [], "data": [],
"data_column": ["particulars", "unit", "on_date", "mtd", "data_column": ["particulars", "unit", "on_date", "mtd",
...@@ -408,6 +429,8 @@ class CCPCReportTemplate: ...@@ -408,6 +429,8 @@ class CCPCReportTemplate:
"REASON FOR STOPAGE" "REASON FOR STOPAGE"
], ],
"query": { "query": {
"ActivityTime":[
SterliteCCPCQuery.ActivityTime.QUERY_1]
}, },
"data": [], "data": [],
"data_column": [ "data_column": [
......
...@@ -32,8 +32,8 @@ class CCPPReportTemplate: ...@@ -32,8 +32,8 @@ class CCPPReportTemplate:
SterliteCCPPQuery.Production.QUERY_2 SterliteCCPPQuery.Production.QUERY_2
], ],
"Lpg": [ "Lpg": [
# SterliteCCPPQuery.Lpg.QUERY_1, SterliteCCPPQuery.Lpg.QUERY_1,
# SterliteCCPPQuery.Lpg.QUERY_2, SterliteCCPPQuery.Lpg.QUERY_2,
], ],
"BariumSulphate": [ "BariumSulphate": [
SterliteCCPPQuery.BariumSulphate.QUERY_1, SterliteCCPPQuery.BariumSulphate.QUERY_1,
...@@ -45,8 +45,8 @@ class CCPPReportTemplate: ...@@ -45,8 +45,8 @@ class CCPPReportTemplate:
SterliteCCPPQuery.SodiumSilicate.QUERY_2, SterliteCCPPQuery.SodiumSilicate.QUERY_2,
], ],
"Power": [ "Power": [
# SterliteCCPPQuery.Power.QUERY_1, SterliteCCPPQuery.Power.QUERY_1,
# SterliteCCPPQuery.Power.QUERY_2, SterliteCCPPQuery.Power.QUERY_2,
], ],
"KanshakiBlister": [ "KanshakiBlister": [
SterliteCCPPQuery.KanshakiBlister.QUERY_1, SterliteCCPPQuery.KanshakiBlister.QUERY_1,
......
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