def test_post_collected_tweets(mock_get, test_status): """Verify post_collected_tweets method returns None Notes: * Mock PostUpdate without making real call to Twitter API """ expected_num_of_ids = 4 status_id_file = Path(__file__).parent.joinpath( "../conf/list_of_status_ids_replied_to.txt" ) list_of_status_ids_replied_to = list(file_reader(status_id_file)) assert len(list_of_status_ids_replied_to) == expected_num_of_ids, ( f"Expected number ({expected_num_of_ids}) of status ids replied to " f"did not match actual ({len(list_of_status_ids_replied_to)})" ) quoted_tweet = test_status("post_reply_response") mock_get.return_value = quoted_tweet response = post_collected_tweets(quoted_tweets=[Tweet(quoted_tweet)]) new_list_of_status_ids_replied_to = list(file_reader(status_id_file)) assert ( str(quoted_tweet.in_reply_to_status_id) == new_list_of_status_ids_replied_to[-1] ), "Expected status id to be last item in list" assert response # clean up by overwriting file with original list with status_id_file.open(mode="w") as f: for line in list_of_status_ids_replied_to: f.write(line + "\n")
def main(): if len(sys.argv) == 3: paths = [sys.argv[1], sys.argv[2]] else: print('please give point cloud file and vehicle trajectory') return plat, plon, palt, pit = np.array(file_reader(paths[0])).T trajlat, trajlon, trajalt, trajit = np.array(file_reader(paths[1])).T trajectory = np.array([[trajlat[0], trajlon[0]], [trajlat[-1], trajlon[-1]]]) traj_direction = trajectory[1] - trajectory[0] new_road_points = road_surface_detection(plat, plon, palt, pit, trajectory) scan_line = scan_line_generator(new_road_points, trajectory) scan_line = boundary_selection(scan_line) intensity = intensity_selection(scan_line) refine_list = lane_marking_refinement(intensity, traj_direction) line_cluster = lane_marking_selection(refine_list, traj_direction) ls = lane_marking_generation(line_cluster) fig = plt.figure() ax = fig.add_subplot(111) ax.plot(plat, plon, ',') for l in ls: ax.plot(l[0], l[1], color='black', linestyle='-') plt.savefig('result.png') plt.show()
def main(): # prepare data print("Split ratio should be a decimal value between 0 and 1") split = float( input("Enter split ratio for the training and testing set : ")) print("enter a positive odd integer value for K nearest neighbour : ") k = int(input("define K for the evaluation : ")) training_set, test_set = util.file_reader(split) print('Train set: ' + repr(len(training_set))) print('Test set: ' + repr(len(test_set))) # generate predictions predictions = [] for x in range(len(test_set)): neighbors = get_neighbours(training_set, test_set[x], k) result = get_response(neighbors) predictions.append(result) # print('> predicted=' + repr(result) + ', actual=' + repr(test_set[x][-1])) accuracy = get_accuracy(test_set, predictions) print('Accuracy: ' + repr(accuracy) + '%')
def robin_karp(str, substr, d, q): n = len(str) m = len(substr) h = pow(d, m - 1) % q substr_hash = 0 str_hash = 0 for s in range(m): substr_hash = (d * substr_hash + ord(substr[s])) % q str_hash = (d * str_hash + ord(str[s])) % q for i in range(n - m + 1): if substr_hash == str_hash: match = True for j in range(m): if substr[j] != str[i + j]: match = False break if match: return i if i < n - m: str_hash = (d * (str_hash - ord(str[i]) * h) + ord(str[i + m])) % q if str_hash < 0: str_hash = str_hash + q return -1 if __name__ == '__main__': content = file_reader("data.txt") print(robin_karp(content, 'А табаку-то вчера дал? То-то, брат. Ну, на, Бог с тобой', 256, 101))
accuracy = 0 output_length = len(output) for i in range(output_length): k = 0 for j in range(len(output[i])): if results[i][j] == output[i][j]: k += 1 if k == 4: accuracy += 1 print('total no of inputs : ', output_length) print("Accurately predicted : ", accuracy) return (accuracy / output_length) * 100 if __name__ == '__main__': training, testing, classes = util.file_reader() input_matrix1, output_matrix1 = get_matrices(testing) input_matrix = np.array([[0.997, 0.9991, 0.9985, 0.9978, 0.9988, 0.9984], [0.334, 1.194, 1.172, 3.335, 0.981, 0.979], [1.172, 0.334, 1.194, 0.981, 3.335, 0.979], [1.194, 1.172, 0.334, 0.981, 0.979, 3.335], [0.471, 0.650, 0.986, 5.379, 5.379, 0.983], [0.986, 0.471, 0.650, 0.984, 5.379, 5.379], [0.471, 0.986, 0.650, 5.379, 0.984, 5.379], [0.205, 0.205, 1.188, 7.187, 7.855, 0.985], [1.188, 0.205, 0.205, 0.985, 7.187, 7.855], [0.205, 1.188, 0.205, 7.187, 0.985, 7.855]]) output_matrix = np.array([[0, 0, 0, 0], [1, 0, 0, 1],