def process_folder()

in data_extraction_transformation/scripts/one_time_use_scripts/check_adjacent_alerts_for_SP.py [0:0]


def process_folder(input_folder, folder, margin):
    global sp_only_tn_count
    global sp_other_values_count
    global sp_with_tp
    global sp_with_fp
    global sp_with_fn
    global sp_with_sp
    global total_sig
    global total_sp_sig
    for signature_file in os.listdir(input_folder + '/' + folder):
        total_sig += 1
        df = pd.read_csv(input_folder + '/' + folder + '/' + signature_file, index_col=False)
        df['push_timestamp'] = pd.to_datetime(df['push_timestamp'])
        df = df.sort_values(by='push_timestamp')
        df = df[['revision', 'signature_id', 'value', 'alert_status_general', 'push_timestamp']]
        sp_only_tn_count_temp = 0
        sp_other_values_count_temp = 0
        sp_with_tp_temp = 0
        sp_with_fp_temp = 0
        sp_with_fn_temp = 0
        sp_with_sp_temp = 0
        contains_sp = False
        for idx, row in df.iterrows():
            if row['alert_status_general'] == 'SP':
                contains_sp = True
                start_idx = max(0, idx - margin)
                end_idx = min(len(df), idx + margin + 1)
                buffer_values = df.loc[start_idx:end_idx, 'alert_status_general']
                buffer_values = buffer_values[buffer_values.index != idx]
                if all(value == 'TN' for value in buffer_values):
                    sp_only_tn_count_temp += 1
                else:
                    sp_other_values_count_temp += 1
                    if 'TP' in buffer_values.values:
                        sp_with_tp_temp += 1
                    if 'FP' in buffer_values.values:
                        sp_with_fp_temp += 1
                    if 'FN' in buffer_values.values:
                        sp_with_fn_temp += 1
                    if 'SP' in buffer_values.values:
                        sp_with_sp_temp += 1
        sp_only_tn_count += sp_only_tn_count_temp
        sp_other_values_count += sp_other_values_count_temp
        sp_with_tp += sp_with_tp_temp
        sp_with_fp += sp_with_fp_temp
        sp_with_fn += sp_with_fn_temp
        sp_with_sp += sp_with_sp_temp
        if contains_sp:
            total_sp_sig += 1