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
10e995be
Commit
10e995be
authored
Oct 11, 2023
by
suryakant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sterlite Custom Report Updates
parent
36223b60
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
269 additions
and
80 deletions
+269
-80
scripts/core/db/postgres/custom_report_query.py
scripts/core/db/postgres/custom_report_query.py
+266
-77
scripts/template/sterlite_report_template.py
scripts/template/sterlite_report_template.py
+3
-3
No files found.
scripts/core/db/postgres/custom_report_query.py
View file @
10e995be
...
...
@@ -337,10 +337,161 @@ class SterliteRefineryQuery:
GROUP BY 1,2,3
"""
class
GridPowerAvailability
:
""" POWER AVAILABILITY """
QUERY_1
=
"""
SELECT
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,
...
...
@@ -351,11 +502,12 @@ class SterliteRefineryQuery:
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
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(
...
...
@@ -365,11 +517,14 @@ class SterliteRefineryQuery:
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
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(
...
...
@@ -379,14 +534,27 @@ class SterliteRefineryQuery:
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
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
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,
...
...
@@ -399,10 +567,11 @@ class SterliteRefineryQuery:
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
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(
...
...
@@ -414,10 +583,13 @@ class SterliteRefineryQuery:
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
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(
...
...
@@ -429,13 +601,27 @@ class SterliteRefineryQuery:
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
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,
...
...
@@ -446,12 +632,12 @@ class SterliteRefineryQuery:
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) as first_tbl
AND DATE BETWEEN '{day_start_date}' AND '{day_end_date}'
GROUP BY 1,2
"""
QUERY_2
=
"""
SELECT
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
:
...
...
scripts/template/sterlite_report_template.py
View file @
10e995be
...
...
@@ -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
,
...
...
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