Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sterlite_custom_reports
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
suryakant
sterlite_custom_reports
Commits
e6c166f7
Commit
e6c166f7
authored
Oct 26, 2023
by
mohammed.akhib
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
UPDATED CCPP QUERIES
parent
11fd85f6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
207 additions
and
79 deletions
+207
-79
scripts/core/db/postgres/custom_report_query.py
scripts/core/db/postgres/custom_report_query.py
+207
-79
No files found.
scripts/core/db/postgres/custom_report_query.py
View file @
e6c166f7
...
@@ -5930,32 +5930,48 @@ class SterliteCCPPQuery:
...
@@ -5930,32 +5930,48 @@ class SterliteCCPPQuery:
class
Lpg
:
class
Lpg
:
QUERY_1
=
"""
QUERY_1
=
"""
select
select tbl2.kpi, tbl2.unit, sum(lpg_consumption_total/production) as metric_value from
'lpg' as kpi,
(select 'Production' as kpi, 'MT' as unit, a.date, (sum(anode_wt)*sum(total_anode))/1000 as production from
'KG/MT' as unit,
(select date(date) as date, production_value as anode_wt from semantic_prod.ccpp_production_plan
lpg_consumption_total as metric_value
where lower(trim(production_anode))='anode weighment') a
from
inner join
semantic_prod.ccpp_actual_production_2
(select date(date) as date, total_anode_accepted_a+total_anode_accepted_b+total_anode_accepted_c as total_anode
WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
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
=
"""
QUERY_2
=
"""
select
select tbl2.kpi, tbl2.unit, sum(lpg_consumption_total/production) as metric_value from
'lpg' as kpi,
(select 'Production' as kpi, 'MT' as unit, a.date, (sum(anode_wt)*sum(total_anode))/1000 as production from
'KG/MT' as unit,
(select date(date) as date, production_value as anode_wt from semantic_prod.ccpp_production_plan
lpg_consumption_total as metric_value
where lower(trim(production_anode))='anode weighment') a
from
inner join
semantic_prod.ccpp_actual_production_2
(select date(date) as date, total_anode_accepted_a+total_anode_accepted_b+total_anode_accepted_c as total_anode
WHERE DATE BETWEEN '{month_start_date}' AND '{month_end_date}'
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
:
class
SodiumSilicate
:
QUERY_1
=
"""
QUERY_1
=
"""
SELECT
SELECT
kpi,
kpi
as particulars
,
SUM(CAST(metric_value AS NUMERIC)) AS metric_value
,
'KG/MT' as unit
,
'KG/MT' as unit
SUM(CAST(metric_value AS NUMERIC)) AS on_date
FROM
FROM
(
(
SELECT
SELECT
...
@@ -5996,9 +6012,10 @@ class SterliteCCPPQuery:
...
@@ -5996,9 +6012,10 @@ class SterliteCCPPQuery:
"""
"""
QUERY_2
=
"""
QUERY_2
=
"""
SELECT
SELECT
kpi,
kpi as particulars,
SUM(CAST(metric_value AS NUMERIC)) AS metric_value,
'KG/MT' as unit,
'KG/MT' as unit
SUM(CAST(metric_value AS NUMERIC)) AS mtd
FROM
FROM
(
(
SELECT
SELECT
...
@@ -6042,18 +6059,18 @@ class SterliteCCPPQuery:
...
@@ -6042,18 +6059,18 @@ class SterliteCCPPQuery:
class
Power
:
class
Power
:
QUERY_1
=
"""
QUERY_1
=
"""
select
select
'power' as
kpi
,
'power' as
particulars
,
'KWH/MT' as unit,
'KWH/MT' as unit,
power_consumption_total as
metric_valu
e
power_consumption_total as
on_dat
e
from
from
semantic_prod.ccpp_actual_production_2
semantic_prod.ccpp_actual_production_2
WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}';
WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}';
"""
"""
QUERY_2
=
"""
QUERY_2
=
"""
select
select
'power' as
kpi
,
'power' as
particulars
,
'KWH/MT' as unit,
'KWH/MT' as unit,
power_consumption_total as m
etric_value
power_consumption_total as m
td
from
from
semantic_prod.ccpp_actual_production_2
semantic_prod.ccpp_actual_production_2
WHERE DATE BETWEEN '{month_start_date}' AND '{month_end_date}';
WHERE DATE BETWEEN '{month_start_date}' AND '{month_end_date}';
...
@@ -6061,7 +6078,7 @@ class SterliteCCPPQuery:
...
@@ -6061,7 +6078,7 @@ class SterliteCCPPQuery:
class
KanshakiBlister
:
class
KanshakiBlister
:
QUERY_1
=
"""
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 (
FROM (
SELECT date, 'Kanshashi Blister' AS kpi, shift, COALESCE(blister_a, '0') AS metric_value
SELECT date, 'Kanshashi Blister' AS kpi, shift, COALESCE(blister_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
FROM semantic_prod.charging_details_ccpp
...
@@ -6083,7 +6100,7 @@ class SterliteCCPPQuery:
...
@@ -6083,7 +6100,7 @@ class SterliteCCPPQuery:
GROUP BY 1 ;
GROUP BY 1 ;
"""
"""
QUERY_2
=
"""
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 (
FROM (
SELECT date, 'Kanshashi Blister' AS kpi, shift, COALESCE(blister_a, '0') AS metric_value
SELECT date, 'Kanshashi Blister' AS kpi, shift, COALESCE(blister_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
FROM semantic_prod.charging_details_ccpp
...
@@ -6107,7 +6124,7 @@ class SterliteCCPPQuery:
...
@@ -6107,7 +6124,7 @@ class SterliteCCPPQuery:
class
RejectedCoil
:
class
RejectedCoil
:
QUERY_1
=
"""
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 (
FROM (
SELECT date, 'Rejected coils' AS kpi, shift, COALESCE(rejected_coil_a, '0') AS metric_value
SELECT date, 'Rejected coils' AS kpi, shift, COALESCE(rejected_coil_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
FROM semantic_prod.charging_details_ccpp
...
@@ -6128,7 +6145,7 @@ class SterliteCCPPQuery:
...
@@ -6128,7 +6145,7 @@ class SterliteCCPPQuery:
GROUP BY 1 ;
GROUP BY 1 ;
"""
"""
QUERY_2
=
"""
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 (
FROM (
SELECT date, 'Rejected coils' AS kpi, shift, COALESCE(rejected_coil_a, '0') AS metric_value
SELECT date, 'Rejected coils' AS kpi, shift, COALESCE(rejected_coil_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
FROM semantic_prod.charging_details_ccpp
...
@@ -6151,7 +6168,7 @@ class SterliteCCPPQuery:
...
@@ -6151,7 +6168,7 @@ class SterliteCCPPQuery:
class
MasterAlloy
:
class
MasterAlloy
:
QUERY_1
=
"""
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 (
FROM (
SELECT date, 'Master Alloy' AS kpi, shift, COALESCE(master_alloy_a, '0') AS metric_value
SELECT date, 'Master Alloy' AS kpi, shift, COALESCE(master_alloy_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
FROM semantic_prod.charging_details_ccpp
...
@@ -6172,7 +6189,7 @@ class SterliteCCPPQuery:
...
@@ -6172,7 +6189,7 @@ class SterliteCCPPQuery:
GROUP BY 1 ;
GROUP BY 1 ;
"""
"""
QUERY_2
=
"""
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 (
FROM (
SELECT date, 'Master Alloy' AS kpi, shift, COALESCE(master_alloy_a, '0') AS metric_value
SELECT date, 'Master Alloy' AS kpi, shift, COALESCE(master_alloy_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
FROM semantic_prod.charging_details_ccpp
...
@@ -6195,7 +6212,7 @@ class SterliteCCPPQuery:
...
@@ -6195,7 +6212,7 @@ class SterliteCCPPQuery:
class
CssBlister
:
class
CssBlister
:
QUERY_1
=
"""
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 (
FROM (
SELECT date, 'CSS Blister' AS kpi, shift, COALESCE(css_blister_a, '0') AS metric_value
SELECT date, 'CSS Blister' AS kpi, shift, COALESCE(css_blister_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
FROM semantic_prod.charging_details_ccpp
...
@@ -6216,7 +6233,7 @@ class SterliteCCPPQuery:
...
@@ -6216,7 +6233,7 @@ class SterliteCCPPQuery:
GROUP BY 1 ;
GROUP BY 1 ;
"""
"""
QUERY_2
=
"""
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 (
FROM (
SELECT date, 'CSS Blister' AS kpi, shift, COALESCE(css_blister_a, '0') AS metric_value
SELECT date, 'CSS Blister' AS kpi, shift, COALESCE(css_blister_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
FROM semantic_prod.charging_details_ccpp
...
@@ -6239,7 +6256,7 @@ class SterliteCCPPQuery:
...
@@ -6239,7 +6256,7 @@ class SterliteCCPPQuery:
class
InternalRejectionAnode
:
class
InternalRejectionAnode
:
QUERY_1
=
"""
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 (
FROM (
SELECT date, 'Internal Rejected Anode' AS kpi, shift, COALESCE(internal_reject_a, '0') AS metric_value
SELECT date, 'Internal Rejected Anode' AS kpi, shift, COALESCE(internal_reject_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
FROM semantic_prod.charging_details_ccpp
...
@@ -6260,7 +6277,7 @@ class SterliteCCPPQuery:
...
@@ -6260,7 +6277,7 @@ class SterliteCCPPQuery:
GROUP BY 1 ;
GROUP BY 1 ;
"""
"""
QUERY_2
=
"""
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 (
FROM (
SELECT date, 'Internal Rejected Anode' AS kpi, shift, COALESCE(internal_reject_a, '0') AS metric_value
SELECT date, 'Internal Rejected Anode' AS kpi, shift, COALESCE(internal_reject_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
FROM semantic_prod.charging_details_ccpp
...
@@ -6283,7 +6300,7 @@ class SterliteCCPPQuery:
...
@@ -6283,7 +6300,7 @@ class SterliteCCPPQuery:
class
RefinerySpentAnode
:
class
RefinerySpentAnode
:
QUERY_1
=
"""
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 (
FROM (
SELECT date, 'Refinery Spent Anode' AS kpi, shift, COALESCE(ref_spent_a, '0') AS metric_value
SELECT date, 'Refinery Spent Anode' AS kpi, shift, COALESCE(ref_spent_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
FROM semantic_prod.charging_details_ccpp
...
@@ -6304,7 +6321,7 @@ class SterliteCCPPQuery:
...
@@ -6304,7 +6321,7 @@ class SterliteCCPPQuery:
GROUP BY 1 ;
GROUP BY 1 ;
"""
"""
QUERY_2
=
"""
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 (
FROM (
SELECT date, 'Refinery Spent Anode' AS kpi, shift, COALESCE(ref_spent_a, '0') AS metric_value
SELECT date, 'Refinery Spent Anode' AS kpi, shift, COALESCE(ref_spent_a, '0') AS metric_value
FROM semantic_prod.charging_details_ccpp
FROM semantic_prod.charging_details_ccpp
...
@@ -6328,7 +6345,7 @@ class SterliteCCPPQuery:
...
@@ -6328,7 +6345,7 @@ class SterliteCCPPQuery:
class
SapProduction
:
class
SapProduction
:
QUERY_1
=
"""
QUERY_1
=
"""
select
select
kpi,
kpi
as particulars
,
sum(value) as Metric_Value
sum(value) as Metric_Value
from
from
semantic_prod.acp_ccpc_ccpp_view
semantic_prod.acp_ccpc_ccpp_view
...
@@ -6584,7 +6601,9 @@ class SterliteCCPPQuery:
...
@@ -6584,7 +6601,9 @@ class SterliteCCPPQuery:
group by
group by
1;
1;
"""
"""
QUERY_2
=
"""
class
TotalBreakdownDetails1
:
QUERY_1
=
"""
select
select
'Total(Mins)' as kpi,
'Total(Mins)' as kpi,
sum(breakdown_duration_hours * 60) as breakdown_duration_mins
sum(breakdown_duration_hours * 60) as breakdown_duration_mins
...
@@ -6611,20 +6630,15 @@ class SterliteCCPPQuery:
...
@@ -6611,20 +6630,15 @@ class SterliteCCPPQuery:
class
MonthwiseProductionDetails
:
class
MonthwiseProductionDetails
:
QUERY_1
=
"""
QUERY_1
=
"""
select
select TO_CHAR(TO_DATE(month::text, 'MM'),'Mon') as month, max(target) as target, max(production) as production from
kpi,
(select month,
category,
case when lower(kpi)='production plan' then sum(value) else 0 end as target,
sum(value) as Metric_Value
case when lower(kpi)='production actual' then sum(value) else 0 end as production
from
from semantic_prod.acp_ccpc_ccpp_view
semantic_prod.acp_ccpc_ccpp_view
where lower(kpi) in('production actual','production plan')
where
and lower(category) = 'ccpp'
lower(kpi) in('production actual', 'production plan')
and DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
and lower(category) = 'ccpp' and
group by 1,kpi) foo group by 1;
DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
group by
kpi,
category
;
"""
"""
class
Paticulars
:
class
Paticulars
:
...
@@ -6713,7 +6727,7 @@ class SterliteCCPPQuery:
...
@@ -6713,7 +6727,7 @@ class SterliteCCPPQuery:
) foo WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
) foo WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
GROUP BY 1 ;
GROUP BY 1 ;
"""
"""
QUERY_
1
=
"""
QUERY_
2
=
"""
SELECT kpi, SUM(CAST(metric_value AS NUMERIC)) AS metric_value, 'KG/MT' as unit
SELECT kpi, SUM(CAST(metric_value AS NUMERIC)) AS metric_value, 'KG/MT' as unit
FROM (
FROM (
SELECT date, 'BARIUM SULPHATE' AS kpi, shift, COALESCE(barium_sulphate_a, '0') AS metric_value
SELECT date, 'BARIUM SULPHATE' AS kpi, shift, COALESCE(barium_sulphate_a, '0') AS metric_value
...
@@ -6802,9 +6816,9 @@ class SterliteCCPPQuery:
...
@@ -6802,9 +6816,9 @@ class SterliteCCPPQuery:
"""
"""
class
Tbc
:
class
Tbc
:
QUERY_1
=
"""
"
QUERY_1
=
"""
SELECT kpi, shift, value, CAST(date AS TIME) AS time
SELECT kpi, shift, value, CAST(date AS TIME) AS time
FROM (
FROM (
SELECT date, lpg_param AS kpi, shift, COALESCE(lpg_value, '0') AS value
SELECT date, lpg_param AS kpi, shift, COALESCE(lpg_value, '0') AS value
FROM semantic_prod.ccpp_lpg_vapouriser
FROM semantic_prod.ccpp_lpg_vapouriser
WHERE LOWER(shift) = 'shift a'
WHERE LOWER(shift) = 'shift a'
...
@@ -6820,11 +6834,125 @@ FROM (
...
@@ -6820,11 +6834,125 @@ FROM (
SELECT date, lpg_param3 AS kpi, shift, COALESCE(lpg_value3, '0') AS value
SELECT date, lpg_param3 AS kpi, shift, COALESCE(lpg_value3, '0') AS value
FROM semantic_prod.ccpp_lpg_vapouriser
FROM semantic_prod.ccpp_lpg_vapouriser
WHERE LOWER(shift) = 'shift c'
WHERE LOWER(shift) = 'shift c'
) foo
) foo
where <date_filters>
WHERE DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
"""
select * from semantic_prod.ccpp_lpg_vapouriser"
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
;
"""
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment