<commit_before># -*- coding: utf-8 -*-
# Copyright (c) 2016, HFO-detect Development Team.


from . import D_file_read
import pyedflib
import pandas as pd
import numpy as np


def data_feeder(file_path, start_samp, stop_samp, channel_name):
    """
    Function that specifies file opener based on extension and returns data.

    Parameters:
    -----------
    file_path(str) - path to data file\n
    start_samp(int) - start sample\n
    stop_samp(int) - stop sample\n
    channel_name(str) - requested channel\n

    Returns:
    --------
    data - requested data\n
    fs - sampling frequency\n
    """

    # Parse the file name to get extension
    ext = file_path[-file_path[::-1].find('.'):]

    # Decide which opener to use and get the data
    if ext == 'd':
        sheader, xheader = D_file_read.read_d_header(file_path)
        fs = sheader['fsamp']
        ch_idx = xheader['channel_names'].index(channel_name)
        data = D_file_read.read_d_data(sheader, [ch_idx],
                                       start_samp, stop_samp)

    elif ext in ['edf','bdf']:
        f = pyedflib.EdfReader(file_path)
        ch_idx = f.getSignalLabels().index(channel_name)
        fs = f.getSampleFrequency(ch_idx)
        data = f.readSignal(ch_idx)

    return data, fs


def create_output_df(fields=[],dtypes=None):
    """
    Function to create a custom pandas dataframe depending on the algorithm
    needs. Fields: event_start,event_stop preset.
    
    Parameters:
    -----------
    fields(list) - additional fields for the dataframe\n
    dtypes(dict) - dictionary with dtypes for specified fields (optional)\n
    
    Returns:
    --------
    dataframe - pandas dataframe for deteciton insertion\n
    """<commit_msg>Edf and bdf distinction fix<commit_after># -*- coding: utf-8 -*-
# Copyright (c) 2016, HFO-detect Development Team.


from . import D_file_read
import pyedflib
import pandas as pd
import numpy as np


def data_feeder(file_path, start_samp, stop_samp, channel_name):
    """
    Function that specifies file opener based on extension and returns data.

    Parameters:
    -----------
    file_path(str) - path to data file\n
    start_samp(int) - start sample\n
    stop_samp(int) - stop sample\n
    channel_name(str) - requested channel\n

    Returns:
    --------
    data - requested data\n
    fs - sampling frequency\n
    """

    # Parse the file name to get extension
    ext = file_path[-file_path[::-1].find('.'):]

    # Decide which opener to use and get the data
    if ext == 'd':
        sheader, xheader = D_file_read.read_d_header(file_path)
        fs = sheader['fsamp']
        ch_idx = xheader['channel_names'].index(channel_name)
        data = D_file_read.read_d_data(sheader, [ch_idx],
                                       start_samp, stop_samp)

    elif ext in ['edf','bdf']:
        if ext == 'edf':
            f = pyedflib.EdfReader(file_path,3)
        elif ext == 'bdf':
            f = pyedflib.EdfReader(file_path,4)
        ch_idx = [x.decode() for x in f.getSignalLabels()].index(channel_name)
        fs = f.getSampleFrequency(ch_idx)
        data = f.readSignal(ch_idx)

    return data, fs


def create_output_df(fields=[],dtypes=None):
    """
    Function to create a custom pandas dataframe depending on the algorithm
    needs. Fields: event_start,event_stop preset.
    
    Parameters:
    -----------
    fields(list) - additional fields for the dataframe\n
    dtypes(dict) - dictionary with dtypes for specified fields (optional)\n
    
    Returns:
    --------
    dataframe - pandas dataframe for deteciton insertion\n
    """
{'fraction_non_alphanumeric': 0.11753318584070796, 'fraction_numerical': 0.0038716814159292035, 'mean_word_length': 2.4122641509433964, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1989575', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1118, 'n_words': 310}