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

UPDATED CCPP QUERIES and CCPC

parent e6c166f7
......@@ -4191,6 +4191,208 @@ class SterliteCCPCQuery:
CCPC report queries
"""
class Production:
QUERY_1 = """
select
'Production' as particulars,
'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.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
where
a.date BETWEEN '{day_start_date}' AND '{day_end_date}';
"""
QUERY_2 = """
select
'Production' as particulars,
'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.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
WHERE a.date BETWEEN '{month_start_date}' AND '{month_end_date}'
GROUP BY
1;
"""
class BariumSulphate:
QUERY_1 = """ SELECT
kpi as particulars,
'MT' as unit,
ROUND(SUM(CAST(metric_value AS NUMERIC)),2) AS on_date
FROM
(
SELECT
date,
'Blister' AS kpi,
shift,
COALESCE(blister_a, '0') AS metric_value
FROM
semantic_prod.charging_details_ccpc_new
WHERE
LOWER(shift) = 'shift a'
UNION ALL
SELECT
date,
'Blister' AS kpi,
shift,
COALESCE(blister_b, '0') AS metric_value
FROM
semantic_prod.charging_details_ccpc_new
WHERE
LOWER(shift) = 'shift b'
UNION ALL
SELECT
date,
'Blister' AS kpi,
shift,
COALESCE(blister_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}'
GROUP BY
1;
"""
QUERY_2 = """
SELECT
kpi as particulars,
'MT' as unit,
ROUND(SUM(CAST(metric_value AS NUMERIC)),2) AS mtd
FROM
(
SELECT
date,
'Blister' AS kpi,
shift,
COALESCE(blister_a, '0') AS metric_value
FROM
semantic_prod.charging_details_ccpc_new
WHERE
LOWER(shift) = 'shift a'
UNION ALL
SELECT
date,
'Blister' AS kpi,
shift,
COALESCE(blister_b, '0') AS metric_value
FROM
semantic_prod.charging_details_ccpc_new
WHERE
LOWER(shift) = 'shift b'
UNION ALL
SELECT
date,
'Blister' AS kpi,
shift,
COALESCE(blister_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
1;
"""
class Sodiumsilicate:
QUERY_1 = """
select tbl2.kpi as particulars, tbl2.unit, sum(sodium_silicate)/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
left join
(SELECT kpi, 'KG/MT' as unit, date(date) as date, SUM(CAST(metric_value AS NUMERIC)) AS sodium_silicate
FROM (
SELECT date, 'SODIUM SILICATE' AS kpi, shift, COALESCE(sodium_silicate_a, '0') AS metric_value
FROM semantic_prod.ccpc_actual_production_data
WHERE LOWER(shift) = 'shift a' and sodium_silicate_a != ''
UNION ALL
SELECT date, 'SODIUM SILICATE' AS kpi, shift, COALESCE(sodium_silicate_b, '0') AS metric_value
FROM semantic_prod.ccpc_actual_production_data
WHERE LOWER(shift) = 'shift b' and sodium_silicate_b != ''
UNION ALL
SELECT date, 'SODIUM SILICATE' AS kpi, shift, COALESCE(sodium_silicate_c, '0') AS metric_value
FROM semantic_prod.ccpc_actual_production_data
WHERE LOWER(shift) = 'shift c' and sodium_silicate_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(sodium_silicate)/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
left join
(SELECT kpi, 'KG/MT' as unit, date(date) as date, SUM(CAST(metric_value AS NUMERIC)) AS sodium_silicate
FROM (
SELECT date, 'SODIUM SILICATE' AS kpi, shift, COALESCE(sodium_silicate_a, '0') AS metric_value
FROM semantic_prod.ccpc_actual_production_data
WHERE LOWER(shift) = 'shift a' and sodium_silicate_a != ''
UNION ALL
SELECT date, 'SODIUM SILICATE' AS kpi, shift, COALESCE(sodium_silicate_b, '0') AS metric_value
FROM semantic_prod.ccpc_actual_production_data
WHERE LOWER(shift) = 'shift b' and sodium_silicate_b != ''
UNION ALL
SELECT date, 'SODIUM SILICATE' AS kpi, shift, COALESCE(sodium_silicate_c, '0') AS metric_value
FROM semantic_prod.ccpc_actual_production_data
WHERE LOWER(shift) = 'shift c' and sodium_silicate_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 BLISTER:
""" PARTICULARS """
QUERY_1 = """ SELECT
......@@ -5353,7 +5555,6 @@ class SterliteCCPCQuery:
WHERE
LOWER(shift) = 'shift c'
) foo WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
GROUP BY
1;"""
QUERY_2 = """SELECT
......@@ -5526,6 +5727,64 @@ class SterliteCCPCQuery:
semantic_prod.ccpc_shift_manpower;
"""
class MonthWiseData:
QUERY_1 = """
select TO_CHAR(TO_DATE(month::text, 'MM'),'Mon') as nos, 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) = 'ccpc' and DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
group by 1,kpi) foo group by 1;"""
class ProductionDetails1:
QUERY1 = """
select kpi, max(Shift_A) as a_shift, max(Shift_B) as b_shift, max(Shift_C) as ac_shift,
max(Shift_A) + max(Shift_B) + max(Shift_C) as total,
max(Prdn_A) as a_shift_prdn, max(Prdn_B) as b_shift_prdn, max(Prdn_C) as c_shift_prdn,
max(Prdn_A) + max(Prdn_B) + max(Prdn_C) as od_prodn
from (
select 'No of Anode' as kpi, date(tbl1.date) as date,
case when lower(shift)='shift a' then sum(total_anode_accepted_a) else 0 end as shift_A,
case when lower(shift)='shift b' then sum(total_anode_accepted_b) else 0 end as shift_B,
case when lower(shift)='shift c' then sum(total_anode_accepted_c) else 0 end as shift_C,
case when lower(shift)='shift a' then (sum(total_anode_accepted_a)*sum(anode_wt))/1000 else 0 end as Prdn_A,
case when lower(shift)='shift b' then (sum(total_anode_accepted_b)*sum(anode_wt))/1000 else 0 end as Prdn_B,
case when lower(shift)='shift c' then (sum(total_anode_accepted_c)*sum(anode_wt))/1000 else 0 end as Prdn_C
from
(select * from semantic_prod.ccpc_actual_production_data) tbl1
left join
(select date(date) as date, production_value as anode_wt from semantic_prod.ccpc_production_plan
where lower(trim(production_anode))='anode weighment') tbl2
on date(tbl1.date)=date(tbl2.date)
group by 1,2,shift) foo where DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
group by 1"""
class ProductionDetails2:
QUERY_1 = """
select kpi, max(Shift_A) as a_shift, max(Shift_B) as b_shift, max(Shift_C) as c_shift,
max(Shift_A) + max(Shift_B) + max(Shift_C) as total,
max(Prdn_A) as a_shift_prdn, max(Prdn_B) as b_shift_prdn, max(Prdn_C) as c_shift_prdn,
max(Prdn_A) + max(Prdn_B) + max(Prdn_C) as od_prodn
from (
select 'Revert generation in Shift' as kpi, date(tbl1.date) as date,
case when lower(shift)='shift a' then sum(total_anode_rejected_a) else 0 end as shift_A,
case when lower(shift)='shift b' then sum(total_anode_rejected_b) else 0 end as shift_B,
case when lower(shift)='shift c' then sum(total_anode_rejected_c) else 0 end as shift_C,
case when lower(shift)='shift a' then (sum(total_anode_rejected_a)*sum(anode_wt))/1000 else 0 end as Prdn_A,
case when lower(shift)='shift b' then (sum(total_anode_rejected_b)*sum(anode_wt))/1000 else 0 end as Prdn_B,
case when lower(shift)='shift c' then (sum(total_anode_rejected_c)*sum(anode_wt))/1000 else 0 end as Prdn_C
from
(select * from semantic_prod.ccpc_actual_production_data) tbl1
left join
(select date(date) as date, production_value as anode_wt from semantic_prod.ccpc_production_plan
where lower(trim(production_anode))='anode weighment') tbl2
on date(tbl1.date)=date(tbl2.date)
group by 1,2,shift) foo where DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
group by 1;
"""
class ChargingDetails:
QUERY_1 = """
select
......@@ -5561,45 +5820,110 @@ class SterliteCCPCQuery:
total DESC;
"""
class BariumSulphate:
class BariumSulphateP:
QUERY_1 = """
select tbl2.kpi as particulars, tbl2.unit, sum(barium_sulphate)/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
left join
(SELECT kpi, '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.ccpc_actual_production_data
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.ccpc_actual_production_data
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.ccpc_actual_production_data
WHERE LOWER(shift) = 'shift c' and barium_sulphate_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(barium_sulphate)/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
left join
(SELECT kpi, '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.ccpc_actual_production_data
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.ccpc_actual_production_data
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.ccpc_actual_production_data
WHERE LOWER(shift) = 'shift c' and barium_sulphate_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 SodiumSulphate:
QUERY_1 = """SELECT
kpi AS consumption_items,
'KG/MT' as unit,
ROUND(SUM(CAST(metric_value AS NUMERIC)), 2) AS on_date
SUM(CAST(metric_value AS NUMERIC)) AS on_date
FROM
(
SELECT
date,
'BARIUM SULPHATE' AS kpi,
'SODIUM SILICATE' AS kpi,
shift,
COALESCE(barium_sulphate_a, '0') AS metric_value
COALESCE(sodium_silicate_a, '0') AS metric_value
FROM
semantic_prod.ccpc_actual_production_data
WHERE
LOWER(shift) = 'shift a'
and barium_sulphate_a != ''
and sodium_silicate_a != ''
UNION ALL
SELECT
date,
'BARIUM SULPHATE' AS kpi,
'SODIUM SILICATE' AS kpi,
shift,
COALESCE(barium_sulphate_b, '0') AS metric_value
COALESCE(sodium_silicate_b, '0') AS metric_value
FROM
semantic_prod.ccpc_actual_production_data
WHERE
LOWER(shift) = 'shift b'
and barium_sulphate_b != ''
and sodium_silicate_b != ''
UNION ALL
SELECT
date,
'BARIUM SULPHATE' AS kpi,
'SODIUM SILICATE' AS kpi,
shift,
COALESCE(barium_sulphate_c, '0') AS metric_value
COALESCE(sodium_silicate_c, '0') AS metric_value
FROM
semantic_prod.ccpc_actual_production_data
WHERE
LOWER(shift) = 'shift c'
and barium_sulphate_c != ''
and sodium_silicate_c != ''
) foo
WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
GROUP BY
......@@ -5608,114 +5932,24 @@ class SterliteCCPCQuery:
QUERY_2 = """SELECT
kpi AS consumption_items,
'KG/MT' as unit,
ROUND(SUM(CAST(metric_value AS NUMERIC)), 2) AS mtd
SUM(CAST(metric_value AS NUMERIC)) AS mtd
FROM
(
SELECT
date,
'BARIUM SULPHATE' AS kpi,
'SODIUM SILICATE' AS kpi,
shift,
COALESCE(barium_sulphate_a, '0') AS metric_value
COALESCE(sodium_silicate_a, '0') AS metric_value
FROM
semantic_prod.ccpc_actual_production_data
WHERE
LOWER(shift) = 'shift a'
and barium_sulphate_a != ''
and sodium_silicate_a != ''
UNION ALL
SELECT
date,
'BARIUM SULPHATE' AS kpi,
shift,
COALESCE(barium_sulphate_b, '0') AS metric_value
FROM
semantic_prod.ccpc_actual_production_data
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.ccpc_actual_production_data
WHERE
LOWER(shift) = 'shift c'
and barium_sulphate_c != ''
) foo
WHERE DATE BETWEEN '{month_start_date}' AND '{month_end_date}'
GROUP BY
1;
"""
class SodiumSulphate:
QUERY_1 = """SELECT
kpi AS consumption_items,
'KG/MT' as unit,
SUM(CAST(metric_value AS NUMERIC)) AS on_date
FROM
(
SELECT
date,
'SODIUM SILICATE' AS kpi,
shift,
COALESCE(sodium_silicate_a, '0') AS metric_value
FROM
semantic_prod.ccpc_actual_production_data
WHERE
LOWER(shift) = 'shift a'
and sodium_silicate_a != ''
UNION ALL
SELECT
date,
'SODIUM SILICATE' AS kpi,
shift,
COALESCE(sodium_silicate_b, '0') AS metric_value
FROM
semantic_prod.ccpc_actual_production_data
WHERE
LOWER(shift) = 'shift b'
and sodium_silicate_b != ''
UNION ALL
SELECT
date,
'SODIUM SILICATE' AS kpi,
shift,
COALESCE(sodium_silicate_c, '0') AS metric_value
FROM
semantic_prod.ccpc_actual_production_data
WHERE
LOWER(shift) = 'shift c'
and sodium_silicate_c != ''
) foo
WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
GROUP BY
1;
"""
QUERY_2 = """SELECT
kpi AS consumption_items,
'KG/MT' as unit,
SUM(CAST(metric_value AS NUMERIC)) AS mtd
FROM
(
SELECT
date,
'SODIUM SILICATE' AS kpi,
shift,
COALESCE(sodium_silicate_a, '0') AS metric_value
FROM
semantic_prod.ccpc_actual_production_data
WHERE
LOWER(shift) = 'shift a'
and sodium_silicate_a != ''
UNION ALL
SELECT
date,
'SODIUM SILICATE' AS kpi,
'SODIUM SILICATE' AS kpi,
shift,
COALESCE(sodium_silicate_b, '0') AS metric_value
FROM
......@@ -5930,7 +6164,7 @@ class SterliteCCPPQuery:
class Lpg:
QUERY_1 = """
select tbl2.kpi, tbl2.unit, sum(lpg_consumption_total/production) as metric_value from
select tbl2.kpi as particulars, tbl2.unit, sum(lpg_consumption_total/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
......@@ -5944,11 +6178,11 @@ 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 a.date between '{day_start_date}' AND '{day_end_date}'
group by 1,2;
"""
QUERY_2 = """
select tbl2.kpi, tbl2.unit, sum(lpg_consumption_total/production) as metric_value from
select tbl2.kpi as particulars, tbl2.unit, sum(lpg_consumption_total/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
......@@ -5962,118 +6196,114 @@ 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 a.date between '{month_start_date}' AND '{month_end_date}'
group by 1,2;
"""
class SodiumSilicate:
QUERY_1 = """
SELECT
kpi as particulars,
'KG/MT' as unit,
SUM(CAST(metric_value AS NUMERIC)) AS on_date
FROM
(
SELECT
date,
'SODIUM SILICATE' AS kpi,
shift,
COALESCE(sodium_silicate_a, '0') AS metric_value
FROM
semantic_prod.actual_production_data_shiftwise_ccpp
WHERE
LOWER(shift) = 'shift a'
and sodium_silicate_a != ''
select tbl2.parameters as particulars, tbl2.unit, sum(sodium_silicate)/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.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 sodium_silicate
FROM (
SELECT date, 'SODIUM SILICATE' AS kpi, shift, COALESCE(sodium_silicate_a, '0') AS metric_value
FROM semantic_prod.ccpp_actual_production_new
WHERE LOWER(shift) = 'shift a' and sodium_silicate_a != ''
UNION ALL
SELECT
date,
'SODIUM SILICATE' AS kpi,
shift,
COALESCE(sodium_silicate_b, '0') AS metric_value
FROM
semantic_prod.actual_production_data_shiftwise_ccpp
WHERE
LOWER(shift) = 'shift b'
and sodium_silicate_b != ''
SELECT date, 'SODIUM SILICATE' AS kpi, shift, COALESCE(sodium_silicate_b, '0') AS metric_value
FROM semantic_prod.ccpp_actual_production_new
WHERE LOWER(shift) = 'shift b' and sodium_silicate_b != ''
UNION ALL
SELECT
date,
'SODIUM SILICATE' AS kpi,
shift,
COALESCE(sodium_silicate_c, '0') AS metric_value
FROM
semantic_prod.actual_production_data_shiftwise_ccpp
WHERE
LOWER(shift) = 'shift c'
and sodium_silicate_c != ''
) foo WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
GROUP BY
1;
SELECT date, 'SODIUM SILICATE' AS kpi, shift, COALESCE(sodium_silicate_c, '0') AS metric_value
FROM semantic_prod.ccpp_actual_production_new
WHERE LOWER(shift) = 'shift c' and sodium_silicate_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
kpi as particulars,
'KG/MT' as unit,
SUM(CAST(metric_value AS NUMERIC)) AS mtd
FROM
(
SELECT
date,
'SODIUM SILICATE' AS kpi,
shift,
COALESCE(sodium_silicate_a, '0') AS metric_value
FROM
semantic_prod.actual_production_data_shiftwise_ccpp
WHERE
LOWER(shift) = 'shift a'
and sodium_silicate_a != ''
select tbl2.parameters as particulars, tbl2.unit, sum(sodium_silicate)/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.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 sodium_silicate
FROM (
SELECT date, 'SODIUM SILICATE' AS kpi, shift, COALESCE(sodium_silicate_a, '0') AS metric_value
FROM semantic_prod.ccpp_actual_production_new
WHERE LOWER(shift) = 'shift a' and sodium_silicate_a != ''
UNION ALL
SELECT
date,
'SODIUM SILICATE' AS kpi,
shift,
COALESCE(sodium_silicate_b, '0') AS metric_value
FROM
semantic_prod.actual_production_data_shiftwise_ccpp
WHERE
LOWER(shift) = 'shift b'
and sodium_silicate_b != ''
SELECT date, 'SODIUM SILICATE' AS kpi, shift, COALESCE(sodium_silicate_b, '0') AS metric_value
FROM semantic_prod.ccpp_actual_production_new
WHERE LOWER(shift) = 'shift b' and sodium_silicate_b != ''
UNION ALL
SELECT
date,
'SODIUM SILICATE' AS kpi,
shift,
COALESCE(sodium_silicate_c, '0') AS metric_value
FROM
semantic_prod.actual_production_data_shiftwise_ccpp
WHERE
LOWER(shift) = 'shift c'
and sodium_silicate_c != ''
) foo
WHERE DATE BETWEEN '{month_start_date}' AND '{month_end_date}'
GROUP BY
1;
SELECT date, 'SODIUM SILICATE' AS kpi, shift, COALESCE(sodium_silicate_c, '0') AS metric_value
FROM semantic_prod.ccpp_actual_production_new
WHERE LOWER(shift) = 'shift c' and sodium_silicate_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 Power:
QUERY_1 = """
select
'power' as particulars,
'KWH/MT' as unit,
power_consumption_total as on_date
from
semantic_prod.ccpp_actual_production_2
WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}';
select tbl2.particulars , tbl2.unit, sum(power_consumption_total)/sum(production) as on_date from
(select 'Production' as particulars, '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 '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}'
group by 1,2;
"""
QUERY_2 = """
select
'power' as particulars,
'KWH/MT' as unit,
power_consumption_total as mtd
from
semantic_prod.ccpp_actual_production_2
WHERE DATE BETWEEN '{month_start_date}' AND '{month_end_date}';
select tbl2.particulars, tbl2.unit, sum(power_consumption_total)/sum(production) as mtd from
(select 'Production' as particulars, '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 '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}'
group by 1,2;
"""
class KanshakiBlister:
......@@ -6593,8 +6823,8 @@ class SterliteCCPPQuery:
class TotalBreakdownDetails:
QUERY_1 = """
select
type_of_breakdown as kpi,
sum(breakdown_duration_hours * 60) as breakdown_duration_mins
type_of_breakdown as total_breakdown,
sum(breakdown_duration_hours * 60) as "on_date"
from
semantic_prod.ccpp_downtime_kpi_view
WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
......@@ -6605,8 +6835,8 @@ class SterliteCCPPQuery:
class TotalBreakdownDetails1:
QUERY_1 = """
select
'Total(Mins)' as kpi,
sum(breakdown_duration_hours * 60) as breakdown_duration_mins
'Total(Mins)' as total_breakdown,
sum(breakdown_duration_hours * 60) as "on_date"
from
semantic_prod.ccpp_downtime_kpi_view
WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
......@@ -6617,10 +6847,10 @@ class SterliteCCPPQuery:
class ChargingDetails:
QUERY_1 = """
select
kpi,
shift_a,
shift_b,
shift_c,
kpi as charging_detail,
shift_a as a_shift,
shift_b as b_shift,
shift_c as c_shift,
total
from
semantic_prod.ccpp_custom_rprt_charging_details
......@@ -6630,7 +6860,7 @@ class SterliteCCPPQuery:
class MonthwiseProductionDetails:
QUERY_1 = """
select TO_CHAR(TO_DATE(month::text, 'MM'),'Mon') as month, max(target) as target, max(production) as production from
select TO_CHAR(TO_DATE(month::text, 'MM'),'Mon') as nos, 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
......@@ -6644,9 +6874,9 @@ class SterliteCCPPQuery:
class Paticulars:
QUERY_1 = """
select
select_ccpp as kpi,
select_ccpp as particulars,
uom_ccpp as uom,
avg(value_ccpp) as metric_value
avg(value_ccpp) as ftd
from
semantic_prod.ccpp_ctp_new
where
......@@ -6661,23 +6891,46 @@ class SterliteCCPPQuery:
class LugThickness:
QUERY_1 = """
select
select_ccpp as kpi,
select_ccpp as particulars,
uom_ccpp as uom,
avg(value_ccpp) as metric_value
avg(value_ccpp) as ftd
from
semantic_prod.ccpp_ctq_new
where
lower(select_ccpp) in (
'anode dimension- body thickness ',
'anode dimension- lug thickness '
)
) and
DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
group by
1,
2;
"""
class ElectricalVapor:
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 BETWEEN '{day_start_date}' AND '{day_end_date}'
"""
QUERY_2 = """
select kpi, shift, water_temp,water_level, water_valve_condition, status from(
select date, electrical_a as kpi,shift, coalesce(water_temp_a,'0') as water_temp, coalesce(water_level_a,'0') as water_level,
coalesce(water_valve_condition_a,'0') as water_valve_condition,status_a as status from
......@@ -6707,43 +6960,39 @@ class SterliteCCPPQuery:
class ConsumptionItem1:
QUERY_1 = """
SELECT kpi, SUM(CAST(metric_value AS NUMERIC)) AS metric_value, 'KG/MT' as unit
SELECT kpi as consumption_item, 'KG/MT' as unit, SUM(CAST(metric_value AS NUMERIC)) AS on_date
FROM (
SELECT date, 'BARIUM SULPHATE' AS kpi, shift, COALESCE(barium_sulphate_a, '0') AS metric_value
FROM semantic_prod.actual_production_data_shiftwise_ccpp
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.actual_production_data_shiftwise_ccpp
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.actual_production_data_shiftwise_ccpp
FROM semantic_prod.ccpp_actual_production_new
WHERE LOWER(shift) = 'shift c' and barium_sulphate_c != ''
) foo WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
GROUP BY 1 ;
"""
QUERY_2 = """
SELECT kpi, SUM(CAST(metric_value AS NUMERIC)) AS metric_value, 'KG/MT' as unit
SELECT kpi as consumption_item, 'KG/MT' as unit, SUM(CAST(metric_value AS NUMERIC)) AS mtd
FROM (
SELECT date, 'BARIUM SULPHATE' AS kpi, shift, COALESCE(barium_sulphate_a, '0') AS metric_value
FROM semantic_prod.actual_production_data_shiftwise_ccpp
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.actual_production_data_shiftwise_ccpp
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.actual_production_data_shiftwise_ccpp
FROM semantic_prod.ccpp_actual_production_new
WHERE LOWER(shift) = 'shift c' and barium_sulphate_c != ''
) foo WHERE DATE BETWEEN '{month_start_date}' AND '{month_end_date}'
GROUP BY 1 ;
......@@ -6751,44 +7000,36 @@ class SterliteCCPPQuery:
class ConsumptionItem2:
QUERY_1 = """
SELECT kpi, SUM(CAST(metric_value AS NUMERIC)) AS metric_value, 'KG/MT' as unit
SELECT kpi as consumption_item, 'KG/MT' as unit, SUM(CAST(metric_value AS NUMERIC)) AS on_date
FROM (
SELECT date, 'SODIUM SILICATE' AS kpi, shift, COALESCE(sodium_silicate_a, '0') AS metric_value
FROM semantic_prod.actual_production_data_shiftwise_ccpp
FROM semantic_prod.ccpp_actual_production_new
WHERE LOWER(shift) = 'shift a' and sodium_silicate_a != ''
UNION ALL
SELECT date, 'SODIUM SILICATE' AS kpi, shift, COALESCE(sodium_silicate_b, '0') AS metric_value
FROM semantic_prod.actual_production_data_shiftwise_ccpp
FROM semantic_prod.ccpp_actual_production_new
WHERE LOWER(shift) = 'shift b' and sodium_silicate_b != ''
UNION ALL
SELECT date, 'SODIUM SILICATE' AS kpi, shift, COALESCE(sodium_silicate_c, '0') AS metric_value
FROM semantic_prod.actual_production_data_shiftwise_ccpp
FROM semantic_prod.ccpp_actual_production_new
WHERE LOWER(shift) = 'shift c' and sodium_silicate_c != ''
) foo
WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
GROUP BY 1 ;
"""
QUERY_2 = """
SELECT kpi, SUM(CAST(metric_value AS NUMERIC)) AS metric_value, 'KG/MT' as unit
SELECT kpi as consumption_item, 'KG/MT' as unit, SUM(CAST(metric_value AS NUMERIC)) AS mtd
FROM (
SELECT date, 'SODIUM SILICATE' AS kpi, shift, COALESCE(sodium_silicate_a, '0') AS metric_value
FROM semantic_prod.actual_production_data_shiftwise_ccpp
FROM semantic_prod.ccpp_actual_production_new
WHERE LOWER(shift) = 'shift a' and sodium_silicate_a != ''
UNION ALL
SELECT date, 'SODIUM SILICATE' AS kpi, shift, COALESCE(sodium_silicate_b, '0') AS metric_value
FROM semantic_prod.actual_production_data_shiftwise_ccpp
FROM semantic_prod.ccpp_actual_production_new
WHERE LOWER(shift) = 'shift b' and sodium_silicate_b != ''
UNION ALL
SELECT date, 'SODIUM SILICATE' AS kpi, shift, COALESCE(sodium_silicate_c, '0') AS metric_value
FROM semantic_prod.actual_production_data_shiftwise_ccpp
FROM semantic_prod.ccpp_actual_production_new
WHERE LOWER(shift) = 'shift c' and sodium_silicate_c != ''
) foo
WHERE DATE BETWEEN '{month_start_date}' AND '{month_end_date}'
......@@ -6798,50 +7039,27 @@ class SterliteCCPPQuery:
class ConsumptionItem3:
QUERY_1 = """
select
'power' as kpi,
'power' as consumption_item,
'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 consumption_item,
'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}'
"""
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 BETWEEN '{day_start_date}' AND '{day_end_date}'
"""
class Production:
QUERY_1 = """
select
'Production' as parameters,
'Production' as particulars,
'MT' as unit,
(sum(anode_wt) * sum(total_anode)) / 1000 as on_date
from
......@@ -6866,7 +7084,7 @@ class SterliteCCPPQuery:
"""
QUERY_2 = """
select
'Production' as parameters,
'Production' as particulars,
'MT' as unit,
(sum(anode_wt) * sum(total_anode)) / 1000 as mtd
from
......@@ -6892,7 +7110,7 @@ class SterliteCCPPQuery:
class BariumSulphate:
QUERY_1 = """
select tbl2.parameters, tbl2.unit, sum(barium_sulphate/production) as on_date from
select tbl2.parameters as particulars, 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
......@@ -6919,13 +7137,13 @@ class SterliteCCPPQuery:
)foo GROUP BY 1,2,3
) tbl2
on tbl1.date=tbl2.date
tbl1.date between '{day_start_date}' and '{day_end_date}'
where 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 tbl2.parameters as particulars, 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
......@@ -6952,7 +7170,121 @@ class SterliteCCPPQuery:
)foo GROUP BY 1,2,3
) tbl2
on tbl1.date=tbl2.date
tbl1.date between '{month_start_date}' and '{month_end_date}'
where tbl1.date between '{month_start_date}' and '{month_end_date}'
group by 1,2
;
"""
class AnodesBookingPending:
QUERY_1 = """
select 'Anode Booking Pending' as particulars,
'MT' as unit, sum(unbooked_anode) as on_date
from semantic_prod.ccpp_daily_production_3
WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}' ;"""
QUERY_2 = """
select 'Anode Booking Pending' as particulars, 'MT' as unit, sum(unbooked_anode) as mtd from semantic_prod.ccpp_daily_production_3
WHERE DATE BETWEEN '{month_start_date}' AND '{month_end_date}';
"""
class AnodeInCCPPYard:
QUERY_1 = """
select
'Anode in CCPP Yard' as particulars,
'MT' as unit,
sum(booked_anode) as on_date
from
semantic_prod.ccpp_daily_production_3
WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}';"""
QUERY_2 = """
select
'Anode in CCPP Yard' as particulars,
'MT' as unit,
sum(booked_anode) as mtd
from
semantic_prod.ccpp_daily_production_3
WHERE DATE BETWEEN '{month_start_date}' AND '{month_end_date}'
"""
class InternalAnodeRejection:
QUERY_1 = """
SELECT kpi as internal_anode_rejection, SUM(CAST(metric_value AS NUMERIC)) AS ccpp_anode_rejection
FROM (
SELECT date, 'Shift A' AS kpi, COALESCE(values_shift_a_ccpp, '0') AS metric_value
FROM semantic_prod.anode_rejection_ccpp
UNION ALL
SELECT date, 'Shift B' AS kpi, COALESCE(values_shift_b_ccpp, '0') AS metric_value
FROM semantic_prod.anode_rejection_ccpp
UNION ALL
SELECT date, 'Shift C' AS kpi, COALESCE(values_shift_c_ccpp, '0') AS metric_value
FROM semantic_prod.anode_rejection_ccpp
UNION ALL
SELECT date, 'Total' AS kpi, COALESCE(values_shift_a_ccpp, '0') + COALESCE(values_shift_b_ccpp, '0') + COALESCE(values_shift_c_ccpp, '0') AS metric_value
FROM semantic_prod.anode_rejection_ccpp
) foo
where Date(date) BETWEEN '{day_start_date}' AND '{day_end_date}'
GROUP BY 1
ORDER by 1;
"""
class ProductionDetails1:
QUERY_1 = """
select kpi as production_detail, max(Shift_A) as a_shift, max(Shift_B) as b_shift, max(Shift_C) as c_shift,
max(Shift_A) + max(Shift_B) + max(Shift_C) as total_anode,
max(Prdn_A) as a_shift_production, max(Prdn_B) as b_shift_production, max(Prdn_C) as c_shift_production,
max(Prdn_A) + max(Prdn_B) + max(Prdn_C) as od_production
from (
select 'No of Anode' as kpi, date(tbl1.date) as date,
case when lower(shift)='shift a' then sum(total_anode_accepted_a) else 0 end as shift_A,
case when lower(shift)='shift b' then sum(total_anode_accepted_b) else 0 end as shift_B,
case when lower(shift)='shift c' then sum(total_anode_accepted_c) else 0 end as shift_C,
case when lower(shift)='shift a' then (sum(total_anode_accepted_a)*sum(anode_wt))/1000 else 0 end as Prdn_A,
case when lower(shift)='shift b' then (sum(total_anode_accepted_b)*sum(anode_wt))/1000 else 0 end as Prdn_B,
case when lower(shift)='shift c' then (sum(total_anode_accepted_c)*sum(anode_wt))/1000 else 0 end as Prdn_C
from
(select * from semantic_prod.ccpp_actual_production_new) tbl1
left join
(select date(date) as date, production_value as anode_wt from semantic_prod.ccpp_production_plan
where lower(trim(production_anode))='anode weighment') tbl2
on date(tbl1.date)=date(tbl2.date)
group by 1,2,shift) foo where Date(date) BETWEEN '{day_start_date}' AND '{day_end_date}'
group by 1;
"""
class ProductionDetails2:
QUERY_1 = """
select kpi as production_detail, max(Shift_A) as a_shift, max(Shift_B) as b_shift, max(Shift_C) as c_shift,
max(Shift_A) + max(Shift_B) + max(Shift_C) as total_anode,
max(Prdn_A) as a_shift_production, max(Prdn_B) as b_shift_production, max(Prdn_C) as c_shift_production,
max(Prdn_A) + max(Prdn_B) + max(Prdn_C) as od_production
from (
select 'Revert generation in Shift' as kpi, date(tbl1.date) as date,
case when lower(shift)='shift a' then sum(total_anode_rejected_a) else 0 end as shift_A,
case when lower(shift)='shift b' then sum(total_anode_rejected_b) else 0 end as shift_B,
case when lower(shift)='shift c' then sum(total_anode_rejected_c) else 0 end as shift_C,
case when lower(shift)='shift a' then (sum(total_anode_rejected_a)*sum(anode_wt))/1000 else 0 end as Prdn_A,
case when lower(shift)='shift b' then (sum(total_anode_rejected_b)*sum(anode_wt))/1000 else 0 end as Prdn_B,
case when lower(shift)='shift c' then (sum(total_anode_rejected_c)*sum(anode_wt))/1000 else 0 end as Prdn_C
from
(select * from semantic_prod.ccpp_actual_production_new) tbl1
left join
(select date(date) as date, production_value as anode_wt from semantic_prod.ccpp_production_plan
where lower(trim(production_anode))='anode weighment') tbl2
on date(tbl1.date)=date(tbl2.date)
group by 1,2,shift) foo where Date(date) BETWEEN '{day_start_date}' AND '{day_end_date}'
group by 1;
"""
class ActivityTime:
QUERY_1 = """
select
from_time as start_tm,
to_time as end_tm,
loss_in_minutes as total_tm,
stoppage_details as reason_for_stopage
from
semantic_prod.ccpp_plant_stoppage
where
date(date) BETWEEN '{day_start_date}' AND '{day_end_date}';
"""
......@@ -4,6 +4,7 @@ import pandas as pd
from datetime import datetime
from scripts.constants import ReportType, CommonConstants, PostgresConstant
from scripts.template.ccpc_report_template import CCPCReportTemplate
from scripts.template.ccpp_report_template import CCPPReportTemplate
from scripts.template.refinery_report_template import SterliteRefineryTemplate
from scripts.template.acp_report_template import ACPReportTemplate
from scripts.core.logging.application_logging import logger
......@@ -631,7 +632,7 @@ class CustomReportHandler:
logger.info(f"date filter: {each_date_range}")
report_template = copy.deepcopy(
ACPReportTemplate.REPORT_TEMPLATE
CCPPReportTemplate.CCPP_REPORT_TEMPLATE
)
start_col = CommonConstants.START_COLUMN
start_row = CommonConstants.START_ROW
......@@ -658,9 +659,9 @@ class CustomReportHandler:
input_json=each_blocks, writer=writer,
workbook=workbook, sheet_name=sheet_name,
start_col=start_col, start_row=start_row,
header_merge_format=ACPReportTemplate.COLUMN_HEADER_FORMAT,
column_merge_format=ACPReportTemplate.COLUMN_HEADER_FORMAT,
blank_merge_format=ACPReportTemplate.BLANK_COLUMN_HEADER_FORMAT
header_merge_format=CCPPReportTemplate.COLUMN_HEADER_FORMAT,
column_merge_format=CCPPReportTemplate.COLUMN_HEADER_FORMAT,
blank_merge_format=CCPPReportTemplate.BLANK_COLUMN_HEADER_FORMAT
)
if total_column < shape[1]:
......
......@@ -25,6 +25,18 @@ class CCPCReportTemplate:
"MTD",
],
"query": {
"Production":[
SterliteCCPCQuery.Production.QUERY_1,
SterliteCCPCQuery.Production.QUERY_2
],
"BariumSulphateP":[
SterliteCCPCQuery.BariumSulphateP.QUERY_1,
SterliteCCPCQuery.BariumSulphateP.QUERY_2
],
"Sodiumsilicate":[
SterliteCCPCQuery.Sodiumsilicate.QUERY_1,
SterliteCCPCQuery.Sodiumsilicate.QUERY_2
],
"BLISTER": [
SterliteCCPCQuery.BLISTER.QUERY_1,
SterliteCCPCQuery.BLISTER.QUERY_2,
......@@ -295,7 +307,11 @@ class CCPCReportTemplate:
},
"MONTHWISE PRODUCTION DETAILS (MT)": {
"columns": ["NOS", "TARGET", "PRODUCTION"],
"query": {},
"query": {
"MonthWiseData":[
SterliteCCPCQuery.MonthWiseData.QUERY_1
]
},
"data": [],
"data_column": ["nos", "target", "production"],
"addition": {
......@@ -317,11 +333,17 @@ class CCPCReportTemplate:
"OD PRODN (MT) ="
],
"query": {
"ProductionDetails1":[
SterliteCCPCQuery.ProductionDetails1.QUERY1
],
"ProductionDetails2": [
SterliteCCPCQuery.ProductionDetails2.QUERY_1
]
},
"data": [],
"data_column": [
"production details-no. of anodes",
"kpi",
"a_shift",
"b_shift",
"c_shift",
......
......@@ -2,15 +2,17 @@ from scripts.constants import PostgresConstant
from scripts.core.db.postgres.custom_report_query import SterliteCCPPQuery
class CCPCReportTemplate:
CCPC_REPORT_TEMPLATE = [
class CCPPReportTemplate:
CCPP_REPORT_TEMPLATE = [
{
"BLANK0": {
"columns": [
None
],
"data": [],
"query": {},
"query": {
},
"data_column": [
None
]
......@@ -24,7 +26,85 @@ class CCPCReportTemplate:
"ON DATE",
"MTD",
],
"query": {},
"query": {
"Production": [
SterliteCCPPQuery.Production.QUERY_1,
SterliteCCPPQuery.Production.QUERY_2
],
"Lpg": [
# SterliteCCPPQuery.Lpg.QUERY_1,
# SterliteCCPPQuery.Lpg.QUERY_2,
],
"BariumSulphate": [
SterliteCCPPQuery.BariumSulphate.QUERY_1,
SterliteCCPPQuery.BariumSulphate.QUERY_2
],
"SodiumSilicate": [
SterliteCCPPQuery.SodiumSilicate.QUERY_1,
SterliteCCPPQuery.SodiumSilicate.QUERY_2,
],
"Power": [
# SterliteCCPPQuery.Power.QUERY_1,
# SterliteCCPPQuery.Power.QUERY_2,
],
"KanshakiBlister": [
SterliteCCPPQuery.KanshakiBlister.QUERY_1,
SterliteCCPPQuery.KanshakiBlister.QUERY_2,
],
"RejectedCoil": [
SterliteCCPPQuery.RejectedCoil.QUERY_1,
SterliteCCPPQuery.RejectedCoil.QUERY_2,
],
"MasterAlloy": [
SterliteCCPPQuery.MasterAlloy.QUERY_1,
SterliteCCPPQuery.MasterAlloy.QUERY_2,
],
"CssBlister": [
SterliteCCPPQuery.CssBlister.QUERY_1,
SterliteCCPPQuery.CssBlister.QUERY_2,
],
"InternalRejectionAnode": [
SterliteCCPPQuery.InternalRejectionAnode.QUERY_1,
SterliteCCPPQuery.InternalRejectionAnode.QUERY_2,
],
"RefinerySpentAnode": [
SterliteCCPPQuery.RefinerySpentAnode.QUERY_1,
SterliteCCPPQuery.RefinerySpentAnode.QUERY_2,
],
"SapProduction": [
SterliteCCPPQuery.SapProduction.QUERY_1,
SterliteCCPPQuery.SapProduction.QUERY_2,
],
"Dingot": [
SterliteCCPPQuery.Dingot.QUERY_1,
SterliteCCPPQuery.Dingot.QUERY_2,
],
"KcmAnode": [
SterliteCCPPQuery.KcmAnode.QUERY_1,
SterliteCCPPQuery.KcmAnode.QUERY_2,
],
"CuLumps": [
SterliteCCPPQuery.CuLumps.QUERY_1,
SterliteCCPPQuery.CuLumps.QUERY_2,
],
"AcpRejectAnode": [
SterliteCCPPQuery.AcpRejectAnode.QUERY_1,
SterliteCCPPQuery.AcpRejectAnode.QUERY_2,
],
"ChargingVariation": [
SterliteCCPPQuery.ChargingVariation.QUERY_1,
SterliteCCPPQuery.ChargingVariation.QUERY_2,
],
"AnodesBookingPending": [
SterliteCCPPQuery.AnodesBookingPending.QUERY_1,
SterliteCCPPQuery.AnodesBookingPending.QUERY_2
],
"AnodeInCCPPYard": [
SterliteCCPPQuery.AnodeInCCPPYard.QUERY_1,
SterliteCCPPQuery.AnodeInCCPPYard.QUERY_2
]
},
"data": [],
"data_column": ["particulars", "unit", "on_date", "mtd",
],
......@@ -57,12 +137,13 @@ class CCPCReportTemplate:
]
},
"TOTAL BREAKDOWN DETAILS": {
"columns": ["TEMP", "ON DATE"],
"columns": ["TOTAL BREAKDOWN DETAILS(MINS)", "ON DATE"],
"query": {
"TotalBreakdownDetails": [SterliteCCPPQuery.TotalBreakdownDetails.QUERY_1],
"TotalBreakdownDetails1": [SterliteCCPPQuery.TotalBreakdownDetails1.QUERY_1]
},
"data": [],
"data_column": ["temp", "on_date"],
"data_column": ["total_breakdown", "on_date"],
},
"BLANK2": {
"columns": [
......@@ -75,13 +156,14 @@ class CCPCReportTemplate:
]
},
"MONTH WISE PRODUCTION": {
"columns": ["POSITION", "SHIFT", "AVG-TEMP"],
"columns": ["NOS", "SHIFT", "PRODUCTION"],
"query": {
"MonthwiseProductionDetails": [SterliteCCPPQuery.MonthwiseProductionDetails.QUERY_1]
},
"data": [],
"data_column": ["position", "shift", "avg-temp"],
"data_column": ["nos", "target", "production"],
"addition": {
"merge_header": "Furnace Shell Temp DCS - Data to be fetched shiftwise",
"merge_header": "Monthwise Production details (MT)",
}
},
......@@ -90,27 +172,23 @@ class CCPCReportTemplate:
{
"CHARGING DETAILS": {
"columns": [
"DCS - DATA TO BE FETCHED SHIFTWISE",
"",
"6AM",
"7AM",
"8AM",
"1PM"
"CHARGING_DETAIL",
"A-SHIFT",
"B-SHIFT",
"C-SHIFT",
"TOTAL"
],
"query": {
"ChargingDetails": [SterliteCCPPQuery.ChargingDetails.QUERY_1]
},
"data": [],
"data_column": [
"dcs_data_to_be_fetched_shiftwise",
"",
"6am",
"7am",
"8am",
"1pm"
],
"addition": {
"merge_header": "SHIFT-A",
}
"charging_detail",
"a_shift",
"b_shift",
"c_shift",
"total"
]
},
"BLANK0": {
"columns": [
......@@ -124,27 +202,19 @@ class CCPCReportTemplate:
},
"INTERNAL ANODE REJECTION": {
"columns": [
"DCS - DATA TO BE FETCHED SHIFTWISE",
"",
"6AM",
"7AM",
"8AM",
"1PM"
"INTERNAL ANODE REJECTION",
"CCPP ANODE REJECTION"
],
"query": {
"InternalAnodeRejection": [
SterliteCCPPQuery.InternalAnodeRejection.QUERY_1
]
},
"data": [],
"data_column": [
"dcs - data to be fetched shiftwise",
"",
"6am",
"7am",
"8am",
"1pm"
"internal_anode_rejection",
"ccpp_anode_rejection"
],
"addition": {
"merge_header": "SHIFT-B",
}
},
"BLANK1": {
"columns": [
......@@ -158,12 +228,19 @@ class CCPCReportTemplate:
},
"PARTICULAR TEMP": {
"columns": [
None
"PARTICULARS",
"UOM",
"FTD"
],
"data": [],
"query": {},
"query": {
"Paticulars": [SterliteCCPPQuery.Paticulars.QUERY_1],
"LugThickness": [SterliteCCPPQuery.LugThickness.QUERY_1]
},
"data_column": [
None
"particulars",
"uom",
"ftd"
]
}
......@@ -171,375 +248,345 @@ class CCPCReportTemplate:
{
"TBC": {
"columns": [
"DCS - DATA TO BE FETCHED SHIFTWISE",
"",
"6AM",
"7AM",
"8AM",
"1PM"
],
"query": {
"Tbc": [SterliteCCPPQuery.Tbc.QUERY_1,
SterliteCCPPQuery.Tbc.QUERY_2]
},
"data": [],
"data_column": [
"dcs - data to be fetched shiftwise",
"",
"6am",
"7am",
"8am",
"1pm"
],
"addition": {
"merge_header": "SHIFT-C",
}
}
},
{
"PERSON ON DUTY": {
"columns": ["SHIFT", "TIME", "TANK OUTLET PRESSURE", "VAP. OUTLET PRESSURE", "LINE. OUTLET PRESSURE",
"LINE. TEM "],
"columns": ["PERSONS ON DUTY", "A SHIFT", "B SHIFT", "C SHIFT"],
"query": {
"PersonOnDuty": [SterliteCCPPQuery.PersonOnDuty.QUERY_1]
},
"data": [],
"data_column": ["shift", "time", "tank outlet pressure", "vap. outlet pressure",
"line. outlet pressure", "line. tem "],
"data_column": ["persons_on_duty", "a_shift", "b_shift", "c_shift"],
},
},
{
"PRODUCTION DETAILS": {
"columns": ["PARAMATER", "AVG VALUE"],
"columns": ["PRODUCTION_DETAIL", "A_SHIFT", "B_SHIFT", "C_SHIFT", "TOTAL_ANODE", "A_SHIFT_PRODUCTION",
"B_SHIFT_PRODUCTION", "C_SHIFT_PRODUCTION", "OD_PRODUCTION"],
"query": {
"ProductionDetails1": [SterliteCCPPQuery.ProductionDetails1.QUERY_1],
"ProductionDetails2": [SterliteCCPPQuery.ProductionDetails2.QUERY_1]
},
"data": [],
"data_column": ["parameter", "avg_value"]
"data_column": ["production_detail", "a_shift", "b_shift", "c_shift", "total_anode",
"a_shift_production", "b_shift_production", "c_shift_production", "od_production"]
},
},
{
"CONSUMPTION ITEMS": {
"columns": ["CHARGING DETAILS", "A SHIFT", "B SHIFT", "C SHIFT", "TOTAL"],
"columns": ["CONSUMPTION ITEM", "UNIT", "ON DATE", "MTD"],
"query": {
"ConsumptionItem1": [SterliteCCPPQuery.ConsumptionItem1.QUERY_1,
SterliteCCPPQuery.ConsumptionItem1.QUERY_2],
"ConsumptionItem2": [SterliteCCPPQuery.ConsumptionItem2.QUERY_1,
SterliteCCPPQuery.ConsumptionItem2.QUERY_2],
"ConsumptionItem3": [SterliteCCPPQuery.ConsumptionItem3.QUERY_1,
SterliteCCPPQuery.ConsumptionItem3.QUERY_2]
},
"data": [],
"data_column": ["charging_details", "shift_a", "shift_b", "shift_c", "total"],
"data_column": ["consumption_item", "unit", "on_date", "mtd"],
}
},
{
"ACTIVITY TIME": {
"columns": [
"PRODUCTION DETAILS-NO. OF ANODES",
"A SHIFT",
"B SHIFT",
"C SHIFT",
"TOTAL",
"A-SHIFT PRDN",
"B-SHIFT PRDN",
"C-SHIFT PRDN",
"OD PRODN (MT) ="
],
"query": {
},
"data": [],
"data_column": [
"production details-no. of anodes",
"a_shift",
"b_shift",
"c_shift",
"total",
"a_shift_prdn",
"b_shift_prdn",
"c_shift_prdn",
"od_prodn"
],
}
},
{
"A-SHIFT": {
"columns": [
"CONSUMPTION ITEMS",
"UNIT",
"ON DATE",
"MTD",
],
"query": {
},
"data": [],
"data_column": [
"consumption_items",
"unit",
"on_date",
"mtd",
],
},
"BLANK0": {
"columns": [
None
],
"data": [],
"query": {},
"data_column": [
None
]
},
"LINEAR CASTING": {
"columns": [
None
],
"data": [],
"query": {},
"data_column": [
None
]
},
},
{
"A-SHIFT": {
"columns": [
"CONSUMPTION ITEMS",
"UNIT",
"ON DATE",
"MTD",
],
"query": {
},
"data": [],
"data_column": [
"consumption_items",
"unit",
"on_date",
"mtd",
],
},
"BLANK0": {
"columns": [
None
],
"data": [],
"query": {},
"data_column": [
None
]
},
"LINEAR CASTING": {
"columns": [
None
],
"data": [],
"query": {},
"data_column": [
None
]
},
},
{
"SHIFT ACTIVITY": {
"columns": [
"ACTIVITY-TIME",
"SHIFT",
"START TIME",
"END TIME",
"TOTAL TIME (MINUTES)",
"REASON FOR STOPAGE"
],
"query": {
},
"data": [],
"data_column": [
"activity_time",
"shift",
"start_time",
"end_time",
"total_time",
"reason_for_stopage"
],
},
"BLANK": {
"columns": [
None
],
"data": [],
"query": {},
"data_column": [
None
]
},
"CIRCULAR CASTING": {
"columns": [
None
],
"data": [],
"query": {},
"data_column": [
None
]
},
},
{
"B-SHIFT": {
"columns": [
"CONSUMPTION ITEMS",
"UNIT",
"ON DATE",
"MTD",
],
"query": {
},
"data": [],
"data_column": [
"consumption_items",
"unit",
"on_date",
"mtd",
],
},
"BLANK0": {
"columns": [
None
],
"data": [],
"query": {},
"data_column": [
None
]
},
"LINEAR CASTING": {
"columns": [
None
],
"data": [],
"query": {},
"data_column": [
None
]
},
},
{
"SHIFT ACTIVITY": {
"columns": [
"ACTIVITY-TIME",
"SHIFT",
"START TIME",
"ACTIVITY TIME",
"SHIFT TIME",
"END TIME",
"TOTAL TIME (MINUTES)",
"REASON FOR STOPAGE"
],
"query": {
# "ActivityTime":[
# # SterliteCCPPQuery.ActivityTime.QUERY_1
# ]
},
"data": [],
"data_column": [
"activity_time",
"shift",
"start_time",
"shift_time",
"end_time",
"total_time",
"reason_for_stopage"
],
},
"BLANK": {
"columns": [
None
],
"data": [],
"query": {},
"data_column": [
None
]
},
"CIRCULAR CASTING": {
"columns": [
None
],
"data": [],
"query": {},
"data_column": [
None
]
},
},
{
"C-SHIFT": {
"columns": [
"CONSUMPTION ITEMS",
"UNIT",
"ON DATE",
"MTD",
],
"query": {
},
"data": [],
"data_column": [
"consumption_items",
"unit",
"on_date",
"mtd",
],
},
"BLANK0": {
"columns": [
None
],
"data": [],
"query": {},
"data_column": [
None
]
},
"LINEAR CASTING": {
"columns": [
None
],
"data": [],
"query": {},
"data_column": [
None
]
},
},
{
"SHIFT ACTIVITY": {
"columns": [
"ACTIVITY-TIME",
"SHIFT",
"START TIME",
"END TIME",
"TOTAL TIME (MINUTES)",
"REASON FOR STOPAGE"
],
"query": {
},
"data": [],
"data_column": [
"activity_time",
"shift",
"start_time",
"end_time",
"total_time",
"reason_for_stopage"
],
},
"BLANK": {
"columns": [
None
],
"data": [],
"query": {},
"data_column": [
None
]
},
"CIRCULAR CASTING": {
"columns": [
None
],
"data": [],
"query": {},
"data_column": [
None
]
},
}
},
# {
# "A-SHIFT": {
# "columns": ["",""
# ],
# "query": {
# },
# "data": [],
# "data_column": ["",""
#
# ],
# "addition": {
# "merge_header": "A-SHIFT",
# }
# },
# "BLANK0": {
# "columns": [
# None
# ],
# "data": [],
# "query": {},
# "data_column": [
# None
# ]
# },
# "LINEAR CASTING": {
# "columns": [
# "",""
# ],
# "data": [],
# "query": {},
# "data_column": [
# "",""
# ],
# "addition": {
# "merge_header": "LINEAR CASTING",
# }
# },
# },
# {
# "A-SHIFT": {
# "columns": [
# "",""
# ],
# "query": {
# },
# "data": [],
# "data_column": [
# "",""
# ],
# },
# "BLANK0": {
# "columns": [
# None
# ],
# "data": [],
# "query": {},
# "data_column": [
# None
# ]
# },
# "CIRCULAR CASTING": {
# "columns": [
# "",""
# ],
# "data": [],
# "query": {},
# "data_column": [
# "",""
# ],
# "addition": {
# "merge_header": "CIRCULAR CASTING",
# }
# },
# },
# {
# "SHIFT ACTIVITY": {
# "columns": [
# "",""
# ],
# "query": {
# },
# "data": [],
# "data_column": [
# "",""
# ],
# },
# "BLANK": {
# "columns": [
# None
# ],
# "data": [],
# "query": {},
# "data_column": [
# None
# ]
# },
# "CIRCULAR CASTING": {
# "columns": [
# "",""
# ],
# "data": [],
# "query": {},
# "data_column": [
# "",""
# ],
# "addition": {
# "merge_header": "CIRCULAR CASTING",
# }
# },
# },
# {
# "B-SHIFT": {
# "columns": [
# "", ""
# ],
# "query": {
# },
# "data": [],
# "data_column": [
# "",""
# ],
# },
# "BLANK0": {
# "columns": [
# None
# ],
# "data": [],
# "query": {},
# "data_column": [
# None
# ]
# },
# "LINEAR CASTING": {
# "columns": [
# "",""
# ],
# "data": [],
# "query": {},
# "data_column": [
# "",""
# ],
# "addition": {
# "merge_header": "LINEAR CASTING",
# }
# },
# },
# {
# "SHIFT ACTIVITY": {
# "columns": [
# "ACTIVITY-TIME",
# "SHIFT",
# "START TIME",
# "END TIME",
# "TOTAL TIME (MINUTES)",
# "REASON FOR STOPAGE"
# ],
# "query": {
# },
# "data": [],
# "data_column": [
# "activity_time",
# "shift",
# "start_time",
# "end_time",
# "total_time",
# "reason_for_stopage"
# ],
# },
# "BLANK": {
# "columns": [
# None
# ],
# "data": [],
# "query": {},
# "data_column": [
# None
# ]
# },
# "CIRCULAR CASTING": {
# "columns": [
# "",""
# ],
# "data": [],
# "query": {},
# "data_column": [
# "",""
# ],
# "addition": {
# "merge_header": "CIRCULAR CASTING",
# }
# },
# },
# {
# "C-SHIFT": {
# "columns": ["",""
#
# ],
# "query": {
# },
# "data": [],
# "data_column": ["",""
#
# ],
# },
# "BLANK0": {
# "columns": [
# None
# ],
# "data": [],
# "query": {},
# "data_column": [
# None
# ]
# },
# "LINEAR CASTING": {
# "columns": [
# "",""
# ],
# "data": [],
# "query": {},
# "data_column": [
# "",""
# ],
# "addition": {
# "merge_header": "LINEAR CASTING",
# }
# },
# },
# {
# "SHIFT ACTIVITY": {
# "columns": ["",""
# ],
# "query": {
# },
# "data": [],
# "data_column": ["",""
#
# ],
# },
# "BLANK": {
# "columns": [
# None
# ],
# "data": [],
# "query": {},
# "data_column": [
# None
# ]
# },
# "CIRCULAR CASTING": {
# "columns": [
# "",""
# ],
# "data": [],
# "query": {},
# "data_column": [
# "",""
# ],
# "addition": {
# "merge_header": "CIRCULAR CASTING",
# }
# },
# }
]
WORKSHEET_HEADER_FORMAT = {
"bold": True,
......
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