<commit_before>def mask_from_noncontiguous_indices(n, start_ind, stop_ind):
    '''Create boolean mask from start stop indices of noncontiguous regions

    Args
    ----
    n: int
        length of boolean array to fill
    start_ind: numpy.ndarray
        start index positions of non-contiguous regions
    stop_ind: numpy.ndarray
        stop index positions of non-contiguous regions

    Returns
    -------
    mask: numpy.ndarray, shape (n,), dtype boolean
        boolean mask array
    '''
    import numpy

    mask = numpy.zeros(n, dtype=bool)

    for i in range(len(start_ind)):
        mask[start_ind[i]:stop_ind[i]] = True

    return mask


def get_n_lines(file_path):
    '''Get number of lines by calling bash command wc'''
    import os
    import subprocess

    cmd = 'wc -l {0}'.format(file_path)
    output = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout
    n_lines = int((output).readlines()[0].split()[0])

    return n_lines


def get_versions(module_name):
    '''Return versions for repository and packages in requirements file

    Args
    ----
    module_name: str
        Name of module calling this routine, stored with local git hash

    Returns
    -------
    versions: OrderedDict
        Dictionary of module name and dependencies with versions
    '''
    from collections import OrderedDict
    import importlib
    import os

    versions = OrderedDict()

    module = importlib.util.find_spec(module_name)

    # Add git hash for pylleo to dict
    versions[module_name] = get_githash('long')

    # Get path to pylleo requirements file
    module_path  = os.path.split(module.origin)[0]
    requirements = os.path.join(module_path, 'requirements.txt')

    # Add packages and versions to dictionary
    with open(requirements) as f:
        for l in f.readlines():
            package, version = l.strip().split('==')
            versions[package] = version

    return versions


def get_githash(hash_type):
    '''Add git commit for reference to code that produced data

    Args
    ----
    hash_type: str
        keyword determining length of has. 'long' gives full hash, 'short'
        gives 6 character hash

    Returns
    -------
    git_hash: str
        Git hash as a 6 or 40 char string depending on keywork `hash_type`
    '''
    import subprocess<commit_msg>added routine for creating project directory paths/yaml. fixed git hash retrieval if out of git repo directory<commit_after>
def create_project(path_project):
    """Generate project based on values in *d*."""
    from collections import OrderedDict
    import datetime
    import importlib
    import os
    import shutil
    import yamlord

    import utils

    # Get path to pylleo requirements file
    module = importlib.util.find_spec('smartmove')
    module_path  = os.path.split(module.origin)[0]

    fname_cfg_project = 'cfg_project.yaml'
    fname_cfg_exp = 'cfg_experiments.yaml'
    fname_cfg_ann = 'cfg_ann.yaml'
    for fname in [fname_cfg_project, fname_cfg_exp, fname_cfg_ann]:
        src = os.path.join(module_path, 'templates', fname)
        dst = os.path.join(path_project, fname)
        shutil.copyfile(src, dst)

    d = yamlord.read_yaml(os.path.join(path_project, fname_cfg_project))

    d['meta'] = OrderedDict()
    d.move_to_end('meta', last=False)
    d['meta']['created'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    d['meta']['versions'] = utils.get_versions('smartmove')

    yamlord.write_yaml(d, os.path.join(path_project, fname_cfg_project))

    # Create paths if not existing
    for key in d['paths'].keys():
        p = os.path.join(path_project, d['paths'][key])
        if not os.path.isdir(p):
            os.makedirs(p, exist_ok=True)

    print('\nYour project directory has been created at {}.\n'
          'You must now copy your datalogger data to the `{}` directory, '
          'the body condition `.csv` files to the `{}` directory, and the CTD '
          '`.mat` file to the `{}` directory'.format(path_project,
                                                     d['paths']['acc'],
                                                     d['paths']['csv'],
                                                     d['paths']['ctd']))

    return None


#def _check_path(path):
#    '''Check that a path exists or can be created'''
#    import os
#
#    if os.path.exists(path):
#        #the file is there
#        path_valid = True
#    elif os.access(os.path.dirname(path), os.W_OK):
#        #the file does not exists but write privileges are given
#        path_valid = True
#    else:
#        #can not write there
#        path_valid = False
#
#    return path_valid
#
#
#def input_path(msg, check_current=True):
#    import os
#    import sys
#
#    path_valid = False
#    ans_valid  = False
#    print()
#    print(msg)
#    try:
#        while ans_valid is False:
#            if check_current == True:
#                m = ('Use current <{}>?\n'
#                     'Enter `y` or `n`: '.format(os.path.abspath('.')))
#                ans = (input(m)).lower()
#            else:
#                ans = 'n'
#
#            if ans == 'y':
#                ans_valid = True
#                path = os.path.abspath('.')
#            elif ans == 'n':
#                ans_valid = True
#                while path_valid is False:
#                    path = input('Enter a new path: ')
#                    path_valid = _check_path(path)
#            else:
#                ans_valid = False
#                print('Please enter `y` or `n`.')
#                continue
#
#    except KeyboardInterrupt:
#        return sys.exit()
#
#    return path


def mask_from_noncontiguous_indices(n, start_ind, stop_ind):
    '''Create boolean mask from start stop indices of noncontiguous regions

    Args
    ----
    n: int
        length of boolean array to fill
    start_ind: numpy.ndarray
        start index positions of non-contiguous regions
    stop_ind: numpy.ndarray
        stop index positions of non-contiguous regions

    Returns
    -------
    mask: numpy.ndarray, shape (n,), dtype boolean
        boolean mask array
    '''
    import numpy

    mask = numpy.zeros(n, dtype=bool)

    for i in range(len(start_ind)):
        mask[start_ind[i]:stop_ind[i]] = True

    return mask


def get_n_lines(file_path):
    '''Get number of lines by calling bash command wc'''
    import os
    import subprocess

    cmd = 'wc -l {0}'.format(file_path)
    output = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout
    n_lines = int((output).readlines()[0].split()[0])

    return n_lines


def get_versions(module_name):
    '''Return versions for repository and packages in requirements file

    Args
    ----
    module_name: str
        Name of module calling this routine, stored with local git hash

    Returns
    -------
    versions: OrderedDict
        Dictionary of module name and dependencies with versions
    '''
    from collections import OrderedDict
    import importlib
    import os

    versions = OrderedDict()

    module = importlib.util.find_spec(module_name)

    # Get path to pylleo requirements file
    module_path  = os.path.split(module.origin)[0]
    requirements = os.path.join(module_path, 'requirements.txt')

    # Add git hash for pylleo to dict
    cwd = os.getcwd()
    os.chdir(module_path)
    versions[module_name] = get_githash('long')
    os.chdir(cwd)

    # Add packages and versions to dictionary
    with open(requirements) as f:
        for l in f.readlines():
            package, version = l.strip().split('==')
            versions[package] = version

    return versions

def get_githash(hash_type):
    '''Add git commit for reference to code that produced data

    Args
    ----
    hash_type: str
        keyword determining length of has. 'long' gives full hash, 'short'
        gives 6 character hash

    Returns
    -------
    git_hash: str
        Git hash as a 6 or 40 char string depending on keywork `hash_type`
    '''
    import subprocess
{'fraction_non_alphanumeric': 0.10583260788459146, 'fraction_numerical': 0.0021141649048625794, 'mean_word_length': 2.298605414273995, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5718269', 'n_tokens_mistral': 2414, 'n_tokens_neox': 2338, 'n_words': 715}