import json


def read_data_settings_file(fname):
    """
    Read the data settings file containing a JSON format of XYR, F, DIST,
    directory etc. information.

    Args:
        fname -- (str) name of the file

    Returns:
        2-tuple -- (tuple of 2 dicts) The first dictionary has information
            about the original data files. The second dictionary has
            information about the random data files.
    """
    DATA_JSON = json.load(open(fname, "r"))

    # orig data files' locations
    ORIG_DATA_FILES = {
        'XYR': DATA_JSON['orig']['XYR_file'],
        'F': DATA_JSON['orig']['F_file'],
        'DIST': DATA_JSON['orig']['DIST_file']
    }

    # rand data files' locations
    def rand_data_fname(key):
        """
        Returns the file name for rand data associated with key type of
        information.
        """
        return "{0:s}{1:d}{2:s}".format(
            DATA_JSON['rand'][key]['pre'],
            DATA_JSON['rand']['locs_in_file'],
            DATA_JSON['rand'][key]['suff']
        )

    RAND_DATA_FILES = {
        'XYR': rand_data_fname('XYR_file'),
        'F': rand_data_fname('F_file'),
        'DIST': rand_data_fname('DIST_file'),
        'XYR_weights': rand_data_fname('XYR_weights_file'),
    }

    return ORIG_DATA_FILES, RAND_DATA_FILES