Commit f53f393e authored by suryakant's avatar suryakant

Merge remote-tracking branch 'origin/develop_suryakant' into develop_suryakant

# Conflicts:
#	scripts/core/handler/event_handler.py
parents d06e70a4 7f2a8b89
custom_report_json = [
{
}
]
custom_report_json = [{}]
"""
This __init__ file contains the configuration settings for the application
"""
import os
import shutil
from pydantic import BaseSettings
from dotenv import load_dotenv
......@@ -15,6 +13,7 @@ class SecurityDetails(BaseSettings):
"""
Configuration class for security token details
"""
secure_cookie: bool
lock_out_time_mins: int
leeway_in_mins: int
......@@ -29,6 +28,7 @@ class ServiceDetails(BaseSettings):
"""
Configuration class for application service details
"""
host_name: str
port_name: str
env: str
......@@ -39,6 +39,7 @@ class LoggingDetails(BaseSettings):
"""
Configuration class for logging database details
"""
log_base_path: str
log_level: str
max_bytes: int
......@@ -54,6 +55,7 @@ class PostgresDetails(BaseSettings):
Config:
env_prefix (str): The environment variable prefix for PostgreSQL settings.
"""
uri: str
host: str
port: str
......
......@@ -19,6 +19,7 @@ class APIConstants:
"""
Constants related to API endpoints
"""
STARTUP = "startup"
SHUTDOWN = "shutdown"
HEALTH_CHECK = "/healthcheck"
......@@ -30,6 +31,7 @@ class CommonConstants:
"""
Common constants used in the application
"""
GET = "GET"
POST = "POST"
CUSTOM_REPORT_TAG = "Event Handler Endpoints"
......@@ -51,6 +53,7 @@ class ReportType:
"""
Constants related to ReportType
"""
REFINERY_REPORT = "refinery_report"
......
......@@ -7,14 +7,11 @@ class GeneralException(Exception):
class ErrorMessages:
"""
""" """
"""
CONNECTION_EXCEPTION = ""
COMMON_MESSAGE = ""
class PostgresDBError:
"""
"""
""" """
......@@ -66,6 +66,7 @@ class CustomReportHandler:
"""
for each_blocks in input_json:
# Iterating each blocks for fetching query
print(each_blocks)
if input_json[each_blocks][CommonConstants.QUERY]:
for each_kpi in input_json[each_blocks][CommonConstants.QUERY]:
......@@ -92,19 +93,17 @@ class CustomReportHandler:
if not temp_data_dict:
# Creating null values if no data
for each_columns in input_json[each_blocks][
CommonConstants.DATA_COLUMN]:
for each_columns in input_json[each_blocks]["data_column"]:
temp_data_dict.update({each_columns: None})
input_json[each_blocks][CommonConstants.DATA].append(temp_data_dict)
input_json[each_blocks]["data"].append(temp_data_dict)
else:
temp_data_dict = dict()
for each_columns in input_json[each_blocks][
CommonConstants.DATA_COLUMN]:
for each_columns in input_json[each_blocks]["data_column"]:
temp_data_dict.update(
{each_columns: None}
)
input_json[each_blocks][CommonConstants.DATA].append(temp_data_dict)
input_json[each_blocks]["data"].append(temp_data_dict)
return input_json
def custom_report_handler(self, input_json):
......@@ -114,7 +113,7 @@ class CustomReportHandler:
"""
status = False
message = "Error generating a message"
data = CommonConstants.DATA
data = "Data"
try:
# if str(input_json.job_type).lower() == ReportType.REFINERY_REPORT:
if str(input_json["job_type"]).lower() == ReportType.REFINERY_REPORT:
......@@ -127,7 +126,7 @@ class CustomReportHandler:
each_blocks = self.get_queries_from_db(
input_json=each_blocks, date_filter=each_date_range
)
print(each_blocks)
# print(each_blocks)
print("=========================================")
break
......
......@@ -17,7 +17,7 @@ from scripts.core.logging.application_logging import logger
from scripts.constants import APIConstants, CommonConstants, figlet
from scripts.core.schemas.api import (
custom_report_input_model,
custom_report_output_model
custom_report_output_model,
)
report_handler_obj = CustomReportHandler()
......@@ -40,8 +40,7 @@ async def shutdown_event():
print("Exiting!")
@event_router.get(
APIConstants.HEALTH_CHECK)
@event_router.get(APIConstants.HEALTH_CHECK)
async def ping():
"""
This function returns the `200 status message`.
......@@ -50,7 +49,8 @@ async def ping():
@event_router.post(
APIConstants.CUSTOM_REPORT_ENDPOINT, response_model=custom_report_output_model)
APIConstants.CUSTOM_REPORT_ENDPOINT, response_model=custom_report_output_model
)
async def custom_report_function(input_json: custom_report_input_model):
"""
Initiate postgres db and create tables
......
......@@ -23,8 +23,11 @@ class PostgresDBUtility:
def create_connection(self, db=None):
_db = db or self.db_name
conn = psycopg2.connect(
database=_db, user=self.username, password=self.password, host=self.host,
port=self.port
database=_db,
user=self.username,
password=self.password,
host=self.host,
port=self.port,
)
logger.debug("Connection established successfully")
return conn
......@@ -125,8 +128,11 @@ class PostgresDBUtility:
cursor.execute(query)
json = cursor.fetchall()
list_of_lists = list(
map(lambda each: [each["plant"], each["line"], each["machine"]],
json))
map(
lambda each: [each["plant"], each["line"], each["machine"]],
json,
)
)
except Exception as e:
logger.error(f"Exception while fetching {str(e)}")
except Exception as e:
......@@ -232,7 +238,8 @@ class PostgresDBUtility:
except Exception as e:
logger.exception(
f"Exception in the check table existance definition{str(e)}")
f"Exception in the check table existance definition{str(e)}"
)
finally:
try:
......
......@@ -11,13 +11,13 @@ class SterliteRefineryTemplate:
"NORMS (Month)",
"ON DATE(Day)",
"MTD",
"YTD"
"YTD",
],
"query": {
"ANODE_AVAILABILITY": [
SterliteRefineryQuery.AnodeAvailability.QUERY_AA,
SterliteRefineryQuery.AnodeAvailability.QUERY_MTD,
SterliteRefineryQuery.AnodeAvailability.QUERY_YTD
SterliteRefineryQuery.AnodeAvailability.QUERY_YTD,
],
"DO CELLS IN OPERATION": [
SterliteRefineryQuery.DOCellsInOperation.QUERY_AA
......@@ -25,34 +25,37 @@ class SterliteRefineryTemplate:
"Total Cells In Operation": [
SterliteRefineryQuery.TotalCellsInOperation.QUERY_1,
SterliteRefineryQuery.TotalCellsInOperation.QUERY_2,
SterliteRefineryQuery.TotalCellsInOperation.QUERY_3
]
SterliteRefineryQuery.TotalCellsInOperation.QUERY_3,
],
},
"data": [],
"data_column": ["anode_availability", "uom",
"norms", "on_date", "mtd",
"ytd"],
"data_column": [
"anode_availability",
"uom",
"norms",
"on_date",
"mtd",
"ytd",
],
"description": "",
"format": ""
"format": "",
},
"SAFETY REPORT": {
"columns": [
"SAFETY REPORT",
"UOM",
"NORMS",
"ON DATE",
"MTD",
"YTD"
],
"columns": ["SAFETY REPORT", "UOM", "NORMS", "ON DATE", "MTD", "YTD"],
"query": [],
"data": [],
"data_column": ["safety_report", "uom",
"norms", "on_date", "mtd",
"ytd"],
"data_column": [
"safety_report",
"uom",
"norms",
"on_date",
"mtd",
"ytd",
],
"additions": [],
"description": "",
"format": ""
}
"format": "",
},
},
{
"POWER AVAILABILITY": {
......@@ -62,7 +65,7 @@ class SterliteRefineryTemplate:
"NORMS",
"ON DATE",
"MTD",
"YTD"
"YTD",
],
"query": [],
"data": [],
......@@ -71,7 +74,7 @@ class SterliteRefineryTemplate:
"ytd"],
"additions": [],
"description": "",
"format": ""
"format": "",
},
"RM ANODE RECEIPT DETAILS": {
"columns": [
......@@ -80,7 +83,7 @@ class SterliteRefineryTemplate:
"MTD",
"YTD",
"Material",
"OPENING STOCK"
"OPENING STOCK",
],
"query": [],
"data": [],
......@@ -88,26 +91,19 @@ class SterliteRefineryTemplate:
"mtd", "ytd", "material", "opening_stock"],
"additions": [],
"description": "",
"format": ""
}
"format": "",
},
},
{
"EFFICIENCIES": {
"columns": [
"EFFICIENCIES",
"UOM",
"NORMS",
"ON DATE",
"MTD",
"YTD"
],
"columns": ["EFFICIENCIES", "UOM", "NORMS", "ON DATE", "MTD", "YTD"],
"query": [],
"data": [],
"data_column": ["efficiencies", "uom", "norms",
"on_date", "mtd", "ytd"],
"additions": [],
"description": "",
"format": ""
"format": "",
},
"BANK / CROP": {
"columns": [
......@@ -115,7 +111,7 @@ class SterliteRefineryTemplate:
"CE (%)",
"THEOR. WEIGHT",
"ACTUAL WEIGHT",
"STRIPPING TIME"
"STRIPPING TIME",
],
"query": [],
"data": [],
......@@ -123,73 +119,51 @@ class SterliteRefineryTemplate:
"actual_weight", "stripping_time"],
"additions": [],
"description": "",
"format": ""
}
"format": "",
},
},
{
"PRODUCTION": {
"columns": [
"PRODUCTION",
"UOM",
"NORMS",
"ON DATE",
"MTD",
"YTD"
],
"columns": ["PRODUCTION", "UOM", "NORMS", "ON DATE", "MTD", "YTD"],
"query": [],
"data": [],
"data_column": ["production", "uom", "norms",
"on_date", "mtd", "ytd"],
"additions": [],
"description": "",
"format": ""
"format": "",
},
"CIRCULATION": {
"columns": [
"CIRCULATION",
"CE%",
"THEOR. WEIGHT",
"ACTUAL WEIGHT"
],
"columns": ["CIRCULATION", "CE%", "THEOR. WEIGHT", "ACTUAL WEIGHT"],
"query": [],
"data": [],
"data_column": ["circulation", "ce", "theor_weight", "actual_weight"],
"additions": [],
"description": "",
"format": ""
}
"format": "",
},
},
{
"FG INVENTORY": {
"columns": [
"FG INVENTORY",
"ON DATE",
"MTD",
"YTD"
],
"columns": ["FG INVENTORY", "ON DATE", "MTD", "YTD"],
"query": [],
"data": [],
"data_column": ["fg_inventory", "on_date",
"mtd", "ytd"],
"additions": [],
"description": "",
"format": ""
"format": "",
},
"PRODUCTION": {
"columns": [
"PRODUCTION",
"ON DATE",
"MTD",
"YTD"
],
"columns": ["PRODUCTION", "ON DATE", "MTD", "YTD"],
"query": [],
"data": [],
"data_column": ["production", "on_date",
"mtd", "ytd"],
"additions": [],
"description": "",
"format": ""
}
"format": "",
},
},
{
"CROP": {
......@@ -198,13 +172,13 @@ class SterliteRefineryTemplate:
"BANKS",
"TOTAL CELLS",
"CELL VOLTAGE (V)",
"T. SHORTS / CELL / CHECK"
"T. SHORTS / CELL / CHECK",
],
"query": [],
"data": [],
"additions": [],
"description": "",
"format": ""
"format": "",
}
},
{
......@@ -215,13 +189,13 @@ class SterliteRefineryTemplate:
"1st CROP - Sttripping time",
"2nd CROP - Change over time",
"3rd CROP",
"CSM Plate Rejection"
"CSM Plate Rejection",
],
"query": [],
"data": [],
"additions": [],
"description": "",
"format": ""
"format": "",
}
},
{
......@@ -232,13 +206,13 @@ class SterliteRefineryTemplate:
"MTD",
"Filtered Volume",
"Total Volume Refinery",
"ON DATE"
"ON DATE",
],
"query": [],
"data": [],
"additions": [],
"description": "",
"format": ""
"format": "",
}
},
{
......@@ -249,29 +223,22 @@ class SterliteRefineryTemplate:
"NORMS",
"ON DATE",
"MTD",
"YTD"
"YTD",
],
"query": [],
"data": [],
"additions": [],
"description": "",
"format": ""
"format": "",
},
"SPECIFIC CONSUMPTION": {
"columns": [
"CONSUMABLES",
"UOM",
"NORMS",
"ON DATE",
"MTD",
"YTD"
],
"columns": ["CONSUMABLES", "UOM", "NORMS", "ON DATE", "MTD", "YTD"],
"query": [],
"data": [],
"additions": [],
"description": "",
"format": ""
}
"format": "",
},
},
{
"ELECTROLYTE COMPOSITION": {
......@@ -281,56 +248,40 @@ class SterliteRefineryTemplate:
"NORMS",
"DATE",
"CIR-1",
"CIR-2"
"CIR-2",
],
"query": [],
"data": [],
"additions": [],
"description": "",
"format": ""
"format": "",
},
"SUSPENDED SOLIDS": {
"columns": [
"SUSPENDED SOLIDS"
],
"columns": ["SUSPENDED SOLIDS"],
"query": [],
"data": [],
"additions": [],
"description": "",
"format": ""
}
"format": "",
},
},
{
"BLEEDING SECTION": {
"columns": [
"BLEEDING SECTION",
"UOM",
"ON DATE",
"MTD",
"YTD"
],
"columns": ["BLEEDING SECTION", "UOM", "ON DATE", "MTD", "YTD"],
"query": [],
"data": [],
"additions": [],
"description": "",
"format": ""
"format": "",
},
"BANK / CROP": {
"columns": [
"BANK / CROP",
"TIME",
"WEIGHT (MT)",
"CELLS",
"READING"
],
"query": [
],
"columns": ["BANK / CROP", "TIME", "WEIGHT (MT)", "CELLS", "READING"],
"query": [],
"data": [],
"additions": [],
"description": "",
"format": ""
}
"format": "",
},
},
{
"DEPARTMENT(M4)": {
......@@ -340,13 +291,13 @@ class SterliteRefineryTemplate:
"EQUIPMENT LOCATION",
"DURATION",
"(MT) PRODUCTION",
"CAUSE OF THE BREAK DOWN"
"CAUSE OF THE BREAK DOWN",
],
"query": [],
"data": [],
"additions": [],
"description": "",
"format": ""
}
"format": "",
}
},
]
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