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

UPDATED CCPP QUERIES and CCPC

parent cf93420f
......@@ -4191,6 +4191,44 @@ class SterliteCCPCQuery:
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:
QUERY_1 = """
select
......@@ -4393,6 +4431,42 @@ class SterliteCCPCQuery:
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:
""" PARTICULARS """
QUERY_1 = """ SELECT
......@@ -5514,7 +5588,6 @@ class SterliteCCPCQuery:
WHERE
LOWER(shift) = 'shift c'
) foo WHERE DATE BETWEEN '{month_start_date}' AND '{month_end_date}'
GROUP BY
1;"""
......@@ -5598,84 +5671,152 @@ class SterliteCCPCQuery:
1;"""
class ANODEREJECTION:
QUERY_1 = """SELECT
kpi as particulars,
ROUND(SUM(CAST(metric_value AS NUMERIC)), 2) AS ondate,
'MT' as unit
FROM
(
SELECT
date,
'Anode rejection' AS kpi,
shift,
COALESCE(acp_reject_a, '0') AS metric_value
FROM
semantic_prod.charging_details_ccpc_new
WHERE
LOWER(shift) = 'shift a'
UNION ALL
SELECT
date,
'Anode rejection' AS kpi,
shift,
COALESCE(acp_reject_b, '0') AS metric_value
FROM
semantic_prod.charging_details_ccpc_new
WHERE
LOWER(shift) = 'shift b'
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 '{day_start_date}' AND '{day_end_date}'
QUERY_1 = """
select tbl2.kpi as particulars, tbl2.unit, (sum(rejection)/sum(production))*100 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
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 '{day_start_date}' AND '{day_end_date}'
GROUP BY 1,2;"""
QUERY_2 = """
select tbl2.kpi as particulars, tbl2.unit, (sum(rejection)/sum(production))*100 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
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
1;"""
QUERY_2 = """SELECT
kpi as particulars,
ROUND(SUM(CAST(metric_value AS NUMERIC)), 2) AS mtd,
'MT' as unit
FROM
(
SELECT
date,
'Anode rejection' AS kpi,
shift,
COALESCE(acp_reject_a, '0') AS metric_value
FROM
semantic_prod.charging_details_ccpc_new
WHERE
LOWER(shift) = 'shift a'
UNION ALL
SELECT
date,
'Anode rejection' AS kpi,
shift,
COALESCE(acp_reject_b, '0') AS metric_value
FROM
semantic_prod.charging_details_ccpc_new
WHERE
LOWER(shift) = 'shift b'
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}'
class Day02:
QUERY_1 = """
select
'Day O2' as particulars,
'ppm' as unit,
sum(refinary_labdata_oxygen) 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 O2' as particulars,
'ppm' as unit,
sum(refinary_labdata_oxygen) 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;"""
GROUP BY
1;"""
class DayAs:
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:
""" TOTAL BREAKDOWN DETAILS """
......@@ -6178,7 +6319,7 @@ class SterliteCCPPQuery:
(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}'
where tbl1.date.date between '{day_start_date}' AND '{day_end_date}'
group by 1,2;
"""
QUERY_2 = """
......@@ -6196,7 +6337,7 @@ class SterliteCCPPQuery:
(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}'
where tbl1.date.date between '{month_start_date}' AND '{month_end_date}'
group by 1,2;
"""
......@@ -6282,7 +6423,7 @@ class SterliteCCPPQuery:
(select 'power' as parameters, 'KWH/MT' as unit, date(date) as date, power_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}'
WHERE tbl1.date.date BETWEEN '{day_start_date}' AND '{day_end_date}'
group by 1,2;
"""
......@@ -6301,7 +6442,7 @@ class SterliteCCPPQuery:
(select 'power' as parameters, 'KWH/MT' as unit, date(date) as date, power_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}'
WHERE tbl1.date.date BETWEEN '{month_start_date}' AND '{month_end_date}'
group by 1,2;
"""
......
......@@ -25,10 +25,15 @@ class CCPCReportTemplate:
"MTD",
],
"query": {
"Production":[
SterliteCCPCQuery.Production.QUERY_1,
SterliteCCPCQuery.Production.QUERY_2
],
"Lpg": [
SterliteCCPCQuery.Lpg.QUERY_1,
SterliteCCPCQuery.Lpg.QUERY_2
],
"BariumSulphateP":[
SterliteCCPCQuery.BariumSulphateP.QUERY_1,
SterliteCCPCQuery.BariumSulphateP.QUERY_2
......@@ -37,6 +42,10 @@ class CCPCReportTemplate:
SterliteCCPCQuery.Sodiumsilicate.QUERY_1,
SterliteCCPCQuery.Sodiumsilicate.QUERY_2
],
"Power":[
SterliteCCPCQuery.Power1.QUERY_1,
SterliteCCPCQuery.Power1.QUERY_2
],
"BLISTER": [
SterliteCCPCQuery.BLISTER.QUERY_1,
SterliteCCPCQuery.BLISTER.QUERY_2,
......@@ -109,6 +118,18 @@ class CCPCReportTemplate:
SterliteCCPCQuery.ANODEREJECTION.QUERY_1,
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_column": ["particulars", "unit", "on_date", "mtd",
......@@ -408,6 +429,8 @@ class CCPCReportTemplate:
"REASON FOR STOPAGE"
],
"query": {
"ActivityTime":[
SterliteCCPCQuery.ActivityTime.QUERY_1]
},
"data": [],
"data_column": [
......
......@@ -32,8 +32,8 @@ class CCPPReportTemplate:
SterliteCCPPQuery.Production.QUERY_2
],
"Lpg": [
# SterliteCCPPQuery.Lpg.QUERY_1,
# SterliteCCPPQuery.Lpg.QUERY_2,
SterliteCCPPQuery.Lpg.QUERY_1,
SterliteCCPPQuery.Lpg.QUERY_2,
],
"BariumSulphate": [
SterliteCCPPQuery.BariumSulphate.QUERY_1,
......@@ -45,8 +45,8 @@ class CCPPReportTemplate:
SterliteCCPPQuery.SodiumSilicate.QUERY_2,
],
"Power": [
# SterliteCCPPQuery.Power.QUERY_1,
# SterliteCCPPQuery.Power.QUERY_2,
SterliteCCPPQuery.Power.QUERY_1,
SterliteCCPPQuery.Power.QUERY_2,
],
"KanshakiBlister": [
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