def __init__(self, node): self._node = node self._encoder = encoding.Bencode() self._translator = msgformat.DefaultFormat() self._sentMessages = {} self._partialMessages = {} self._partialMessagesProgress = {} self._delay = Delay() # keep track of outstanding writes so that they # can be cancelled on shutdown self._call_later_list = {} # keep track of bandwidth usage by peer self._history_rx = {} self._history_tx = {} self._bytes_rx = {} self._bytes_tx = {} self._unique_contacts = [] self._queries_rx_per_second = 0 self._queries_tx_per_second = 0 self._kbps_tx = 0 self._kbps_rx = 0 self._recent_contact_count = 0 self._total_bytes_tx = 0 self._total_bytes_rx = 0 self._bandwidth_stats_update_lc = task.LoopingCall( self._update_bandwidth_stats)
def sleep(): """ Induce a simple delay of 'x' seconds by sleeping """ # Read number of seconds from arguments. If not provided, default it to 10 seconds seconds = int(request.args.get("seconds", "10")) d = Delay() d.simple_delay_by_sleep(seconds) if request.method == 'POST': # If it is a POST request, simply return whatever input we have received. input_json = request.get_json() resp = jsonify({"Input received": input_json}) else: # If it is GET request, return "Successful" resp = "Successful" return resp, 201
def run(self, total, parallel, running, url, json, headers): self.cv.current_counter = 1 started_threads = [] """ Loop until all threads are submitted OR simulator is stopped explicitely """ print("Inside run. Running Flag: {}. Total: {}".format( running(), total())) while running() and self.cv.current_counter <= total(): self.cv.current_parallel = len(started_threads) print("Target: {}. Current: {}. Parallel: {}. Current: {}".format( total(), self.cv.current_counter, parallel(), self.cv.current_parallel)) # Wait for a chance before starting new thread self.wait_till_I_get_a_chance(started_threads, parallel) # Okay. Good to go. Start a new thread. d = Delay(self.cv) t = threading.Thread(target=d.hit_a_url, args=(self.cv.url, self.cv.json, self.cv.headers)) t.daemon = True started_threads.append(t) t.start() # Counter goes up self.cv.current_counter += 1 if running(): print("Submitted all {} jobs.".format(total())) print("Let's wait till the submitted jobs to finish") """ Now simulator started all the jobs OR got interrupted by user If interrupted by the user, threads will be stopped anyway. Just wait for all threads to stop gracefully """ self.wait_till_threads_complete(started_threads) print("All done.") self.cv.running = False print("Current running status inside simulator: {}".format( self.cv.running)) return
def load(self): # load all the service-objects. They work as functions, don't wrap the data, cause the data objects can be scattered to_add = DeviceTemplate() Service.all_services[to_add.get_name()] = to_add Service.template_service = to_add to_add = Statistician() Service.all_services[to_add.get_name()] = to_add to_add = Delay() Service.all_services[to_add.get_name()] = to_add to_add = NN() Service.all_services[to_add.get_name()] = to_add to_add = Rule() Service.all_services[to_add.get_name()] = to_add to_add = DeviceMonitor() Service.all_services[to_add.get_name()] = to_add
import secrets from delay import Delay from timekeeper import TimeKeeper time = TimeKeeper(0, 0, 0, 0, 0) dayCountActive = 7 # Max days left before reminder becomes active ldrMinValue = 5 # LDR value under which screen turns off [0-1023] HTTPupdateDelay = Delay(10 * 60 * 1000) # delay time in milliseconds screenUpdateDelay = Delay(1 * 1000) # delay time in milliseconds apiUrl = "http://api.lakitna.nl/?src=upy&key=" + secrets.apikey # URL to API HTTPupdateFlag = True
def buttoncheck( self): # Generator object: thread which tests and debounces wf = Timeout(self.desc['debounce']) state_id = 0 if self.long_func: longdelay = Delay(self.objSched, self.long_func, self.long_func_args) if self.double_func: doubledelay = Delay(self.objSched) while True: state = self.rawstate() if state != self.buttonstate: # State has changed: act on it now. self.buttonstate = state if state: # Button has been pressed if self.long_func and not longdelay.running(): longdelay.trigger(self.desc['long_press_time'] ) # Start long press delay if self.double_func: if doubledelay.running(): self.double_func(*self.double_func_args) else: # First click: start doubleclick timer doubledelay.trigger(self.desc['double_click_time']) if self.true_func: self.true_func(*self.true_func_args) else: # Button release if self.long_func and longdelay.running(): longdelay.stop( ) # Avoid interpreting a second click as a long push if self.false_func: self.false_func(*self.false_func_args) yield wf() # Ignore further state changes until switch has settled
'''test in online mode''' from delay import Delay from termcolor import colored import time print("\n\n$$$$$$$$$$$\ ONLINE MODE $$$$$$$$$$$\n\n") # Test Delay in online mode delay_online = Delay(delay_on=2, delay_off=0) insec = 2 rep = 2 l = [] l += [False] * 10 l += ([True] * insec + [False] * insec) * rep l += ([True] * 2 * insec + [False] * 2 * insec) * rep l += ([True] * 3 * insec + [False] * 3 * insec) * rep l += ([True] * insec + [False] * insec) * rep l += ([True] * 4 * insec + [False] * 4 * insec) * rep l += ([True] * 5 * insec + [False] * 5 * insec) * rep l += ([True] * 6 * insec + [False] * 6 * insec) * rep for c in l: time.sleep(0.4) inp = c out = delay_online(c) color = "green" if inp == out else "grey" on_c = "on_white" if inp == out else "on_red" conn = " ---------- " if inp == out else " ----/---- "
help="number of frames to consider to predict a pose", type=int, default=45) parser.add_argument("--show_lm", help="show hand landmarks", type=bool, default=True) args = parser.parse_args() hand_detect = HandDetect(detect_threshold=args.detect_threshold) hand_pose = HandPoses(pose_threshold=args.pose_threshold, name_classifier=args.path_classifier) hand_movements = HandMovements(screen_proportion=args.screen_proportion, len_moving_average=args.len_moving_average) delay = Delay(moving_average=args.moving_average, frames_in_action=args.frames_in, frames_out=args.frames_out) cap = cv2.VideoCapture(0) # start_time = time.time() # frame_count = 0 with hand_detect.mp_hands.Hands(max_num_hands=1, min_detection_confidence=0.6, min_tracking_confidence=0.5) as hands: while (True): ret, image = cap.read() raw_frame = copy.deepcopy(image) # frame_count += 1
help="number of frames to consider to predict a pose", type=int, default=40) parser.add_argument("--show_lm", help="show hand landmarks", type=bool, default=True) args = parser.parse_args() hand_detect = HandDetect(detect_threshold=args.detect_threshold) hand_pose = HandPoses(pose_threshold=args.pose_threshold, name_classifier=args.path_classifier) # This will log into Spotify using your personal account with a separate popup window spotify_controller = SpotifyControls() delay = Delay(hand_pose.classifier.classes_, moving_average=args.moving_average, frames_in_action=args.frames_in, frames_out=args.frames_out) webcam = True if webcam: cap = cv2.VideoCapture(0) else: sct = mss() with hand_detect.mp_hands.Hands(max_num_hands=1, min_detection_confidence=0.6, min_tracking_confidence=0.5) as hands: while True: if webcam: ret, image = cap.read() else: # screenshot
def buttoncheck(self): # Generator object: thread which tests and debounces wf = Timeout(self.desc['debounce']) state_id = 0 if self.long_func: longdelay = Delay(self.objSched, self.long_func, self.long_func_args) if self.double_func: doubledelay = Delay(self.objSched) while True: state = self.rawstate() if state != self.buttonstate: # State has changed: act on it now. self.buttonstate = state if state: # Button has been pressed if self.long_func and not longdelay.running(): longdelay.trigger(self.desc['long_press_time']) # Start long press delay if self.double_func: if doubledelay.running(): self.double_func(*self.double_func_args) else: # First click: start doubleclick timer doubledelay.trigger(self.desc['double_click_time']) if self.true_func: self.true_func(*self.true_func_args) else: # Button release if self.long_func and longdelay.running(): longdelay.stop() # Avoid interpreting a second click as a long push if self.false_func: self.false_func(*self.false_func_args) yield wf() # Ignore further state changes until switch has settled
#========= compute inversion ========= #inversions = {} ##for name in ['all', 'content']: #for name in ['verb', 'content']: # inversion = Inversion(args.corpus, name, para_corpus) # inversion.compute_inv_percent() # inversion.compute_inv_dist() # inversions[name] = inversion ##inversions['verb'].print_zero_inv_sent(para_corpus) ##inversions['content'].print_inversions('reuters_content_inversion.txt', para_corpus) ##sys.exit(0) #========= compute delay ========= delays = {} for name in ['all', 'verb', 'content']: delay = Delay(args.corpus, name, para_corpus) delay.compute_avg_delay() delays[name] = delay # compute average delay of all words n = 0 total_delay = 0 for d in delay.delays: if d: n += len(d) total_delay += sum(d) print 'Average delay of %s: %f' % (name.upper(), total_delay / float(n)) #========= compute passive ========= passivization = Passivization(args.corpus, para_corpus) passivization.compute_pass_condition()
def random_date(start,l): current = start while l >= 0: tdl = datetime.timedelta(seconds=randrange(1,7)) #print(tdl) current = current + tdl yield current l-=1 data = [] startDate = datetime.datetime(2019, 9, 20,13,00) for x in random_date(startDate,20): prev = sig_gen(prev) data.append((x, prev)) delay_offline = Delay(delay_on=3, delay_off=4) for t, d in data: inp = d out = delay_offline(d, t.timestamp()) color = "green" if inp == out else "grey" on_c = "on_white" if inp == out else "on_red" conn = " ---------- " if inp == out else " ----/---- " print(colored(str(d) + conn + str(out) , color, on_c, attrs=['bold'])) print("$$"*20) print()