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
e1c392af
Commit
e1c392af
authored
Oct 14, 2023
by
suryakant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Query Update
parent
a682a952
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
51 additions
and
14 deletions
+51
-14
dev-variables.env
dev-variables.env
+0
-1
scripts/configurations/__init__.py
scripts/configurations/__init__.py
+0
-1
scripts/constants/__init__.py
scripts/constants/__init__.py
+6
-0
scripts/core/db/postgres/custom_report_query.py
scripts/core/db/postgres/custom_report_query.py
+16
-2
scripts/core/handler/event_handler.py
scripts/core/handler/event_handler.py
+15
-5
scripts/core/utilities/postgresql_db_utils.py
scripts/core/utilities/postgresql_db_utils.py
+3
-2
scripts/template/sterlite_report_template.py
scripts/template/sterlite_report_template.py
+11
-3
No files found.
dev-variables.env
View file @
e1c392af
...
@@ -9,7 +9,6 @@ POSTGRES_HOST = 20.219.42.36
...
@@ -9,7 +9,6 @@ POSTGRES_HOST = 20.219.42.36
POSTGRES_PORT = 5786
POSTGRES_PORT = 5786
POSTGRES_USERNAME = svc_sterlite
POSTGRES_USERNAME = svc_sterlite
POSTGRES_PASSWORD = sterliteSvc#1247
POSTGRES_PASSWORD = sterliteSvc#1247
POSTGRES_DATABASE = strelite-datalakedev
# Log Details
# Log Details
LOG_BASE_PATH=logs/
LOG_BASE_PATH=logs/
...
...
scripts/configurations/__init__.py
View file @
e1c392af
...
@@ -60,7 +60,6 @@ class PostgresDetails(BaseSettings):
...
@@ -60,7 +60,6 @@ class PostgresDetails(BaseSettings):
port
:
str
port
:
str
username
:
str
username
:
str
password
:
str
password
:
str
database
:
str
class
Config
:
class
Config
:
env_prefix
=
"POSTGRES_"
env_prefix
=
"POSTGRES_"
...
...
scripts/constants/__init__.py
View file @
e1c392af
...
@@ -65,6 +65,12 @@ class ReportType:
...
@@ -65,6 +65,12 @@ class ReportType:
REFINERY_WORKSHEET_NAME
=
"REFINERY DAILY PERFORMANCE REPORT"
REFINERY_WORKSHEET_NAME
=
"REFINERY DAILY PERFORMANCE REPORT"
class
PostgresConstant
:
""" Constant used in Postgre SQL """
STRELITE_DATALAKE_DEV
=
"strelite-datalakedev"
PROJECT_101__ILENS_AI
=
"project_101__ilens_ai"
figlet
=
"""
figlet
=
"""
____ _ _ _ _
____ _ _ _ _
/ ___| | |_ ___ _ __ | | (_) | |_ ___
/ ___| | |_ ___ _ __ | | (_) | |_ ___
...
...
scripts/core/db/postgres/custom_report_query.py
View file @
e1c392af
...
@@ -3699,3 +3699,17 @@ class SterliteRefineryQuery:
...
@@ -3699,3 +3699,17 @@ class SterliteRefineryQuery:
WHERE
WHERE
DATE = '{day_start_date}'
DATE = '{day_start_date}'
"""
"""
class
BankCrop
:
""" BANK / CROP """
QUERY_1
=
"""
SELECT
"Bank" AS BANK_CROP,
"Date"::VARCHAR AS TIME,
"Op" AS OP,
"Priority" AS PRIORITY,
"Copper Prod" AS COPPER_PROD,
"KA_new" AS KA_NEW
FROM PUBLIC.REFINERY_PRODUCTION_DAY_WISE RPDW
WHERE DATE("Date") = '{day_start_date}'
"""
scripts/core/handler/event_handler.py
View file @
e1c392af
...
@@ -2,7 +2,7 @@ import copy
...
@@ -2,7 +2,7 @@ import copy
import
pandas
as
pd
import
pandas
as
pd
from
datetime
import
datetime
from
datetime
import
datetime
from
scripts.constants
import
ReportType
,
CommonConstants
from
scripts.constants
import
ReportType
,
CommonConstants
,
PostgresConstant
from
scripts.template.sterlite_report_template
import
SterliteRefineryTemplate
from
scripts.template.sterlite_report_template
import
SterliteRefineryTemplate
from
scripts.core.logging.application_logging
import
logger
from
scripts.core.logging.application_logging
import
logger
from
scripts.core.exception.app_exceptions
import
GeneralException
from
scripts.core.exception.app_exceptions
import
GeneralException
...
@@ -76,6 +76,10 @@ class CustomReportHandler:
...
@@ -76,6 +76,10 @@ class CustomReportHandler:
append_flag
=
False
append_flag
=
False
data_list
=
[]
data_list
=
[]
database
=
PostgresConstant
.
STRELITE_DATALAKE_DEV
if
"database"
in
input_json
[
each_blocks
]:
database
=
input_json
[
each_blocks
][
"database"
]
# Iterating each query for each KPI
# Iterating each query for each KPI
if
input_json
[
each_blocks
][
CommonConstants
.
QUERY
][
each_kpi
]:
if
input_json
[
each_blocks
][
CommonConstants
.
QUERY
][
each_kpi
]:
for
each_query
in
\
for
each_query
in
\
...
@@ -95,7 +99,9 @@ class CustomReportHandler:
...
@@ -95,7 +99,9 @@ class CustomReportHandler:
year_end_date
=
date_filter
[
year_end_date
=
date_filter
[
CommonConstants
.
YEAR_END_DATE
])
CommonConstants
.
YEAR_END_DATE
])
response
=
self
.
postgres_db_obj
.
fetch_data
(
query
=
query
)
response
=
self
.
postgres_db_obj
.
\
select_postgres_table
(
query
=
query
,
db
=
database
)[
1
]
if
response
and
"addition"
not
in
input_json
[
each_blocks
]:
if
response
and
"addition"
not
in
input_json
[
each_blocks
]:
if
len
(
response
)
<=
1
:
if
len
(
response
)
<=
1
:
...
@@ -217,6 +223,7 @@ class CustomReportHandler:
...
@@ -217,6 +223,7 @@ class CustomReportHandler:
if
str
(
input_json
[
"job_type"
])
.
lower
()
==
ReportType
.
REFINERY_REPORT
:
if
str
(
input_json
[
"job_type"
])
.
lower
()
==
ReportType
.
REFINERY_REPORT
:
logger
.
info
(
"Generating custom date filter with in the range"
)
logger
.
info
(
"Generating custom date filter with in the range"
)
# Getting custom date range using start date and end date
# Getting custom date range using start date and end date
date_filter
=
self
.
create_custom_date_filter
(
input_json
=
input_json
)
date_filter
=
self
.
create_custom_date_filter
(
input_json
=
input_json
)
...
@@ -234,9 +241,9 @@ class CustomReportHandler:
...
@@ -234,9 +241,9 @@ class CustomReportHandler:
start_row
=
CommonConstants
.
START_ROW
start_row
=
CommonConstants
.
START_ROW
total_column
=
0
total_column
=
0
workbook
=
writer
.
book
workbook
=
writer
.
book
sheet_name
=
datetime
.
strptime
(
each_date_range
[
sheet_name
=
datetime
.
strptime
(
CommonConstants
.
DAY_START_DATE
],
"
%
Y-
%
m-
%
d"
)
.
\
each_date_range
[
CommonConstants
.
DAY_START_DATE
],
strftime
(
"
%
d
%
b
%
Y"
)
"
%
Y-
%
m-
%
d"
)
.
strftime
(
"
%
d
%
b
%
Y"
)
worksheet
=
None
worksheet
=
None
...
@@ -244,6 +251,9 @@ class CustomReportHandler:
...
@@ -244,6 +251,9 @@ class CustomReportHandler:
for
each_blocks
in
report_template
:
for
each_blocks
in
report_template
:
logger
.
info
(
"Fetching each KPI data from queries"
)
logger
.
info
(
"Fetching each KPI data from queries"
)
print
(
"--------------------"
)
print
(
each_blocks
)
print
(
"--
\n
"
)
each_blocks
=
self
.
get_queries_from_db
(
each_blocks
=
self
.
get_queries_from_db
(
input_json
=
each_blocks
,
date_filter
=
each_date_range
input_json
=
each_blocks
,
date_filter
=
each_date_range
)
)
...
...
scripts/core/utilities/postgresql_db_utils.py
View file @
e1c392af
...
@@ -11,17 +11,18 @@ class PostgresDBUtility:
...
@@ -11,17 +11,18 @@ class PostgresDBUtility:
def
__init__
(
self
):
def
__init__
(
self
):
try
:
try
:
logger
.
debug
(
"Meta DB connection initialization"
)
logger
.
debug
(
"Meta DB connection initialization"
)
self
.
cursor_type
=
RealDictCursor
self
.
host
=
postgres_details
.
host
self
.
host
=
postgres_details
.
host
self
.
port
=
postgres_details
.
port
self
.
port
=
postgres_details
.
port
self
.
username
=
postgres_details
.
username
self
.
username
=
postgres_details
.
username
self
.
password
=
postgres_details
.
password
self
.
password
=
postgres_details
.
password
self
.
db_name
=
postgres_details
.
database
self
.
db_name
=
postgres_details
.
database
self
.
cursor_type
=
RealDictCursor
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
error
(
f
"Exception in the Meta DB initialization : {str(e)}"
)
logger
.
error
(
f
"Exception in the Meta DB initialization : {str(e)}"
)
def
create_connection
(
self
,
db
=
None
):
def
create_connection
(
self
,
db
=
None
):
_db
=
db
or
self
.
db_name
_db
=
db
or
self
.
db_name
print
(
"Database ====================================> "
,
_db
)
conn
=
psycopg2
.
connect
(
conn
=
psycopg2
.
connect
(
database
=
_db
,
database
=
_db
,
user
=
self
.
username
,
user
=
self
.
username
,
...
@@ -42,7 +43,7 @@ class PostgresDBUtility:
...
@@ -42,7 +43,7 @@ class PostgresDBUtility:
"""
"""
logger
.
debug
(
f
" SQL QUERY {query}"
)
logger
.
debug
(
f
" SQL QUERY {query}"
)
connection
=
None
connection
=
None
result
=
""
result
=
[]
flag
=
False
flag
=
False
try
:
try
:
connection
=
self
.
create_connection
(
db
)
connection
=
self
.
create_connection
(
db
)
...
...
scripts/template/sterlite_report_template.py
View file @
e1c392af
from
scripts.constants
import
PostgresConstant
from
scripts.core.db.postgres.custom_report_query
import
SterliteRefineryQuery
from
scripts.core.db.postgres.custom_report_query
import
SterliteRefineryQuery
...
@@ -572,10 +573,17 @@ class SterliteRefineryTemplate:
...
@@ -572,10 +573,17 @@ class SterliteRefineryTemplate:
},
},
{
{
"BANK / CROP"
:
{
"BANK / CROP"
:
{
"columns"
:
[
"BANK / CROP"
,
"TIME"
,
"WEIGHT (MT)"
,
"CELLS"
,
"READING"
],
"columns"
:
[
"BANK / CROP"
,
"TIME"
,
"OP"
,
"PRIORITY"
,
"query"
:
{},
"COPPER_PROD"
,
"KA_NEW"
],
"query"
:
{
"BankCrop"
:
[
SterliteRefineryQuery
.
BankCrop
.
QUERY_1
,
]
},
"data"
:
[],
"data"
:
[],
"data_column"
:
[
"bank_crop"
,
"time"
,
"weight"
,
"cells"
,
"reading"
],
"data_column"
:
[
"bank_crop"
,
"time"
,
"op"
,
"priority"
,
"copper_prod"
,
"ka_new"
],
"database"
:
PostgresConstant
.
PROJECT_101__ILENS_AI
},
},
},
},
{
{
...
...
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