def click_func_key(): if src == "=": try: self.val_ans = count(self.answerLabel.text(), self.val_ans) except Exception as e: QtWidgets.QMessageBox.critical( self, "MyCalculator", "Error Happened!\n" + str(e)) self.answerLabel.clear() return self.answerLabel.setText(str(self.val_ans)) return if src == "AC": self.answerLabel.clear() return if src == "Del": s = self.answerLabel.text() try: s = s[:-2] except IndexError: pass self.answerLabel.setText(s) return if src == "Insert Function": ans = QtWidgets.QInputDialog.getItem(self, "MyCalculator", "Choice A Function:", FUNCTIONS) if not ans[1]: return text = self.answerLabel.text() + str(ans[0]) + "(" self.answerLabel.setText(text) return text = self.answerLabel.text() + SYMBOLS_INPUT[src] self.answerLabel.setText(text)
def count_helper(fds): fds['count_fd'], fds['control_fd'] = counter.open_counter(args.tdc) count = counter.count(fds['control_fd'], fds['count_fd'], args.tdc) counter.close(fds['control_fd'], fds['count_fd']) if count!=None: return count else: return count_helper(fds)
def show_result(name, counter, signal, do_print=False, plot=True): count_result = counter.count(signal) format_str = "{}:\nunified_count: {}, sub_counts:{}\nnn_count:{}, nn_sub_count:{}\n" to_print = format_str.format(name, count_result['unified_count'], count_result['max_counts'], count_result['unified_marked_count'], count_result['max_marked_counts']) print(to_print) if plot==True: plotting.plot_extrema_df_marked(signal, name, count_result)
def objects(examID,exam_loc): """ Uses the Series class to make an object for each series found in the local computer's files. Takes in examID and exam_loc as strings. Returns a list of Series's objects. """ series,filenames,user=query.harddrive(exam_loc) #needs dicom files only objects=[] print 'Creating objects...' j=0 while j<len(series): objects.append(Series(series[j],filenames[j],examID,exam_loc)) j+=1 counter.count(objects,exam_loc,user) counter.size(objects) return objects
def objects(examID, exam_loc): """ Uses the Series class to make an object for each series found in the local computer's files. Takes in examID and exam_loc as strings. Returns a list of Series's objects. """ series, filenames, user = query.harddrive( exam_loc) #needs dicom files only objects = [] print 'Creating objects...' j = 0 while j < len(series): objects.append(Series(series[j], filenames[j], examID, exam_loc)) j += 1 counter.count(objects, exam_loc, user) counter.size(objects) return objects
def test_two_trigrams(self): test_input = "this has two trigrams" output = counter.count([test_input]) self.assertTrue("this has two" in output) self.assertTrue("has two trigrams" in output) self.assertEqual(output["this has two"], 1) self.assertEqual(output["has two trigrams"], 1) # negative tests to make sure our gram "window" isn't sliding too far self.assertTrue("two trigrams" not in output) self.assertTrue("trigrams" not in output) self.assertEqual(len(output.keys()), 2)
def test_extremely_large_input(self): """ This was for doing a convenient in-memory stress test without having to gather real files """ test_input = "" # This will produce a string the size of just over 54 copies of Origin of Species total_occurrences = 5000000 for i in range(total_occurrences): test_input += "big text here " output = counter.count([test_input]) self.assertTrue("big text here" in output) self.assertEqual(output["big text here"], total_occurrences)
def images_handler(self): image_path = QFileDialog.getExistingDirectory(self, "Select Image Directory") # image_path = input("Enter Image Path:") imag = os.listdir(image_path) images = [os.path.join(image_path, t) for t in imag] # pprint(images) # images = self.get_frame(images) self.frame_counter = count() # images = sorted(images, key=lambda x: int(x[6])) for image in images: self.frame_counter.set(image) self.frame_counter.set_target_as_zero() # self.frame_counter.sort_dict() # pprint(self.frame_counter.display_all()) return self.frame_counter
def test_2(self): result = count('MyHeartWillGoOn') self.assertEqual( result, { 'M': 1, 'y': 1, 'H': 1, 'e': 1, 'a': 1, 'r': 1, 't': 1, 'W': 1, 'i': 1, 'l': 2, 'G': 1, 'o': 1, 'O': 1, 'n': 1 })
def test_strip_special_chars(self): test_input = r"super,simple.test:a;few!more&words\"here'and?there" output = counter.count([test_input]) self.assertTrue("super simple test" in output) self.assertEqual(output["super simple test"], 1) self.assertTrue("simple test a" in output) self.assertEqual(output["simple test a"], 1) self.assertTrue("test a few" in output) self.assertEqual(output["test a few"], 1) self.assertTrue("a few more" in output) self.assertEqual(output["a few more"], 1) self.assertTrue("few more words" in output) self.assertEqual(output["few more words"], 1) self.assertTrue("more words here" in output) self.assertEqual(output["more words here"], 1) self.assertTrue("words here and" in output) self.assertEqual(output["words here and"], 1) self.assertTrue("here and there" in output) self.assertEqual(output["here and there"], 1)
def assess_data(input_file='data.json'): """Assessment of source data acquired from Docker Hub API""" counter.count(input_file)
def count_in_cython(arr): return counter.count(arr)
import counter as c import time start = time.clock() for x in range(0, 100): count_fd, control_fd = c.open_counter(10) print c.count(control_fd, count_fd, 10) time.sleep(10.0 / 1000) c.close(control_fd, count_fd) print time.clock() - start
import struct import counter for i in range(0, 10): counter.count() with open(counter.file_name, 'rb') as count_file: num = count_file.read(counter.chunk_size) while num: print(struct.unpack('i', num)[0]) num = count_file.read(counter.chunk_size)
positions.append([pos_x, pos_y, radius]) dot_mask[pos_x - int(radius / 2):pos_x + int(radius / 2), pos_y - int(radius / 2):pos_y + int(radius / 2)] = 255 dot_mask = cv2.erode(dot_mask, None, iterations=10) dot_mask = cv2.dilate(dot_mask, None, iterations=15) cv2.imshow('this', dot_mask) num_dot, markers = cv2.connectedComponents(dot_mask) for dot in range(num_dot - 1): index = np.where(markers == dot + 1) this_mask = np.zeros((markers.shape[0], markers.shape[1], 3), np.uint8) this_mask[markers == dot + 1] = 255 this_mask = cv2.bitwise_and(this_mask, img) # cv2.imshow(str(dot),this_mask) # cv2.waitKey() dot_img = np.zeros( (index[0].max() - index[0].min(), index[1].max() - index[1].min(), 3), np.uint8) dot_img = this_mask[index[0].min():index[0].max(), index[1].min():index[1].max()] img = count(img, this_mask, index[0].min(), index[1].min()) # cv2.imshow(str(dot),dot_img) # cv2.waitKey() print(num_dot) cv2.imshow('num', img) cv2.waitKey(0)
def test_number(self): text = '1 2 3' result = counter.count(text) self.assertEqual(result, {'quantity': 3, 'distinct': 3})
def test_empty_string_should_return_empty_dict(self): output = counter.count([""]) self.assertEqual({}, output)
def test_4(self): result = count('12341234') self.assertEqual(result, {'1': 2, '2': 2, '3': 2, '4': 2})
def test_super_simple_three_word_input(self): test_input = "super simple test" output = counter.count([test_input]) self.assertTrue("super simple test" in output) self.assertEqual(output["super simple test"], 1) self.assertEqual(len(output.keys()), 1) # total trigrams expected
def test_simple_repeated_trigram(self): test_input = "apples are tasty and also apples are tasty" output = counter.count([test_input]) self.assertTrue("apples are tasty" in output) self.assertEqual(output["apples are tasty"], 2) self.assertEqual(len(output.keys()), 5)
def test_super_simple_mixed_case(self): test_input = "super simple test SUPER SIMPLE TEST" output = counter.count([test_input]) self.assertTrue("super simple test" in output) self.assertEqual(output["super simple test"], 2) self.assertEqual(len(output.keys()), 3)
def test_3(self): result = count('HAHAHAHAHAHAHA') self.assertEqual(result, {'H': 7, 'A': 7})
def test3(): assert student.count(0, 10, -1) == ""
def test_1(self): result = count('') self.assertEqual(result, {})
def test4(): assert student.count(10, 0, -1) == "10 9 8 7 6 5 4 3 2 1 0 "
END_DLY = 70 FILENAME = 'dll_swp_5ps.csv' datalist = [] delay_fd = Gpib(name=DEVICE_NAME, pad=PRIMARY_ADDR) delay_fd.write("DLY {}".format(INIT_DLY)) time.sleep(3) start = time.clock() delay_fd.write("DLY {}".format(END_DLY)) for i in range(0, LOOPTILL): count_fd, control_fd = c.open_counter(INT_TIME) count = c.count(control_fd, count_fd, INT_TIME) datalist.append([count, time.clock() - start + 0.001 * (i + 1)]) c.close(control_fd, count_fd) #print('{},{}'.format(count,time.clock()-start)) print(time.clock() - start) save = open(FILENAME, 'w+') save.write('count, time\n') for data in datalist: out = '{}, {}\n'.format(data[0], data[1]) print out save.write(out) save.close()
def test5(): assert student.count(0, 100, 7) == "0 7 14 21 28 35 42 49 56 63 70 77 84 91 98 "
def count(string): return counter.count(string)
def test1(): assert student.count(1, 10, 2) == "1 3 5 7 9 "
def test_base(self): text = 'one two three' result = counter.count(text) self.assertEqual(result, {'quantity': 3, 'distinct': 3})
def test2(): assert student.count(0, 10, 2) == "0 2 4 6 8 10 "