Untitled
unknown
plain_text
4 days ago
3.2 kB
2
Indexable
Never
def get_immediate_conditional_flow(self, input_param_idx, data): """ Function to get immediate code flow. I will the end capturing flow till the immediate IF or EVALUATE """ seq_list = [] row = tuple(data.iloc[input_param_idx]) seq_list.append(row[0]) # While loop to get seq id of flow while (pd.notna(row[5])) and (row[4] not in ['IF', 'EVALUATE']) and (row[5]): row = tuple(data[data['Sequence'].astype('int')==int(float(row[5]))].iloc[0]) seq_list.append(row[0]) #DF with retrieved seq id df = data[data.Sequence.isin(seq_list)] #If steatement under ELSE if 'ELSE' in df.Keywords.to_list(): df = df[~df['Keywords'].str.contains('ELSE')] ls = df['Statement'].iloc[0].strip().split() ls.insert(1, 'NOT') df.iloc[0, 1] = ' '.join(ls) return df def get_code(self, df): """ Function to format code block Args: df: The pandas DataFrame with 'Seq_no' and 'Conditional_Seq' columns. Returns: The DataFrame with the added third column. """ df['indentation'] = 0 # Initialize the third column with 0s for index, row in df.iterrows(): if pd.notna(row['Conditional_Seq']): # Find the row with matching 'Seq_no' matching_row = df[df['Sequence'].astype(int) == int(float(row['Conditional_Seq']))] if not matching_row.empty: # If a match is found, increment the value from the matching row's 'Third_Column' df.loc[index, 'indentation'] = matching_row['indentation'].iloc[0] + 1 result = [] for i,d in df.iterrows(): indentation = d.indentation*" " idx = str(d.Sequence).zfill(6) statement = d.Statement result.append(f'{idx} {indentation}{statement}') return result #Get Seq index input_param_idx = data[data['Sequence'].astype(str)==str(st.query_params['seq_id'])].index.item() #Get Start & end of block where target maniulated # start,ed = bre_utils.get_block_idx(input_param_idx, data) # df = data.iloc[start:ed+1] data.to_excel("data.xlsx") print("\n\nINPUT PARAM INDEX\n\n:",input_param_idx) df = bre_utils.get_immediate_conditional_flow(input_param_idx, data) print("\n\n\nDF\n\n:",df) lines = [f'000000 PROGRAM-ID {st.query_params["program_id"]}']+[str(i) for i in bre_utils.get_code(df)] print("\n\nLINES\n\n:",lines) #Code block st.markdown(code_css, unsafe_allow_html=True) st.code("\n".join(lines), language='cobol') # st.code(lines, language="cobol") st.markdown('</div>', unsafe_allow_html=True) INPUT PARAM INDEX : 925 DF : Sequence Statement ... Source Target 922 923 IF NOT WS-SUSP-FOUND-SW = 'Y' ... None None 925 926 MOVE ABQ-RSN-CODE OF WS-SCOPE-QWABQVX1 TO AIG-... ... ['ABQ-RSN-CODE OF WS-SCOPE-QWABQVX1'] ['AIG-CODE'] [2 rows x 9 columns] LINES : ['000000 PROGRAM-ID PAJSFN32', "000923 IF NOT WS-SUSP-FOUND-SW = 'Y'", '000926 MOVE ABQ-RSN-CODE OF WS-SCOPE-QWABQVX1 TO AIG-CODE']
Leave a Comment