Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
trends_dashboard
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
trends_dashboard
Commits
78c28285
Commit
78c28285
authored
Mar 05, 2024
by
suryakant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Trends Dashboard
parent
e5e4f7df
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
129 additions
and
3 deletions
+129
-3
.env
.env
+1
-0
scripts/configurations/__init__.py
scripts/configurations/__init__.py
+1
-0
scripts/constants/__init__.py
scripts/constants/__init__.py
+16
-0
scripts/core/db/postgres/psql_query.py
scripts/core/db/postgres/psql_query.py
+60
-1
scripts/core/handler/trends_handler.py
scripts/core/handler/trends_handler.py
+49
-2
scripts/core/schemas/api/trends_schema.py
scripts/core/schemas/api/trends_schema.py
+1
-0
scripts/core/service/trends_service.py
scripts/core/service/trends_service.py
+1
-0
No files found.
.env
View file @
78c28285
...
...
@@ -4,6 +4,7 @@ PORT = 80
# POSTGRES DETAILS
POSTGRES_URI = postgresql://admin:UtAdm#Post265399@20.221.119.96:5335/project_101__ilens_assistant
POSTGRES_MASTER_TBL = public.trends_master_tbl_
# LOG DETAILS
LOG_BASE_PATH=logs/
...
...
scripts/configurations/__init__.py
View file @
78c28285
...
...
@@ -26,6 +26,7 @@ class PostgresDetails(BaseSettings):
"""
uri
:
str
master_tbl
:
str
class
Config
:
env_prefix
=
"POSTGRES_"
...
...
scripts/constants/__init__.py
View file @
78c28285
...
...
@@ -44,6 +44,22 @@ class Constants:
VALUES
=
"values"
FILTER_NAME
=
"filter_name"
MAPPING_JSON
=
{
0
:
"function"
,
1
:
"form"
,
2
:
"l1"
,
3
:
"l2"
,
4
:
"l3"
,
5
:
"l4"
,
6
:
"l5"
,
7
:
"l6"
,
8
:
"l7"
,
9
:
"l8"
,
10
:
"l9"
,
11
:
"l10"
,
}
class
LoggerConstants
:
LOGGER_1
=
""
scripts/core/db/postgres/psql_query.py
View file @
78c28285
from
scripts.constants
import
Constants
from
scripts.configurations
import
postgres_details
from
sqlalchemy
import
select
,
and_
,
cast
,
Text
...
...
@@ -9,6 +9,65 @@ def get_unique_departments(table):
)
.
distinct
()
def
get_filter_query
(
current_level
,
department
=
None
,
function
=
None
,
form
=
None
,
filter_value
=
None
,
table
=
None
):
query
=
None
if
current_level
and
current_level
==
0
:
query
=
f
"""
SELECT
DISTINCT FUNCTION
FROM
{table}
WHERE
DEPARTMENT='{department}'
ORDER BY
FUNCTION
"""
elif
current_level
and
current_level
==
1
:
query
=
f
"""
SELECT
DISTINCT FORM
FROM
{table}
WHERE
DEPARTMENT='{department}'
AND FUNCTION='{function}'
ORDER BY
FORM
"""
elif
current_level
and
current_level
>=
2
:
current_level
-=
1
where_clause
=
""
if
current_level
>=
2
:
where_clause
=
f
"""
AND FILTER ->> 'l{current_level - 1}-value' = '{filter_value}'
"""
query
=
f
"""
SELECT
DISTINCT (FILTER - >> 'l{current_level}-name') AS L{current_level}_NAME,
(FILTER - >> 'l{current_level}-value') AS L{current_level}_VALUE
FROM
{table}
WHERE
DEPARTMENT='{department}'
AND FUNCTION='{function}'
AND FORM='{form}'
{where_clause}
ORDER BY
L{current_level}_NAME
"""
return
query
def
get_unique_function
(
table
,
department
):
return
select
(
table
.
function
.
label
(
Constants
.
DATA
)
...
...
scripts/core/handler/trends_handler.py
View file @
78c28285
import
copy
from
datetime
import
datetime
from
scripts.configurations
import
postgres_details
from
scripts.constants
import
Constants
from
scripts.core.db.postgres
import
database_init
from
scripts.core.db.postgres.psql_query
import
(
get_unique_departments
,
get_unique_function
,
get_unique_form
,
get_unique_filters
get_unique_form
,
get_unique_filters
,
get_filter_query
)
from
scripts.core.schemas.postgres
import
TableObject
from
scripts.core.logging.application_logging
import
logger
...
...
@@ -19,7 +21,7 @@ class TrendsDashboardHandler:
PepsiCo metrics.
"""
def
get_trends_metadata
(
self
,
request_data
):
def
get_trends_metadata
_old
(
self
,
request_data
):
"""
get_trends_metadata
"""
...
...
@@ -85,6 +87,51 @@ class TrendsDashboardHandler:
return
final_metadata_json
def
get_trends_metadata
(
self
,
request_data
):
"""
get_trends_metadata
"""
final_metadata_json
=
dict
(
values
=
[]
)
print
(
request_data
)
logger
.
info
(
"Database initialization"
)
db_init
=
database_init
()
# Creating table object
trends_master_tbl_obj
=
TableObject
(
db
=
db_init
,
table_name
=
TrendsMasterTable
)
if
request_data
.
current_level
:
filter_query
=
get_filter_query
(
current_level
=
request_data
.
current_level
,
department
=
request_data
.
department
,
function
=
request_data
.
function
,
form
=
request_data
.
form
,
filter_value
=
None
,
table
=
postgres_details
.
master_tbl
)
else
:
filter_query
=
get_unique_departments
(
table
=
TrendsMasterTable
)
# Getting response from the Trends Master Table
response_data
=
trends_master_tbl_obj
.
execute_query
(
query
=
filter_query
)
if
response_data
:
for
each_metadata
in
response_data
:
# Create a JSON for UI
print
(
each_metadata
)
final_metadata_json
[
Constants
.
FILTER_NAME
]
=
"filter_name"
return
final_metadata_json
def
get_trends_data
(
self
,
request_data
):
"""
Docstring
...
...
scripts/core/schemas/api/trends_schema.py
View file @
78c28285
...
...
@@ -9,6 +9,7 @@ class DashboardFilterInput(BaseModel):
department
:
Optional
[
str
]
=
None
function
:
Optional
[
str
]
=
None
form
:
Optional
[
str
]
=
None
current_level
:
Optional
[
str
]
=
None
class
DashboardFilterOutput
(
BaseModel
):
...
...
scripts/core/service/trends_service.py
View file @
78c28285
...
...
@@ -56,6 +56,7 @@ async def dashboard_metadata(
"""
try
:
trends_obj
=
TrendsDashboardHandler
()
print
(
request_data
)
return
trends_obj
.
get_trends_metadata
(
request_data
=
request_data
)
except
Exception
as
err
:
logger
.
exception
(
...
...
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