Commit 10e995be authored by suryakant's avatar suryakant

Sterlite Custom Report Updates

parent 36223b60
......@@ -337,121 +337,307 @@ class SterliteRefineryQuery:
GROUP BY 1,2,3
"""
class Cir140KARectifierAvgCurrent:
class GridPowerAvailability:
""" POWER AVAILABILITY """
QUERY_1 = """
SELECT
'Cir-1 40 KA Rectifier Avg. Current' AS power_availability,
'KAmp' AS uom,
AVG(PLAN_METRIC_VALUE) AS norms,
SUM(ACTUAL_METRIC_VALUE) / COALESCE(NULLIF(COUNT(
CASE
first_tbl.power_availability,
first_tbl.uom,
first_tbl.norms,
first_tbl.on_date,
second_tbl.mtd,
third_tbl.ytd
FROM
(select
'Grid Power Availability' as power_availability,
'%' as UOM,
avg(grid_plan) as norms,
avg(grid_actual) as on_date
from(
select dd_1.date_dt as date,
plan.grid_plan,
case when actual.grid_actual is null then 100 else actual.grid_actual
end as grid_actual
from(
select date(date) as posting_date,
area_ics_head_value::double precision as grid_plan
from semantic_prod.area_ics_head_refinery_norms
where lower(trim(area_ics_head_select)) = 'grid power availability'
and date_part('day',date) = 1
group by 1,2
)plan
left join(SELECT dim_date.date_dt,
dim_date.month_of_yr_num AS mnth,
dim_date.yr_name AS yr
FROM semantic_prod.dim_date) dd_1 ON dd_1.mnth = date_part('month',
plan.posting_date)
and dd_1.yr = date_part('year',plan.posting_date)
left join(
select date(date) as posting_date,
max(case when lower(trim(loss_or_gain_shutdown_rectifier)) = 'both'
then ((24 - coalesce(loss_or_gain_shutdown_duration::double precision,
0)) / 24) * 100
else null end) as grid_actual
from semantic_prod.shutdown_details
group by 1
)actual on dd_1.date_dt = actual.posting_date
)grid_data
where date between '{day_start_date}' AND '{day_end_date}'
group by 1,2) as first_tbl
JOIN
(
select
'Grid Power Availability' as power_availability,
'%' as UOM,
avg(grid_actual) as mtd
from(
select dd_1.date_dt as date,
plan.grid_plan,
case when actual.grid_actual is null then 100 else actual.grid_actual
end as grid_actual
from(
select date(date) as posting_date,
area_ics_head_value::double precision as grid_plan
from semantic_prod.area_ics_head_refinery_norms
where lower(trim(area_ics_head_select)) = 'grid power availability'
and date_part('day',date) = 1
group by 1,2
)plan
left join(SELECT dim_date.date_dt,
dim_date.month_of_yr_num AS mnth,
dim_date.yr_name AS yr
FROM semantic_prod.dim_date) dd_1 ON dd_1.mnth = date_part('month',
plan.posting_date)
and dd_1.yr = date_part('year',plan.posting_date)
left join(
select date(date) as posting_date,
max(case when lower(trim(loss_or_gain_shutdown_rectifier)) = 'both'
then ((24 - coalesce(loss_or_gain_shutdown_duration::double precision,
0)) / 24) * 100
else null end) as grid_actual
from semantic_prod.shutdown_details
group by 1
)actual on dd_1.date_dt = actual.posting_date
)grid_data
where date between '{month_start_date}' AND '{month_end_date}'
group by 1,2
) as second_tbl
ON first_tbl.power_availability=second_tbl.power_availability
JOIN
(
select
'Grid Power Availability' as power_availability,
'%' as UOM,
avg(grid_actual) as ytd
from(
select dd_1.date_dt as date,
plan.grid_plan,
case when actual.grid_actual is null then 100 else actual.grid_actual
end as grid_actual
from(
select date(date) as posting_date,
area_ics_head_value::double precision as grid_plan
from semantic_prod.area_ics_head_refinery_norms
where lower(trim(area_ics_head_select)) = 'grid power availability'
and date_part('day',date) = 1
group by 1,2
)plan
left join(SELECT dim_date.date_dt,
dim_date.month_of_yr_num AS mnth,
dim_date.yr_name AS yr
FROM semantic_prod.dim_date) dd_1 ON dd_1.mnth = date_part('month',
plan.posting_date)
and dd_1.yr = date_part('year',plan.posting_date)
left join(
select date(date) as posting_date,
max(case when lower(trim(loss_or_gain_shutdown_rectifier)) = 'both'
then ((24 - coalesce(loss_or_gain_shutdown_duration::double precision,
0)) / 24) * 100
else null end) as grid_actual
from semantic_prod.shutdown_details
group by 1
)actual on dd_1.date_dt = actual.posting_date
)grid_data
where date between '{year_start_date}' AND '{year_end_date}'
group by 1,2
) as third_tbl
ON second_tbl.power_availability=third_tbl.power_availability
"""
class Cir140KARectifierAvgCurrent:
""" POWER AVAILABILITY """
QUERY_1 = """
SELECT
first_tbl.power_availability,
first_tbl.uom,
first_tbl.norms,
ROUND(first_tbl.on_date :: NUMERIC, 2) on_date,
ROUND(second_tbl.mtd :: NUMERIC, 2) mtd,
ROUND(third_tbl.ytd :: NUMERIC, 2) ytd
FROM
(SELECT
'Cir-1 40 KA Rectifier Avg. Current' AS power_availability,
'KAmp' AS uom,
AVG(PLAN_METRIC_VALUE) AS norms,
SUM(ACTUAL_METRIC_VALUE) / COALESCE(NULLIF(COUNT(
CASE
WHEN ACTUAL_METRIC_VALUE <> 0 THEN 1
ELSE NULL END), 0), 1) AS on_date
FROM SEMANTIC_PROD.RECTIFIER_KPI_VIEW
WHERE LOWER(TRIM(KPI)) = '40ka_rectifier_current'
AND DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
GROUP BY 1,2
"""
QUERY_2 = """
SELECT
'Cir-1 40 KA Rectifier Avg. Current' AS power_availability,
'KAmp' AS uom,
SUM(ACTUAL_METRIC_VALUE) / COALESCE(NULLIF(COUNT(
CASE
FROM SEMANTIC_PROD.RECTIFIER_KPI_VIEW
WHERE LOWER(TRIM(KPI)) = '40ka_rectifier_current'
AND date between '{day_start_date}' AND '{day_end_date}'
group by 1,2) as first_tbl
JOIN
(SELECT
'Cir-1 40 KA Rectifier Avg. Current' AS power_availability,
'KAmp' AS uom,
SUM(ACTUAL_METRIC_VALUE) / COALESCE(NULLIF(COUNT(
CASE
WHEN ACTUAL_METRIC_VALUE <> 0 THEN 1
ELSE NULL END), 0), 1) AS mtd
FROM SEMANTIC_PROD.RECTIFIER_KPI_VIEW
WHERE LOWER(TRIM(KPI)) = '40ka_rectifier_current'
AND DATE BETWEEN '{month_start_date}' AND '{month_end_date}'
GROUP BY 1,2
"""
QUERY_3 = """
SELECT
'Cir-1 40 KA Rectifier Avg. Current' AS power_availability,
'KAmp' AS uom,
SUM(ACTUAL_METRIC_VALUE) / COALESCE(NULLIF(COUNT(
CASE
FROM SEMANTIC_PROD.RECTIFIER_KPI_VIEW
WHERE LOWER(TRIM(KPI)) = '40ka_rectifier_current'
AND date between '{month_start_date}' AND '{month_end_date}'
group by 1,2) as second_tbl
ON first_tbl.power_availability=second_tbl.power_availability
JOIN
(SELECT
'Cir-1 40 KA Rectifier Avg. Current' AS power_availability,
'KAmp' AS uom,
SUM(ACTUAL_METRIC_VALUE) / COALESCE(NULLIF(COUNT(
CASE
WHEN ACTUAL_METRIC_VALUE <> 0 THEN 1
ELSE NULL END), 0), 1) AS ytd
FROM SEMANTIC_PROD.RECTIFIER_KPI_VIEW
WHERE LOWER(TRIM(KPI)) = '40ka_rectifier_current'
AND DATE BETWEEN '{year_start_date}' AND '{year_end_date}'
GROUP BY 1,2
"""
FROM SEMANTIC_PROD.RECTIFIER_KPI_VIEW
WHERE LOWER(TRIM(KPI)) = '40ka_rectifier_current'
AND date between '{year_start_date}' AND '{year_end_date}'
group by 1,2) as third_tbl
ON second_tbl.power_availability=third_tbl.power_availability
"""
class Cir235KARectifierAvgCurrent:
""" POWER AVAILABILITY """
QUERY_1 = """
SELECT
'Cir-2 35 KA Rectifier Avg. Current' AS power_availability,
'KAmp' AS uom,
AVG(PLAN_METRIC_VALUE) AS norms,
SUM(ACTUAL_METRIC_VALUE) / COALESCE(NULLIF(COUNT(
SELECT
first_tbl.power_availability,
first_tbl.uom,
first_tbl.norms,
ROUND(first_tbl.on_date :: NUMERIC, 2) on_date,
ROUND(second_tbl.mtd :: NUMERIC, 2) mtd,
ROUND(third_tbl.ytd :: NUMERIC, 2) ytd
FROM
(SELECT
'Cir-2 35 KA Rectifier Avg. Current' AS power_availability,
'KAmp' AS uom,
AVG(PLAN_METRIC_VALUE) AS norms,
SUM(ACTUAL_METRIC_VALUE) / COALESCE(NULLIF(COUNT(
CASE
WHEN ACTUAL_METRIC_VALUE <> 0
THEN 1 ELSE NULL END), 0), 1)
AS on_date
FROM SEMANTIC_PROD.RECTIFIER_KPI_VIEW
WHERE LOWER(TRIM(KPI)) = '35ka_rectifier_current'
FROM SEMANTIC_PROD.RECTIFIER_KPI_VIEW
WHERE LOWER(TRIM(KPI)) = '35ka_rectifier_current'
AND DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
GROUP BY 1,2
"""
QUERY_2 = """
SELECT
'Cir-2 35 KA Rectifier Avg. Current' AS power_availability,
'KAmp' AS uom,
SUM(ACTUAL_METRIC_VALUE) / COALESCE(NULLIF(COUNT(
GROUP BY 1,2) as first_tbl
JOIN
(SELECT
'Cir-2 35 KA Rectifier Avg. Current' AS power_availability,
'KAmp' AS uom,
SUM(ACTUAL_METRIC_VALUE) / COALESCE(NULLIF(COUNT(
CASE
WHEN ACTUAL_METRIC_VALUE <> 0
THEN 1 ELSE NULL END), 0), 1)
AS mtd
FROM SEMANTIC_PROD.RECTIFIER_KPI_VIEW
WHERE LOWER(TRIM(KPI)) = '35ka_rectifier_current'
FROM SEMANTIC_PROD.RECTIFIER_KPI_VIEW
WHERE LOWER(TRIM(KPI)) = '35ka_rectifier_current'
AND DATE BETWEEN '{month_start_date}' AND '{month_end_date}'
GROUP BY 1,2
"""
QUERY_3 = """
SELECT
'Cir-2 35 KA Rectifier Avg. Current' AS power_availability,
'KAmp' AS uom,
SUM(ACTUAL_METRIC_VALUE) / COALESCE(NULLIF(COUNT(
GROUP BY 1,2) as second_tbl
ON first_tbl.power_availability=second_tbl.power_availability
JOIN
(SELECT
'Cir-2 35 KA Rectifier Avg. Current' AS power_availability,
'KAmp' AS uom,
SUM(ACTUAL_METRIC_VALUE) / COALESCE(NULLIF(COUNT(
CASE
WHEN ACTUAL_METRIC_VALUE <> 0
THEN 1 ELSE NULL END), 0), 1)
AS ytd
FROM SEMANTIC_PROD.RECTIFIER_KPI_VIEW
WHERE LOWER(TRIM(KPI)) = '35ka_rectifier_current'
FROM SEMANTIC_PROD.RECTIFIER_KPI_VIEW
WHERE LOWER(TRIM(KPI)) = '35ka_rectifier_current'
AND DATE BETWEEN '{year_start_date}' AND '{year_end_date}'
GROUP BY 1,2
"""
GROUP BY 1,2) as third_tbl
ON second_tbl.power_availability=third_tbl.power_availability
"""
class TotalAvgCurrent:
""" POWER AVAILABILITY """
QUERY_1 = """
SELECT
SELECT
first_tbl.power_availability,
first_tbl.uom,
first_tbl.norms,
ROUND(first_tbl.on_date :: NUMERIC, 2) on_date,
ROUND(second_tbl.mtd :: NUMERIC, 2) mtd,
ROUND(third_tbl.ytd :: NUMERIC, 2) ytd
FROM
(SELECT
'Total Avg. Current' AS power_availability,
'KAmp' AS uom,
AVG(PLAN_METRIC_VALUE) AS norms,
SUM(ACTUAL_METRIC_VALUE) / COALESCE(NULLIF(COUNT(
CASE WHEN ACTUAL_METRIC_VALUE <> 0 THEN 1
ELSE NULL END), 0), 1) AS on_date
FROM SEMANTIC_PROD.RECTIFIER_KPI_VIEW
WHERE LOWER(TRIM(KPI)) in
('40ka_rectifier_current', '35ka_rectifier_current')
AND DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
GROUP BY 1,2
"""
QUERY_2 = """
SELECT
AND date between '{day_start_date}' AND '{day_end_date}'
group by 1,2) as first_tbl
JOIN
(SELECT
'Total Avg. Current' AS power_availability,
'KAmp' AS uom,
SUM(ACTUAL_METRIC_VALUE) / COALESCE(NULLIF(COUNT(
......@@ -461,12 +647,14 @@ class SterliteRefineryQuery:
FROM SEMANTIC_PROD.RECTIFIER_KPI_VIEW
WHERE LOWER(TRIM(KPI)) in
('40ka_rectifier_current', '35ka_rectifier_current')
AND date between '{month_start_date}' AND '{month_end_date}'
group by 1,2) as second_tbl
AND DATE BETWEEN '{month_start_date}' AND '{month_end_date}'
GROUP BY 1,2
"""
QUERY_3 = """
SELECT
ON first_tbl.power_availability=second_tbl.power_availability
JOIN
(SELECT
'Total Avg. Current' AS power_availability,
'KAmp' AS uom,
SUM(ACTUAL_METRIC_VALUE) / COALESCE(NULLIF(COUNT(
......@@ -476,9 +664,10 @@ class SterliteRefineryQuery:
FROM SEMANTIC_PROD.RECTIFIER_KPI_VIEW
WHERE LOWER(TRIM(KPI)) in
('40ka_rectifier_current', '35ka_rectifier_current')
AND date between '{year_start_date}' AND '{year_end_date}'
group by 1,2) as third_tbl
AND DATE BETWEEN '{year_start_date}' AND '{year_end_date}'
GROUP BY 1,2
ON second_tbl.power_availability=third_tbl.power_availability
"""
class CurrentDensity:
......
......@@ -79,7 +79,9 @@ class SterliteRefineryTemplate:
"YTD",
],
"query": {
"Grid Power Availability": [],
"Grid Power Availability": [
SterliteRefineryQuery.GridPowerAvailability.QUERY_1,
],
"Cir 1 Avg. Rectifier Running Hrs.": [],
"Cir 2 Avg. Rectifier Running Hrs.": [],
"Power Availability to Cir-1": [],
......@@ -87,8 +89,6 @@ class SterliteRefineryTemplate:
"Power Availability to Cell House": [],
"Cir-1 40 KA Rectifier Avg. Current": [
SterliteRefineryQuery.Cir140KARectifierAvgCurrent.QUERY_1,
SterliteRefineryQuery.Cir140KARectifierAvgCurrent.QUERY_2,
SterliteRefineryQuery.Cir140KARectifierAvgCurrent.QUERY_3,
],
"Cir-2 35 KA Rectifier Avg. Current": [
SterliteRefineryQuery.Cir235KARectifierAvgCurrent.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