(user_files, which_set, max_users, include_hierarchy)
used in split-by-user case
used in split-by-user case
used in split - by - user case
def create_jsons_for(user_files, which_set, max_users, include_hierarchy):
    """used in split-by-user case"""
    user_count = 0
    json_index = 0
    users = []
    num_samples = []
    user_data = {}
    prev_dir = None
    for (i, t) in enumerate(user_files):
        (u, ns, f) = t

        file_dir = os.path.join(subdir, f)
        if prev_dir != file_dir:
            with open(file_dir, "r") as inf:
                data = json.load(inf)
            prev_dir = file_dir

        users.append(u)
        num_samples.append(ns)
        user_data[u] = data['user_data'][u]
        user_count += 1

    if (user_count == max_users) or (i == len(user_files) - 1):

        all_data = {}
        all_data['users'] = users
        all_data['num_samples'] = num_samples
        all_data['user_data'] = user_data

        data_i = f.find('data')
        num_i = data_i + 5
        num_to_end = f[num_i:]
        param_i = num_to_end.find('_')
        param_to_end = '.json'
        if param_i != -1:
            param_to_end = num_to_end[param_i:]
        nf = '%s_%d%s' % (f[:(num_i-1)], json_index, param_to_end)
        file_name = '%s_%s_%s.json' % ((nf[:-5]), which_set, arg_label)
        ouf_dir = os.path.join(dir, which_set, file_name)

        print('writing %s' % file_name)
        with open(ouf_dir, 'w') as outfile:
            json.dump(all_data, outfile)

        user_count = 0
        json_index += 1
        users = []
        num_samples = []
        user_data = {}
def create_jsons_for ( user_files , which_set , max_users , include_hierarchy ) : user_count = 0 json_index = 0 users = [ ] num_samples = [ ] user_data = { } prev_dir = None for ( i , t ) in enumerate ( user_files ) : ( u , ns , f ) = t file_dir = os . path . join ( subdir , f ) if prev_dir != file_dir : with open ( file_dir , "r" ) as inf : data = json . load ( inf ) prev_dir = file_dir users . append ( u ) num_samples . append ( ns ) user_data [ u ] = data [ 'user_data' ] [ u ] user_count += 1 if ( user_count == max_users ) or ( i == len ( user_files ) - 1 ) : all_data = { } all_data [ 'users' ] = users all_data [ 'num_samples' ] = num_samples all_data [ 'user_data' ] = user_data data_i = f . find ( 'data' ) num_i = data_i + 5 num_to_end = f [ num_i : ] param_i = num_to_end . find ( '_' ) param_to_end = '.json' if param_i != - 1 : param_to_end = num_to_end [ param_i : ] nf = '%s_%d%s' % ( f [ : ( num_i - 1 ) ] , json_index , param_to_end ) file_name = '%s_%s_%s.json' % ( ( nf [ : - 5 ] ) , which_set , arg_label ) ouf_dir = os . path . join ( dir , which_set , file_name ) print ( 'writing %s' % file_name ) with open ( ouf_dir , 'w' ) as outfile : json . dump ( all_data , outfile ) user_count = 0 json_index += 1 users = [ ] num_samples = [ ] user_data = { }