def get_data_for_hc1_id_el(self): """ This will return the data and construct the data frame object :return: None """ try: assert self._db_connection, { STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR } queries_list = [ COLOR_CODING_TLE.format(self.sync_time), COLOR_CODING_FURNACE_O2.format(self.sync_time), COLOR_CODING_COT.format(self.sync_time), COLOR_CODING_FURNACE_FEED_FLOW_METER.format(self.sync_time), COLOR_CODING_FURNACE_DILUTION_STEAM_FLOW.format(self.sync_time) ] temp_df = self.get_dataframe(queries_list) if not temp_df.empty: for furnace_name in temp_df.equipment_name.unique(): offline_satatus, g_count, b_count, y_count, r_count, df = self.get_color_count( temp_df[temp_df.equipment_name == furnace_name]) self.HC1_EQUIPMENT_ID_DF = self.HC1_EQUIPMENT_ID_DF.append( self.equipment_level_instrument_drift( offline_satatus, g_count, b_count, y_count, r_count, df), ignore_index=True) else: pass except AssertionError as e: log_error("Exception due to : %s" + str(e))
def get_data_for_hc1_dt_el(self): """ This will return the data and construct the data frame object :return: None """ try: assert self._db_connection, { STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR } queries_list = [ COLOR_CODING_STABILITY_INDEX_DT.format(self.sync_time) ] temp_df = self.get_dataframe(queries_list) if not temp_df.empty: temp_df[CONSOLE_FLAG] = None temp_df[FEATURE_COL] = DEVIATION_TRACKER self.HC1_EQUIPMENT_DT_DF = temp_df.copy() else: pass except AssertionError as e: log_error("Exception due to : %s" + str(e))
def get_data_for_hc1_pt_el(self): """ This will return the data and construct the data frame object for the plant performance tracker :return: None """ try: assert self._db_connection, { STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR } queries_list = [ COLOR_CODING_FURNACE_PERFORMANCE_TRACKER_QUERY.format( self.sync_time) ] temp_df = self.get_dataframe(queries_list) if not temp_df.empty: temp_df[CONSOLE_FLAG] = None temp_df[FEATURE_COL] = PERFORMANCE_TRACKER self.HC1_EQUIPMENT_PT_DF = temp_df.copy() else: pass except AssertionError as e: log_error("Exception due to : %s" + str(e))
def get_hgi_values(self): """ This will return the lat updated and target list and offset value :return: Json Response """ try: assert self._db_connection, { STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR } df_data = pd.DataFrame( self._csql_session.execute( TARGET_HGI_LIST.format(NAME, TABLE_NAME, self.algorithm_name))) dict_data = { "target_hgi": ListofTargetHGI, "offset": None, "last_updated_target": self.get_updated_data_by_algorithm_name(self.algorithm_name) } if not df_data.empty: df = pd.DataFrame.from_dict(json.loads(df_data['value'][0])) for i, row in df.iterrows(): dict_data["offset"] = int(row['HgiDelta']) return JsonResponse(dict_data, safe=False) except AssertionError as e: log_error("Assertion error due to : %s" + str(e)) return asert_res(e) except Exception as e: log_error("Exception due to : %s" + str(e)) return json_InternalServerError
def get_algorithms_details(self): """ This will return all the list of the algorithm in json format and algorithm status from the Database . :return: Json Responses """ try: assert self._db_connection, { STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR } final_response = { "algorithm_status": self.get_algorithm_status(), "algorithm_name": self.get_algorithm_list() } return JsonResponse(final_response, safe=False) except AssertionError as e: log_error("Exception due to : %s", e) return JsonResponse({MESSAGE_KEY: e.args[0][MESSAGE_KEY]}, status=e.args[0][STATUS_KEY]) except Exception as e: log_error(traceback.format_exc()) return JsonResponse( {MESSAGE_KEY: EXCEPTION_CAUSE.format(traceback.format_exc())}, status=HTTP_500_INTERNAL_SERVER_ERROR)
def add_user(self): """ This function will add the user details :return: Json payload """ try: assert self._db_connection, { STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR } if self.__is_user_not_authorised(): return JsonResponse({MESSAGE_KEY: NOT_AUTHORISED}, status=HTTP_401_UNAUTHORIZED) return self.__add_user_query() except AssertionError as e: log_error("Exception due to : %s" + str(e)) return JsonResponse({MESSAGE_KEY: e.args[0][MESSAGE_KEY]}, status=e.args[0][STATUS_KEY]) except Exception as e: log_error(traceback.format_exc()) return JsonResponse( {MESSAGE_KEY: EXCEPTION_CAUSE.format(traceback.format_exc())}, status=HTTP_500_INTERNAL_SERVER_ERROR)
def update_case(self): """ This will data on the bases of the eqipment and console name.This will give the overview for the dyanmic benchmaraking features :return: Json Response """ try: assert self._db_connection, { STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR} self._psql_session.execute(MAKE_FALSE_POSTGRES_QUERY.format(self.console, self.equipment)) self._psql_session.execute(MAKE_TRUE_POSTGRES_QUERY.format(self.console, self.equipment, self.case)) return JsonResponse({MESSAGE_KEY: UPDATED_SUCCESSFULLY}, safe=False) except AssertionError as e: log_error("Exception due to : %s" + str(e)) return JsonResponse({MESSAGE_KEY: e.args[0][MESSAGE_KEY]}, status=e.args[0][STATUS_KEY]) except Exception as e: log_error(traceback.format_exc()) return JsonResponse({MESSAGE_KEY: EXCEPTION_CAUSE.format( traceback.format_exc())}, status=HTTP_500_INTERNAL_SERVER_ERROR)
def get_cases_values(self): """ This will return the cases for the selected console and equipment :return: Json Response """ try: assert self._db_connection, { STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR } self._psql_session.execute( CASES_POSTGRES_QUERY.format(self.console, self.equipment)) df = pd.DataFrame(self._psql_session.fetchall()) if df.shape[0]: return JsonResponse(yaml.safe_load(df.to_json(orient=RECORDS)), safe=False) return JsonResponse([], safe=False) except AssertionError as e: log_error("Exception due to : %s" + str(e)) return JsonResponse({MESSAGE_KEY: e.args[0][MESSAGE_KEY]}, status=e.args[0][STATUS_KEY]) except Exception as e: log_error(traceback.format_exc()) return JsonResponse( {MESSAGE_KEY: EXCEPTION_CAUSE.format(traceback.format_exc())}, status=HTTP_500_INTERNAL_SERVER_ERROR)
def get_algorithms_by_name_and_type(self, algorithm_name): """ This will return all the list of the algorithm in json format from the Database . :return: Json Responses """ try: assert self._db_connection, { STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR} final_response = {PARAMS: self.get_param_data_by_algorithm_name(algorithm_name), FILES: self.get_file_data_by_algorithm_name(algorithm_name)} return JsonResponse(final_response, safe=False) except AssertionError as e: log_error("Exception due to : %s", e) return JsonResponse({MESSAGE_KEY: e.args[0][MESSAGE_KEY]}, status=e.args[0][STATUS_KEY]) except Exception as e: log_error(traceback.format_exc()) return JsonResponse({MESSAGE_KEY: EXCEPTION_CAUSE.format( traceback.format_exc())}, status=HTTP_500_INTERNAL_SERVER_ERROR)
def get_ext_and_perf_tags(self, dict_data): try: self._psql_session.execute( FURNACES_CONFIG_EXTERNAL_TAGS.format( self.query_params[IS_ACTIVE], self.query_params[FEED_NAME])) df = pd.DataFrame(self._psql_session.fetchall()) dict_data[ "external_tags"] = dict_data["external_tags"] + yaml.safe_load( df.to_json(orient=RECORDS)) except Exception as e: log_error('Exception due to get_ext_and_perf_tags Function: %s' + str(e)) try: self._psql_session.execute(FURNACES_CONFIG_PERFORM_TAGS) df = pd.DataFrame(self._psql_session.fetchall()) dict_data["performace_tags"] = dict_data[ "performace_tags"] + yaml.safe_load(df.to_json(orient=RECORDS)) except Exception as e: log_error('Exception due to get_ext_and_perf_tags Function: %s' + str(e))
def get_data_for_hc1_db_el(self): """ This will return the data and construct the data frame object for the Dynamic bench marking :return: None """ try: assert self._db_connection, { STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR } queries_list = [COLOR_LBT.format(self.sync_time)] temp_df = self.get_dataframe(queries_list) # Added the external target code queries_list_ext = [EXT_COLOR_LBT.format(self.sync_time)] ext_df = self.get_dataframe(queries_list_ext) if not ext_df.empty: self.HC1_EQUIPMENT_ET_DF = self.HC1_EQUIPMENT_ET_DF.append( ext_df, ignore_index=True) if not temp_df.empty: for furnace_name in temp_df.equipment_name.unique(): offline_satatus, g_count, b_count, y_count, r_count, df = self.get_color_count( temp_df[temp_df.equipment_name == furnace_name]) self.HC1_EQUIPMENT_DB_DF = self.HC1_EQUIPMENT_DB_DF.append( self.equipment_level_DB(offline_satatus, g_count, b_count, y_count, r_count, df), ignore_index=True) else: pass except AssertionError as e: log_error("Exception due to : %s" + str(e))
def get_data_for_hc1_eh_el(self): """ This will return the data and construct the data frame object for the equipment health :return: None """ try: assert self._db_connection, { STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR } queries_list = [ COLOR_CODING_FURNACE_RUN_LENGTH.format(self.sync_time) ] temp_df = self.get_dataframe(queries_list) if not temp_df.empty: temp_df[CONSOLE_FLAG] = None temp_df[FEATURE_COL] = EQUIPMENT_HEALTH self.HC1_EQUIPMENT_EH_DF = temp_df.copy() else: pass except AssertionError as e: log_error("Exception due to : %s" + str(e))
def get_furnaces(self): """ :return: Json Response """ try: assert self._db_connection, { STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR } dict_data = self.get_dict_data_values() self.get_ext_and_perf_tags(dict_data) return JsonResponse(dict_data, safe=False) except AssertionError as e: log_error('Exception due to : %s' + str(e)) return JsonResponse({MESSAGE_KEY: e.args[0][MESSAGE_KEY]}, status=e.args[0][STATUS_KEY]) except Exception as e: log_error(traceback.format_exc()) return JsonResponse( {MESSAGE_KEY: EXCEPTION_CAUSE.format(traceback.format_exc())}, status=HTTP_500_INTERNAL_SERVER_ERROR)
def get_hot_console1_color_coding_values(): # *args, **kwargs obj = None try: UnitLevel() except Exception as e: log_error("Exception due to : %s" + str(e)) finally: if obj: del obj
def get_logout_user(self): try: token = self._request_payload[TOKEN] role = jwt.decode(token, verify=False) obj = HashingSalting() if role['role'] == 'Admin': obj.decreasing_admin_login_count() if role['role'] == 'Non Admin': obj.decreasing_Non_Admin_login_count() if role['role'] == 'Super Admin': obj.decreasing_super_Admin_login_count() return JsonResponse({MESSAGE_KEY: "Logout Successfully"}) except Exception as e: log_error(e)
def update_user_count(self): """ This function will update the count of the user :return: Json payload """ try: assert self._db_connection, {STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR} return self.__update_user_count_query() except AssertionError as e: log_error("Exception due to : %s" + str(e)) return asert_res(e) except Exception as e: log_error("Exception due to : %s" + str(e)) return json_InternalServerError
def get_dataframe(self, queries_list): """ This function will query from the Database for the provided query and will make dataframe and return :param queries_list: list of queries :return: dataframe """ temp_df = pd.DataFrame() for query in queries_list: try: self._psql_session.execute(query) temp_df = temp_df.append(pd.DataFrame( self._psql_session.fetchall()), ignore_index=True) except Exception as e: log_error("Exception due to : %s" + str(e)) return temp_df
def license_expiry(self): try: self._psql_session.execute(LICENSE_DETAILS) license_expiry = self._psql_session.fetchone() license_end_date = (license_expiry['end_date'] - datetime.now()).days if CONFIGURATION_DATE_1 == license_end_date: dict_data = { "days_remaining": license_end_date, "notify_status": True, "message": "The license is expected to expire in the next {} days. Please " "contact your iSense4i application administrator for the renewal of " "the platform subscription.".format(license_end_date) } elif license_end_date <= CONFIGURATION_DATE_2: dict_data = { "days_remaining": license_end_date, "notify_status": True, "message": "The license is expected to expire in the next {} days. Please " "contact your iSense4i application administrator for the renewal of " "the platform subscription.".format(license_end_date) } else: dict_data = { "days_remaining": license_end_date, "notify_status": False, "message": "The license is expected to expire in the next {} days. Please " "contact your iSense4i application administrator for the renewal of " "the platform subscription.".format(license_end_date) } return JsonResponse(dict_data, safe=False) except Exception as e: log_error(e)
def __init__(self): """ This will call the parent class to validate the connection and initialize the values """ self.sync_time = _GetSyncTime().get_sync_timestamp() try: self.connection = psycopg2.connect( user=DATABASE_CONFIG[DEFAULT][USER], password=DATABASE_CONFIG[DEFAULT][PASSWORD], host=DATABASE_CONFIG[DEFAULT][HOST], port=DATABASE_CONFIG[DEFAULT][PORT], database=DATABASE_CONFIG[DEFAULT][NAME]) self._psql_session = self.connection.cursor( cursor_factory=RealDictCursor) self._db_connection = True except Exception as e: log_error("Exception due to : %s" + str(e)) self._db_connection = False
def update_price_input(self): """ :return: Json Response """ try: assert self._db_connection, { STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR } try: for i in self._request_payload: self._psql_session.execute( UPDATE_PRICE_INPUT.format(i['price'], i["density LB/Gal"], i["density LB/Bbl"], i["price_unit"], i["tag_name"])) except Exception as e: log_error('Exception occurs due to: %s' + str(e)) return JsonResponse({MESSAGE_KEY: UPDATED_SUCCESSFULLY}) except AssertionError as e: log_error('Exception in update_price_input api Function: %s' + str(e)) return JsonResponse({MESSAGE_KEY: e.args[0][MESSAGE_KEY]}, status=e.args[0][STATUS_KEY]) except Exception as e: log_error(traceback.format_exc()) return JsonResponse( {MESSAGE_KEY: EXCEPTION_CAUSE.format(traceback.format_exc())}, status=HTTP_500_INTERNAL_SERVER_ERROR)
def update_targets(self): """ This will return all the list of the targets in json format from the database . :return: Json Response """ try: assert self._db_connection, { STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR } LAST_MODIFIED_DATE = str(round(time.time() * 1000)) try: query = TARGET_HGI_UPDATE.format( NAME, TABLE_NAME, self._request_payload[PARAM_VALUE], LAST_MODIFIED_DATE, FLAG, self.algorithm_name) self._csql_session.execute(query) except Exception as e: log_error("Exception due to : %s" + str(e)) return asert_res(e) return JsonResponse(sucess_message, safe=False) except AssertionError as e: log_error("Assertion error due to : %s" + str(e)) return asert_res(e) except Exception as e: log_error("Exception due to : %s" + str(e)) return json_InternalServerError
def get_price_input__data(self, parameter=None): """ :return: Json Response """ try: assert self._db_connection, { STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR } result = [] try: self._psql_session.execute(get_price_input_data) df = pd.DataFrame(self._psql_session.fetchall()) if not df.empty: result_data = df['json_build_object'][0] result.append(result_data) except Exception as e: log_error('Exception occurs due to: %s' + str(e)) return JsonResponse(result, safe=False) except AssertionError as e: log_error('Exception in get_price_input api Function: %s' + str(e)) return JsonResponse({MESSAGE_KEY: e.args[0][MESSAGE_KEY]}, status=e.args[0][STATUS_KEY]) except Exception as e: log_error(traceback.format_exc()) return JsonResponse( {MESSAGE_KEY: EXCEPTION_CAUSE.format(traceback.format_exc())}, status=HTTP_500_INTERNAL_SERVER_ERROR)
def get_furnaces(self): """ :return: Json Response """ try: assert self._db_connection, { STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR } self.sync_time = None data = [] temp = [] try: self._psql_session.execute(NON_FURNACES_NAME) df = pd.DataFrame(self._psql_session.fetchall()) temp = yaml.safe_load(df.to_json(orient=RECORDS)) except Exception as e: log_error('Exception due to get_furnaces Function: %s' + str(e)) return JsonResponse(temp, safe=False) except AssertionError as e: log_error('Exception due to get_furnaces Function: %s' + str(e)) return JsonResponse({MESSAGE_KEY: e.args[0][MESSAGE_KEY]}, status=e.args[0][STATUS_KEY]) except Exception as e: log_error(traceback.format_exc()) return JsonResponse( {MESSAGE_KEY: EXCEPTION_CAUSE.format(traceback.format_exc())}, status=HTTP_500_INTERNAL_SERVER_ERROR)
def get_values(self): try: assert self._db_connection, { STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR } temp = [] if self.query_params: try: self._psql_session.execute( FEEDS_CONFIG_FURNACE_NAME.format( self.query_params[TYPE_REQUEST])) df = pd.DataFrame(self._psql_session.fetchall()) temp = yaml.safe_load(df.to_json(orient=RECORDS)) except Exception as e: log_error('Exception due to get_values Function: %s' + str(e)) return JsonResponse(temp, safe=False) except AssertionError as e: log_error('Exception due to get_values Function: %s' + str(e)) return JsonResponse({MESSAGE_KEY: e.args[0][MESSAGE_KEY]}, status=e.args[0][STATUS_KEY]) except Exception as e: log_error(traceback.format_exc()) return JsonResponse( {MESSAGE_KEY: EXCEPTION_CAUSE.format(traceback.format_exc())}, status=HTTP_500_INTERNAL_SERVER_ERROR)
def get_update_equip_query(self): if self.query_params: try: equipment = self.query_params[EQUIPMENT].split(",") body = self.req_body feed_name = self.query_params[FEED_NAME] is_active = self.query_params[IS_ACTIVE] self.update_equip(body, equipment, feed_name, is_active) except Exception as e: log_error( 'Exception due to get_update_equip_query Function: %s' + str(e)) return JsonResponse({"message": "Updated Successfully"}, status=200, safe=False) else: return JsonResponse({"message": "Error in updating"}, status=404, safe=False)
def change_password_user(self): """ This function will change the user details :return: Json payload """ try: assert self._db_connection, { STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR } return self.__change_user_password_query() except AssertionError as e: log_error("Exception due to : %s" + str(e)) return JsonResponse({MESSAGE_KEY: e.args[0][MESSAGE_KEY]}, status=e.args[0][STATUS_KEY]) except Exception as e: log_error(traceback.format_exc()) return JsonResponse( {MESSAGE_KEY: EXCEPTION_CAUSE.format(traceback.format_exc())}, status=HTTP_500_INTERNAL_SERVER_ERROR)
def get_datafor_coldconsole1(self, dict_data): if self.console == COLD_CONSOLE_1_VALUE and self.get_value == 3: try: """ Surface condenser data for the ['GB-201', 'GB-202', 'GB-501', 'GB-601'] in the instrument drift feature """ self._psql_session.execute(CONSOLE_SURFACE_CONDENSER_ID) df = pd.DataFrame(self._psql_session.fetchall()) dict_data[INSTRUMENT_DRIFT]["data"] = dict_data[ INSTRUMENT_DRIFT]["data"] + yaml.safe_load( df.to_json(orient=RECORDS)) except Exception as e: log_error("Exception due to : %s" + str(e)) try: self._psql_session.execute( CONSOLE_EXCHANGER_HEALTH_MONITORING_QUERY) df = pd.DataFrame(self._psql_session.fetchall()) dict_data[EQUIPMENT_HEALTH]["data"] = dict_data[ EQUIPMENT_HEALTH]["data"] + yaml.safe_load( df.to_json(orient=RECORDS)) except Exception as e: log_error("Exception due to : %s" + str(e))
def update_external_targets(self): """ :return: Json payload """ try: assert self._db_connection, { STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR } return self.__update_external_query() except AssertionError as e: log_error("Exception due to update_external_targets Function: %s", e) return JsonResponse({MESSAGE_KEY: e.args[0][MESSAGE_KEY]}, status=e.args[0][STATUS_KEY]) except Exception as e: log_error(traceback.format_exc()) return JsonResponse( {MESSAGE_KEY: EXCEPTION_CAUSE.format(traceback.format_exc())}, status=HTTP_500_INTERNAL_SERVER_ERROR)
def get_values(self, date_time=None): """ This will return the data on the bases of the unit and console name for all the features from the Database . :return: Json Response """ try: assert self._db_connection, { STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR } COLOR_CODING_GRAPH = "select * from color_coding_graph where console_name = '{}'" COLOR_CODING_TABULAR = "select * from color_coding_tabular where console_name = '{}'" """ Color Coding for graph data """ dict_data = self.compose_dict_data_object() self.set_graphdata_colorcoding(COLOR_CODING_GRAPH, dict_data) """ Color Coding for tabular data """ self.set_tabulardata_colorcoding(COLOR_CODING_TABULAR, dict_data) """ 1. This condition will be true when it will request is for not hot console 1 2. When it is true this will give the data for the Deviation Tracker algo which is only aplicable on Hot Console 2 , Cold Console 1 , Cold Console 2 """ # self.get_datafor_deviationtracker(dict_data) """ If the request is for the hot console 1 . it will get the data for COT Effulent Analyzer and TLE Algorithm """ self.get_datafor_hotconse1(dict_data) self.get_datafor_hotconsole2(COLOR_CODING_GRAPH, COLOR_CODING_TABULAR, dict_data) # self.get_datafor_coldconsole1(dict_data) # self.get_datafor_coldconsole2(dict_data) return JsonResponse(dict_data, safe=False) except AssertionError as e: log_error("Exception due to : %s" + str(e)) return JsonResponse({MESSAGE_KEY: e.args[0][MESSAGE_KEY]}, status=e.args[0][STATUS_KEY]) except Exception as e: log_error('Exception due to : %s' + str(e)) log_error(traceback.format_exc()) return JsonResponse( {MESSAGE_KEY: EXCEPTION_CAUSE.format(traceback.format_exc())}, status=HTTP_500_INTERNAL_SERVER_ERROR)
def clear_notifications(self): """ This will get query from the Database for LBT algo :return: Json Response """ try: assert self._db_connection, { STATUS_KEY: HTTP_500_INTERNAL_SERVER_ERROR, MESSAGE_KEY: DB_ERROR } self._psql_session.execute( CHECK_AUTHENTICATION_QUERY.format( self.loggedin_userid_details[LOGIN_ID])) user = pd.DataFrame(self._psql_session.fetchall()) if not self._psql_session.rowcount: return JsonResponse( {MESSAGE_KEY: "LOGIN ID NOT REGISTER WITH US"}, status=HTTP_400_BAD_REQUEST) self._psql_session.execute( GET_PERMISSION.format(user['user_type'].iloc[0])) permission = pd.DataFrame(self._psql_session.fetchall()) if not permission.empty: permissions = list(permission["feature"]) else: permissions = [] if 'Notification Clear Functionality' in permissions: for each in self._request_payload: try: clear_notification = CLEAR_NOTIFICATIONS.format( TAG_NAME, TIMESTAMP, USER_ID, each[TAG_NAME], each[TIMESTAMP], self.loggedin_userid_details[LOGIN_ID]) self._psql_session.execute(clear_notification) except Exception as e: log_error("Exception occurred due to" + str(e)) return json_InternalServerError return JsonResponse( {"MESSAGE": "NOTIFICATIONS SUCCESSFULLY CLEARED!"}, safe=False) else: return JsonResponse({MESSAGE_KEY: "FORBIDDEN ERROR"}, status=HTTP_403_FORBIDDEN) except AssertionError as e: log_error("Exception occurred due to" + str(e)) return asert_res(e) except Exception as e: log_error("Exception occurred due to" + str(e)) return json_InternalServerError