# AUTOGENERATED! DO NOT EDIT! File to edit: ../../../nbs/CLI/utils/chunk_size.ipynb.

# %% auto 0
__all__ = ['get_pc_chunk_size_from_n_pc_chunk', 'get_pc_chunk_size_from_pc_chunk_size', 'get_pc_chunk_size_from_n_az_chunk',
           'get_az_chunk_size_from_n_pc_chunk', 'get_az_chunk_size_from_az_chunk_size']

# %% ../../../nbs/CLI/utils/chunk_size.ipynb 3
import math

# %% ../../../nbs/CLI/utils/chunk_size.ipynb 4
def get_pc_chunk_size_from_n_pc_chunk(in_pc_name, out_pc_name,
                                      n_pc_in, pc_chunk_size_in,
                                      n_pc,
                                      logger,
                                      pc_chunk_size=None,n_pc_chunk=None):
    if pc_chunk_size is not None:
        logger.info(f'got pc_chunk_size for {out_pc_name}: {pc_chunk_size}')
        return pc_chunk_size
    else:
        if n_pc_chunk is not None:
            logger.info(f'got n_pc_chunk for {out_pc_name}: {n_pc_chunk}')
            logger.info(f'automatically determine pc_chunk_size from n_pc of {out_pc_name} and n_pc_chunk of {out_pc_name}')
            pc_chunk_size = math.ceil(n_pc/n_pc_chunk)
            logger.info(f'pc_chunk_size for {out_pc_name}: {pc_chunk_size}')
            return pc_chunk_size
        else:
            logger.info(f'automatically determine pc_chunk_size from n_pc of {out_pc_name} and n_pc_chunk of {in_pc_name}')
            n_pc_chunk = math.ceil(n_pc_in/pc_chunk_size_in)
            pc_chunk_size = math.ceil(n_pc/n_pc_chunk)
            logger.info(f'pc_chunk_size for {out_pc_name}: {pc_chunk_size}')
            return pc_chunk_size

# %% ../../../nbs/CLI/utils/chunk_size.ipynb 5
def get_pc_chunk_size_from_pc_chunk_size(in_pc_name, out_pc_name,
                                         pc_chunk_size_in,
                                         n_pc,
                                         logger,
                                         pc_chunk_size=None,n_pc_chunk=None):
    if pc_chunk_size is not None:
        logger.info(f'got pc_chunk_size for {out_pc_name}: {pc_chunk_size}')
        return pc_chunk_size
    else:
        if n_pc_chunk is not None:
            logger.info(f'got n_pc_chunk for {out_pc_name}: {n_pc_chunk}')
            logger.info(f'automatically determine pc_chunk_size from n_pc of {out_pc_name} and n_pc_chunk of {out_pc_name}')
            pc_chunk_size = math.ceil(n_pc/n_pc_chunk)
            logger.info(f'pc_chunk_size for {out_pc_name}: {pc_chunk_size}')
            return pc_chunk_size
        else:
            logger.info(f'automatically determine pc_chunk_size from pc_chunk_size of {in_pc_name}.')
            pc_chunk_size = pc_chunk_size_in
            logger.info(f'pc_chunk_size for {out_pc_name}: {pc_chunk_size}')
            return pc_chunk_size

# %% ../../../nbs/CLI/utils/chunk_size.ipynb 6
def get_pc_chunk_size_from_n_az_chunk(ras_name, pc_name,
                                      nlines, az_chunk_size,
                                      n_pc,
                                      logger,
                                      pc_chunk_size=None,n_pc_chunk=None):
    if pc_chunk_size is not None:
        logger.info(f'got pc_chunk_size for {pc_name}: {pc_chunk_size}')
        return pc_chunk_size
    else:
        if n_pc_chunk is not None:
            logger.info(f'got n_pc_chunk for {pc_name}: {n_pc_chunk}')
            logger.info(f'automatically determine pc_chunk_size from n_pc of {pc_name} and n_pc_chunk of {pc_name}')
            pc_chunk_size = math.ceil(n_pc/n_pc_chunk)
            logger.info(f'pc_chunk_size for {pc_name}: {pc_chunk_size}')
            return pc_chunk_size
        else:
            logger.info(f'automatically determine pc_chunk_size from n_pc of {pc_name} and n_az_chunk of {ras_name}')
            n_pc_chunk = math.ceil(nlines/az_chunk_size)
            pc_chunk_size = math.ceil(n_pc/n_pc_chunk)
            logger.info(f'pc_chunk_size for {pc_name}: {pc_chunk_size}')
            return pc_chunk_size

# %% ../../../nbs/CLI/utils/chunk_size.ipynb 7
def get_az_chunk_size_from_n_pc_chunk(pc_name, ras_name,
                                      n_pc, pc_chunk_size,
                                      nlines,
                                      logger,
                                      az_chunk_size=None,n_az_chunk=None):
    if az_chunk_size is not None:
        logger.info(f'got az_chunk_size for {ras_name}: {az_chunk_size}')
        return az_chunk_size
    else:
        if n_az_chunk is not None:
            logger.info(f'got n_az_chunk for {ras_name}: {n_az_chunk}')
            logger.info(f'automatically determine az_chunk_size from nlines of {ras_name} and n_pc_chunk of {ras_name}')
            az_chunk_size = math.ceil(nlines/n_az_chunk)
            logger.info(f'az_chunk_size for {ras_name}: {az_chunk_size}')
            return az_chunk_size
        else:
            logger.info(f'automatically determine az_chunk_size from nlines of {ras_name} and n_pc_chunk of {pc_name}')
            n_az_chunk = math.ceil(n_pc/pc_chunk_size)
            az_chunk_size = math.ceil(nlines/n_az_chunk)
            logger.info(f'az_chunk_size for {az_name}: {az_chunk_size}')
            return az_chunk_size

# %% ../../../nbs/CLI/utils/chunk_size.ipynb 8
def get_az_chunk_size_from_az_chunk_size(in_ras_name, out_ras_name,
                                         az_chunk_size_in,
                                         nlines,
                                         logger,
                                         az_chunk_size=None,n_az_chunk=None):
    if az_chunk_size is not None:
        logger.info(f'got az_chunk_size for {out_ras_name}: {az_chunk_size}')
        return az_chunk_size
    else:
        if n_az_chunk is not None:
            logger.info(f'got n_az_chunk for {out_ras_name}: {n_az_chunk}')
            logger.info(f'automatically determine az_chunk_size from nlines of {out_ras_name} and n_pc_chunk of {out_ras_name}')
            az_chunk_size = math.ceil(nlines/n_az_chunk)
            logger.info(f'az_chunk_size for {out_ras_name}: {az_chunk_size}')
            return az_chunk_size
        else:
            logger.info(f'automatically determine az_chunk_size from az_chunk_size of {in_ras_name}')
            az_chunk_size = az_chunk_size_in
            logger.info(f'az_chunk_size for {out_az_name}: {az_chunk_size}')
            return az_chunk_size
