def splitFilesMod(files, num_clients): ''' This data distribution method assigns recipients based a value within the file name. this value is then modded by num_clients whos result is used to determine the recipient of the file. files: a list of absolute file paths num_clients: the number of clients to be distributed to. returns: a list with num_clients lists in it. Each sublist corresponds to a client and contains the path of the data file that will be distributed to that client. ''' client_files = emptyList(num_clients) valid_ext = ['txt','json','zip','gz'] for f in files: file_name = f.split("/")[-1] file_ext = f.split(".")[-1] ## Only distribute data files if file_ext in valid_ext: num = extractNum(file_name) ## Subtract 1 from the number before mod so file 1.txt goes to client 1 rather than client 2. mod_client = (num - 1) % num_clients cf = client_files[mod_client] cf.append(f) return client_files
def splitFilesRandom(files, num_clients): ''' This data distribution method random assigns which file from files is sent to each client. files: a list of absolute file paths num_clients: the number of clients to be distributed to. returns: a list with num_clients lists in it. Each sublist corresponds to a client and contains the path of the data file that will be distributed to that client. ''' client_files = emptyList(num_clients) for f in files: rnd_client = random.choice(clients) print "File " + f + " stored on client " + str(rnd_client) cf = client_files[rnd_client] cf.append(f) return client_files