def connect_to_server(server_name='RAPP1'): piServers = PIServers() if piServers.Contains(server_name): piServers.DefaultPIServer = piServers[server_name]; piServer = piServers.DefaultPIServer else: piServer = piServers.Add(server_name) piServers.DefaultPIServer = piServers[server_name]; piServer = piServers.DefaultPIServer logging.log_message(pulpsdkpipath,'Server in use: {}'.format(server_name)) print('Server in use: {}'.format(server_name)) return piServer
def tag_2_kraft_kpi_info(dataset, pulp_kpi_calc_logfile_path): ''' ''' #### Production kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code'] == "RPL.111XC0003:afc".lower()) try: dataset.loc[dataset.index[kpi_main_idx], ['kpi_category_id', 'kpi_id']] = [1, 1] dataset.loc[dataset.index[kpi_main_idx], 'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0002:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.433FQ1260.F:Y_DAY".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.422YI5139-YD:value".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_4'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0005:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_5'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0006:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_6'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0007:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_7'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0008:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_8'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) #Hema Entries kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0221:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_15'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) except: error_message = "Production tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### ClO2 Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code'] == "RPL.111XC0017:afc".lower()) try: dataset.loc[dataset.index[kpi_main_idx], ['kpi_category_id', 'kpi_id']] = [2, 2] dataset.loc[dataset.index[kpi_main_idx], 'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0018:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0019:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) except: error_message = "ClO2 consumption tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### ClO2 Total Active Cl2 kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code'] == "RPL.111XC0023:afc".lower()) try: dataset.loc[dataset.index[kpi_main_idx], ['kpi_category_id', 'kpi_id']] = [2, 3] dataset.loc[dataset.index[kpi_main_idx], 'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0024:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0025:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0251:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_15'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) # Monthly Consumptions kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0252:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_1_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0254:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0256:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0207:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_4_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) except: error_message = "ClO2 Total Active Cl2 tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Defoamer kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code'] == "RPL.111XC0170:afc".lower()) try: dataset.loc[dataset.index[kpi_main_idx], ['kpi_category_id', 'kpi_id']] = [2, 4] dataset.loc[dataset.index[kpi_main_idx], 'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0171:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0172:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0173:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_4'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0202:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_15'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0202:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_15'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) except: error_message = "Defoamer tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### H2O2 Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code'] == "RPL.111XC0020:afc".lower()) try: dataset.loc[dataset.index[kpi_main_idx], ['kpi_category_id', 'kpi_id']] = [2, 5] dataset.loc[dataset.index[kpi_main_idx], 'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0021:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0022:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0194:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_15'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) # Monthly Consumptions kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0226:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_1_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0228:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0230:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) except: error_message = "H2O2 tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### NaOH(Own) Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code'] == "RPL.111XC0032:afc".lower()) try: dataset.loc[dataset.index[kpi_main_idx], ['kpi_category_id', 'kpi_id']] = [2, 6] dataset.loc[dataset.index[kpi_main_idx], 'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0033:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0034:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) except: error_message = "NaOH(Own) tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### NaOH(Purchase) Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code'] == "RPL.111XC0035:afc".lower()) try: dataset.loc[dataset.index[kpi_main_idx], ['kpi_category_id', 'kpi_id']] = [2, 7] dataset.loc[dataset.index[kpi_main_idx], 'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0036:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0037:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) except: error_message = "NaOH(Purchase) tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### NaOH(Total) Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code'] == "RPL.111XC0038:afc".lower()) try: dataset.loc[dataset.index[kpi_main_idx], ['kpi_category_id', 'kpi_id']] = [2, 8] dataset.loc[dataset.index[kpi_main_idx], 'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0039:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0040:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0197:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_15'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) # Monthly Consumptions kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0243:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_1_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0245:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0247:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) except: error_message = "NaOH(Total) tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Oxygen Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code'] == "RPL.111XC0026:afc".lower()) try: dataset.loc[dataset.index[kpi_main_idx], ['kpi_category_id', 'kpi_id']] = [2, 9] dataset.loc[dataset.index[kpi_main_idx], 'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0027:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0028:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0198:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_15'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) except: error_message = "Oxygen tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Sulfuric_Acid (H2SO4) Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code'] == "RPL.111XC0029:afc".lower()) try: dataset.loc[dataset.index[kpi_main_idx], ['kpi_category_id', 'kpi_id']] = [2, 10] dataset.loc[dataset.index[kpi_main_idx], 'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0030:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0031:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) except: error_message = "Sulfuric Acid (H2SO4) tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### White Liqour Consumption (m3/ADt) kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code'] == "RPL.111XC0009:afc".lower()) try: dataset.loc[dataset.index[kpi_main_idx], ['kpi_category_id', 'kpi_id']] = [2, 11] dataset.loc[dataset.index[kpi_main_idx], 'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0010:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0011:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0012:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_4'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0201:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_15'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) # monthly consumptions kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0234:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_1_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0236:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0238:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0240:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_4_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) except: error_message = "White Liqour Consumption (m3/ADt) tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### White Liqour Consumption (tAA/ADt) kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code'] == "RPL.111XC0013:afc".lower()) try: dataset.loc[dataset.index[kpi_main_idx], ['kpi_category_id', 'kpi_id']] = [2, 12] dataset.loc[dataset.index[kpi_main_idx], 'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0014:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0015:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0016:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_4'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) except: error_message = "White Liqour Consumption (tAA/ADt) tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Utility Power Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code'] == "RPL.111XC0050:afc".lower()) try: dataset.loc[dataset.index[kpi_main_idx], ['kpi_category_id', 'kpi_id']] = [3, 13] dataset.loc[dataset.index[kpi_main_idx], 'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0051:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0052:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0053:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_4'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0054:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_5'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0055:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_6'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0056:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_7'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0057:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_8'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) # Monthy Consumptions kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0261:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_1_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0263:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0265:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) except: error_message = "Utility Power Consumption tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Utility LP Steam Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code'] == "RPL.111XC0060:afc".lower()) try: dataset.loc[dataset.index[kpi_main_idx], ['kpi_category_id', 'kpi_id']] = [3, 14] dataset.loc[dataset.index[kpi_main_idx], 'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0061:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0062:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0063:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_4'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0064:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_5'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0065:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_6'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0066:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_7'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0067:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_8'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) except: error_message = "LP Steam Consumption tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Utility MP Steam Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code'] == "RPL.111XC0068:afc".lower()) try: dataset.loc[dataset.index[kpi_main_idx], ['kpi_category_id', 'kpi_id']] = [3, 15] dataset.loc[dataset.index[kpi_main_idx], 'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0069:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0070:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0071:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_4'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0072:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_5'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0073:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_6'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0074:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_7'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0075:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_8'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) print('MP Steam Consumption found ') except: error_message = "MP Steam Consumption tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Utility Total Steam Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code'] == "RPL.111XC0076:afc".lower()) try: dataset.loc[dataset.index[kpi_main_idx], ['kpi_category_id', 'kpi_id']] = [3, 16] dataset.loc[dataset.index[kpi_main_idx], 'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0077:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0078:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0079:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_4'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0080:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_5'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0081:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_6'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0082:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_7'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0083:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_8'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) # Monthly Consumptions kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0317:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_1_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0319:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0321:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0323:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_4_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) print('Total Steam Consumption FOUND ') except: error_message = "Total Steam Consumption tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Utility water Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code'] == "RPL.111XC0084:afc".lower()) try: dataset.loc[dataset.index[kpi_main_idx], ['kpi_category_id', 'kpi_id']] = [3, 17] dataset.loc[dataset.index[kpi_main_idx], 'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0085:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0086:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0087:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_4'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0088:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_5'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0089:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_6'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0090:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_7'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0091:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_8'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) # Monthly Consumptions kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0271:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_1_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0273:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_2_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0275:afc".lower()) dataset.loc[dataset.index[kpi_main_idx], 'process_line_3_m'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) except: error_message = "Total Steam Consumption tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Woodchip Consumption - Woodchip total @2019-11-28 kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code'] == "RPL.111XC0220:afc".lower()) try: dataset.loc[dataset.index[kpi_main_idx], ['kpi_category_id', 'kpi_id']] = [4, 18] dataset.loc[dataset.index[kpi_main_idx], 'process_line_1'] = dataset['kpi_value'] except: error_message = "Woodchip Consumption - Woodchip total tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Woodchip Consumption - Chip meter avg kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code'] == "RPL.111XC0048:afc".lower()) try: dataset.loc[dataset.index[kpi_main_idx], ['kpi_category_id', 'kpi_id']] = [4, 19] dataset.loc[dataset.index[kpi_main_idx], 'process_line_3'] = dataset['kpi_value'] #FL3 except: error_message = "Woodchip Consumption - Chip meter avg tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Woodchip Consumption - Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where( dataset['tag_code'] == "RPL.111XC0211:afc".lower()) #FL1 try: dataset.loc[dataset.index[kpi_main_idx], ['kpi_category_id', 'kpi_id']] = [4, 20] dataset.loc[dataset.index[kpi_main_idx], 'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0213:afc".lower()) #FL2 dataset.loc[dataset.index[kpi_main_idx], 'process_line_2'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) # kpi_fetch_idx = np.where(dataset['tag_code']=="RPL.111XC0108:afc".lower()) #FL3 kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0215:afc".lower()) #FL3 dataset.loc[dataset.index[kpi_main_idx], 'process_line_3'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) # kpi_fetch_idx = np.where(dataset['tag_code']=="RPL.111XC0109:afc".lower()) #PCD kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0217:afc".lower()) #PCD dataset.loc[dataset.index[kpi_main_idx], 'process_line_4'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0219:afc".lower()) #PL15 dataset.loc[dataset.index[kpi_main_idx], 'process_line_15'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) error_message = "Woodchip Consumption - Consumption tag RPL.111XC0211:afc FOUND " print(error_message) except: error_message = "Woodchip Consumption - Consumption tag RPL.111XC0211:afc cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Yield - Cooking kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where( dataset['tag_code'] == "RPL.111XC0130:afc".lower()) #FL1 try: dataset.loc[dataset.index[kpi_main_idx], ['kpi_category_id', 'kpi_id']] = [4, 22] dataset.loc[dataset.index[kpi_main_idx], 'process_line_1'] = dataset['kpi_value'] # kpi_fetch_idx = np.where(dataset['tag_code']=="RPL.111XC0119:afc".lower()) #FL2 kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0131:afc".lower()) #FL2 dataset.loc[dataset.index[kpi_main_idx], 'process_line_2'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) # kpi_fetch_idx = np.where(dataset['tag_code']=="RPL.111XC0120:afc".lower()) #FL3 kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0132:afc".lower()) #FL3 dataset.loc[dataset.index[kpi_main_idx], 'process_line_3'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) # kpi_fetch_idx = np.where(dataset['tag_code']=="RPL.111XC0121:afc".lower()) #PCD kpi_fetch_idx = np.where( dataset['tag_code'] == "RPL.111XC0133:afc".lower()) #PCD dataset.loc[dataset.index[kpi_main_idx], 'process_line_4'] = list( dataset.loc[dataset.index[kpi_fetch_idx], 'kpi_value']) except: error_message = "Yield - Cooking tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) return dataset.copy()
#### To delete all rows after a certain date: #db_con.delete_entries(table_name=db_pi_table, date='2019-04-05',single_deletion=False) # ============================================================================= # ============================================================================= # # # Database connection # # #db_kpi_table is hardcoded in "upsert" function in db_connection script too # ============================================================================= # ============================================================================= try: db_con = db_connection.DB_connection() except: error_message = "DB Connection error received from db_connection module" print(error_message) logging.log_message(krc_power_pi_download_logfile_path, error_message) sys.exit(1) # ============================================================================= # ============================================================================= # # Download Routine # ============================================================================= # ============================================================================= try: try: # Create Tables if not exists #db_con.create_krc_power_pi_table(table_name = db_pi_table) db_con.create_krc_kpi_power_minute_table( table_name=db_kpi_minute_table) db_con.create_krc_kpi_power_daily_table(table_name=db_kpi_daily_table) except:
def tag_2_kraft_kpi_info(dataset,pulp_kpi_calc_logfile_path): ''' ''' #### Production kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code']=="OE.PD1.PULP.PRODUCTION".lower()) try: dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [1,1] dataset.loc[dataset.index[kpi_main_idx],'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PD2.PULP.PRODUCTION".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_2'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PD3.PULP.PRODUCTION".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_3'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL11.PULP.PRODUCTION".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_4'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL12.PULP.PRODUCTION".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_5'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) except: error_message = "Production tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### ClO2 Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code']=="OE.PL11.CHE.CLO2".lower()) try: dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [2,2] dataset.loc[dataset.index[kpi_main_idx],'process_line_4'] = dataset['kpi_value'] kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL12.CHE.CLO2".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_5'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) except: error_message = "ClO2 consumption tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### ClO2 Total Active Cl2 # kpi_main_idx = np.nan # kpi_fetch_idx = np.nan # kpi_main_idx = np.where(dataset['tag_code']=="RPL.111XC0023:afc".lower()) # try: # dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [2,3] # dataset.loc[dataset.index[kpi_main_idx],'process_line_1'] = dataset['kpi_value'] # # kpi_fetch_idx = np.where(dataset['tag_code']=="RPL.111XC0024:afc".lower()) # dataset.loc[dataset.index[kpi_main_idx],'process_line_2'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) # # kpi_fetch_idx = np.where(dataset['tag_code']=="RPL.111XC0025:afc".lower()) # dataset.loc[dataset.index[kpi_main_idx],'process_line_3'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) # except: # error_message = "ClO2 Total Active Cl2 tag cannot be found" # print(error_message) # logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Defoamer kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code']=="OE.PL11.Defoamer".lower()) try: dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [2,4] dataset.loc[dataset.index[kpi_main_idx],'process_line_4'] = dataset['kpi_value'] kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL12.Defoamer".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_5'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) except: error_message = "Defoamer tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### H2O2 Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code']=="OE.PL11.CHE.H202".lower()) try: dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [2,5] dataset.loc[dataset.index[kpi_main_idx],'process_line_4'] = dataset['kpi_value'] kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL12.CHE.H202".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_5'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) except: error_message = "H2O2 tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### NaOH(Own) Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code']=="OE.PL12.CHE.NaOH.OWN".lower()) try: dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [2,6] dataset.loc[dataset.index[kpi_main_idx],'process_line_5'] = dataset['kpi_value'] except: error_message = "NaOH(Own) tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### NaOH(Purchase) Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code']=="OE.PL11.CHE.NaOH.PUR".lower()) try: dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [2,7] dataset.loc[dataset.index[kpi_main_idx],'process_line_4'] = dataset['kpi_value'] kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL12.CHE.NaOH.PUR".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_5'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) except: error_message = "NaOH(Purchase) tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### NaOH(Total) Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code']=="OE.PL11.CHE.NaOH.TOT".lower()) try: dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [2,8] dataset.loc[dataset.index[kpi_main_idx],'process_line_4'] = dataset['kpi_value'] kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL12.CHE.NaOH.TOT".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_5'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) except: error_message = "NaOH(Total) tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Oxygen Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code']=="OE.PL11.CHE.O2".lower()) try: dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [2,9] dataset.loc[dataset.index[kpi_main_idx],'process_line_4'] = dataset['kpi_value'] kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL12.CHE.O2".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_5'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) except: error_message = "Oxygen tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Sulfuric_Acid (H2SO4) Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code']=="OE.PL11.CHE.H2SO4".lower()) try: dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [2,10] dataset.loc[dataset.index[kpi_main_idx],'process_line_4'] = dataset['kpi_value'] kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL12.CHE.H2SO4".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_5'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) except: error_message = "Sulfuric Acid (H2SO4) tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### White Liqour Consumption (m3/ADt) kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code']=="OE.PL11.CHE.WL".lower()) try: dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [2,11] dataset.loc[dataset.index[kpi_main_idx],'process_line_4'] = dataset['kpi_value'] kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL12.CHE.WL".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_5'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) except: error_message = "White Liqour Consumption (m3/ADt) tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### White Liqour Consumption (tAA/ADt) # kpi_main_idx = np.nan # kpi_fetch_idx = np.nan # kpi_main_idx = np.where(dataset['tag_code']=="RPL.111XC0013:afc".lower()) # try: # dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [2,12] # dataset.loc[dataset.index[kpi_main_idx],'process_line_1'] = dataset['kpi_value'] # # kpi_fetch_idx = np.where(dataset['tag_code']=="RPL.111XC0014:afc".lower()) # dataset.loc[dataset.index[kpi_main_idx],'process_line_2'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) # # kpi_fetch_idx = np.where(dataset['tag_code']=="RPL.111XC0015:afc".lower()) # dataset.loc[dataset.index[kpi_main_idx],'process_line_3'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) # # kpi_fetch_idx = np.where(dataset['tag_code']=="RPL.111XC0016:afc".lower()) # dataset.loc[dataset.index[kpi_main_idx],'process_line_4'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) # # except: # error_message = "White Liqour Consumption (m3/ADt) tag cannot be found" # print(error_message) # logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Utility Power Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code']=="OE.PD1.UT.POWER.TOT".lower()) try: dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [3,13] dataset.loc[dataset.index[kpi_main_idx],'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PD2.UT.POWER.TOT".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_2'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PD3.UT.POWER.TOT".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_3'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL11.UT.PR.POWER".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_4'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL12.UT.PR.POWER".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_5'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) except: error_message = "Utility Power Consumption tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Utility LP Steam Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code']=="OE.PD1.UT.LP.STEAM".lower()) try: dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [3,14] dataset.loc[dataset.index[kpi_main_idx],'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PD2.UT.LP.STEAM".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_2'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PD3.UT.LP.STEAM".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_3'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL11.UT.LP.STEAM".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_4'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL12.UT.LP.STEAM".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_5'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) except: error_message = "LP Steam Consumption tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Utility MP Steam Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code']=="OE.PL11.UT.MP.STEAM".lower()) try: dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [3,15] dataset.loc[dataset.index[kpi_main_idx],'process_line_4'] = dataset['kpi_value'] kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL12.UT.MP.STEAM".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_5'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) except: error_message = "MP Steam Consumption tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Utility Total Steam Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code']=="OE.PD1.UT.TOT.STEAM".lower()) try: dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [3,16] dataset.loc[dataset.index[kpi_main_idx],'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PD2.UT.TOT.STEAM".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_2'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PD3.UT.TOT.STEAM".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_3'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL11.UT.TOT.STEAM".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_4'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL12.UT.TOT.STEAM".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_5'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) except: error_message = "Total Steam Consumption tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Utility water Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code']=="OE.PD1.UT.PR.WATER".lower()) try: dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [3,17] dataset.loc[dataset.index[kpi_main_idx],'process_line_1'] = dataset['kpi_value'] kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PD2.UT.PR.WATER".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_2'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PD3.UT.PR.WATER".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_3'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL11.UT.PR.WATER".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_4'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL12.UT.PR.WATER".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_5'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) except: error_message = "Total Steam Consumption tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Woodchip Consumption - Woodchip total # kpi_main_idx = np.nan # kpi_fetch_idx = np.nan # kpi_main_idx = np.where(dataset['tag_code']=="RPL.411WQ7000.F:Y_DAY".lower()) # try: # dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [4,18] # dataset.loc[dataset.index[kpi_main_idx],'process_line_1'] = dataset['kpi_value'] # # kpi_fetch_idx = np.where(dataset['tag_code']=="RPL.341WQ5080YD:value".lower()) # dataset.loc[dataset.index[kpi_main_idx],'process_line_2'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) # # kpi_fetch_idx = np.where(dataset['tag_code']=="RPL.341WI2794-YD:value".lower()) #PCD # dataset.loc[dataset.index[kpi_main_idx],'process_line_4'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) # except: # error_message = "Woodchip Consumption - Woodchip total tag cannot be found" # print(error_message) # logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Woodchip Consumption - Chip meter avg # kpi_main_idx = np.nan # kpi_fetch_idx = np.nan # kpi_main_idx = np.where(dataset['tag_code']=="RPL.111XC0048:afc".lower()) # try: # dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [4,19] # dataset.loc[dataset.index[kpi_main_idx],'process_line_3'] = dataset['kpi_value'] #FL3 # # except: # error_message = "Woodchip Consumption - Chip meter avg tag cannot be found" # print(error_message) # logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Woodchip Consumption - Consumption kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code']=="OE.PL11.CHIPS.GMT".lower()) try: dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [4,20] dataset.loc[dataset.index[kpi_main_idx],'process_line_4'] = dataset['kpi_value'] kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL12.CHIPS.GMT".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_5'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) except: error_message = "Woodchip Consumption - Consumption tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Yield - Bleaching kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code']=="OE.PL11.CHIPS.BLC.YIELD".lower()) try: dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [4,21] dataset.loc[dataset.index[kpi_main_idx],'process_line_4'] = dataset['kpi_value'] kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL12.CHIPS.BLC.YIELD".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_5'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) except: error_message = "Yield - Bleaching tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Yield - Cooking (Digester Yield) kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code']=="OE.PL11.CHIPS.DIG.YIELD".lower()) try: dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [4,22] dataset.loc[dataset.index[kpi_main_idx],'process_line_4'] = dataset['kpi_value'] kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL12.CHIPS.DIG.YIELD".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_5'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) except: error_message = "Yield - Cooking (Digester Yield) tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) #### Yield - Screening kpi_main_idx = np.nan kpi_fetch_idx = np.nan kpi_main_idx = np.where(dataset['tag_code']=="OE.PL11.CHIPS.SCR.YIELD".lower()) try: dataset.loc[dataset.index[kpi_main_idx],['kpi_category_id','kpi_id']] = [4,23] dataset.loc[dataset.index[kpi_main_idx],'process_line_4'] = dataset['kpi_value'] kpi_fetch_idx = np.where(dataset['tag_code']=="OE.PL12.CHIPS.SCR.YIELD".lower()) dataset.loc[dataset.index[kpi_main_idx],'process_line_5'] = list(dataset.loc[dataset.index[kpi_fetch_idx],'kpi_value']) except: error_message = "Yield - Screening tag cannot be found" print(error_message) logging.log_message(pulp_kpi_calc_logfile_path, error_message) return dataset.copy()
pulp_pi_tags += utility_power_consumption pulp_pi_tags += utility_power_consumption_mth pulp_pi_tags += lp_steam_consumption pulp_pi_tags += mp_steam_consumption pulp_pi_tags += total_steam_consumption pulp_pi_tags += total_steam_consumption_tags_mth pulp_pi_tags += utility_water_consumption pulp_pi_tags += wc_woodchip_total pulp_pi_tags += wc_chip_meter_avg pulp_pi_tags += wc_consumption pulp_pi_tags += water_consumption_mth pulp_pi_tags += yield_cooking tag_list = list(set(pulp_pi_tags)) logging.log_message(krc_pulp_pi_download_logfile_path, tag_list) total_Tag_list = '{} tags to download!'.format(len(tag_list)) #HemaEntries # print (total_Tag_list) sampling_freq = "24h" # ============================================================================= # ============================================================================= # # Functions # ============================================================================= # ============================================================================= #### To delete all rows after a certain date: #db_con.delete_entries(table_name=db_pi_table, date='2019-04-05',single_deletion=False)
#### To delete all rows after a certain date: #db_con.delete_entries(table_name=db_pi_table, date='2019-04-05',single_deletion=False) # ============================================================================= # ============================================================================= # # # Database connection # # #db_kpi_table is hardcoded in "upsert" function in db_connection script too # ============================================================================= # ============================================================================= try: db_con = db_connection.DB_connection() except: error_message = "DB Connection error received from db_connection module" print(error_message) logging.log_message(rz_pulp_pi_download_logfile_path, error_message) sys.exit(1) # ============================================================================= # ============================================================================= # # Download Routine # ============================================================================= # ============================================================================= try: try: # Create Tables if not exists db_con.create_rz_pulp_pi_table(table_name=db_pi_table) db_con.create_daily_kpi_pulp_table(table_name=db_daily_kpi_table) except: error_message = "Table creation/check existance error" print(error_message)