def compute_max_file_length(paths): """ Return the integer sum of average length and standard length deviation for the given files """ file_lengths = [compute_file_length(path) for path in paths] return int( math.ceil(average(file_lengths) + standard_deviation(file_lengths)))
def test_average(self): date_list = [datetime.timedelta(seconds=1800), datetime.timedelta(seconds=1800), datetime.timedelta(seconds=7200), datetime.timedelta(seconds=1), datetime.timedelta(seconds=1000), datetime.timedelta(seconds=1000), datetime.timedelta(days=1, seconds=13600)] result = average(date_list) expected = date_list[0] self.assertEqual(type(expected), type(result))
def compute_max_file_length(paths): """ Return the integer sum of average length and standard length deviation for the given files """ file_lengths = [compute_file_length(path) for path in paths] return int(math.ceil( average(file_lengths) + standard_deviation(file_lengths) ))
def grayscale(im, verbose=0): res = [] w, h = float(len(im)), float(len(im[0])) for iy, y in enumerate(im): res.append([]) for ix, x in enumerate(y): res[-1].append(utility.average(x)) if verbose > 0: utility.show_bar(iy * h + ix, w * h, number_limit=True, message='Grayscaling: ') return np.array(res, dtype=float)
def response_time(self) -> dict: """ Calculates the average response time per college :return: dictionary of university and average time mapping :rtype: dict """ response = {} university_response = {} # Calling private member data from the parent class messages = self.get_msg() chat_groups = self.get_chat_groups() user = self.get_user() for msg in range(len(messages)): # checks for the current and next message if first user is # applicant and another is mentor then the difference of the time stamp is # calculated. c_id = messages[msg][2] mentor = chat_groups[int(c_id)][1] if self.is_applicant(messages[msg][1]): if self.is_applicant(messages[msg + 1][1]): logger.info('Both are applicants') pass if self.is_mentor(mentor): diff = difference(messages[msg][4], messages[msg + 1][4]) if user[mentor] not in response: response[user[mentor]] = [] response[user[mentor]].append(diff) for i in response: avg = average(response[i]) university_response.update({i: avg}) print("Average response time for university ({}) is: {}".format( i, avg)) logger.info( "Average response time for university ({}) is: {}".format( i, avg)) return university_response
if line.startswith("Policy 2"): parts = line.split() policy2_data.append(float(parts[2])) if line.startswith("Policy 3"): parts = line.split() policy3_data.append(float(parts[2])) if line.startswith("Openloop"): parts = line.split() openloop_data.append(float(parts[1])) if line.startswith("Naive"): parts = line.split() naive_data.append(float(parts[1])) if len(naive_data) == n: break print("Average over {} tasks:".format(len(naive_data))) # print("{:19}: {:.2f}".format("Policy average", util.average(policy_data))) print("{:19}: {:.2f}".format("Naive average", util.average(naive_data))) # print("{:19}: {:.2f}".format("Openloop average", util.average(openloop_data))) print("{:19}: {:.2f}".format("Policy 1 average", util.average(policy1_data))) print("{:19}: {}".format(" # supermaps", noM[1])) print("{:19}: {}".format(" # lambda calls", nol[1])) # print("{:19}: {:.2f}".format("Policy 2 average", util.average(policy2_data))) # print("{:19}: {}".format(" # lambda calls", nol[1])) # print("{:19}: {:.2f}".format("Policy 3 average", util.average(policy3_data))) # print("{:19}: {}".format(" # lambda calls", nol[3])) print("{:19}: {:.2f}".format("Online average", util.average(online_data))) print("{:19}: {}".format(" # supermaps", noM[0])) print("{:19}: {}".format(" # lambda calls", nol[0]))
def average_damp(f): return lambda x: average(x, f(x))