def analyseRegle(self): """ Analyse la règle et stocke les paramètres dans les attributs de l'objet Permet d'éviter de réanalyser complètement la règle pour chaque mot. """ if self.regle.get_amorce(): # si la règle contient une amorce if self.regle.get_amorce() == "lettre": if self.regle.get_apartide(): self.amorces = increment(self.regle.get_apartide(), len(self.files)) else: self.amorces = increment('aaa', len(self.files)) elif self.regle.get_amorce() == "chiffre": if self.regle.get_apartide(): self.amorces = increment(self.regle.get_apartide(), len(self.files)) else: self.amorces = increment('000', len(self.files)) elif self.regle.get_amorce() == "aucune": self.amorces = "" if (self.amorces == False): self.errorList.append( "Amorce trop courte pour le nombre de fichiers à renommer. Essayez de rajouter un caractère" ) # analyse du reste de la règle if self.regle.get_prefixe(): self.prefixe = self.regle.get_prefixe() self.fileName = self.regle.get_nomFichier() if self.regle.get_postfixe(): self.postfixe = self.regle.get_postfixe()
def chunked_speaking_turns(speaking_events, n=5): turns = [{}] # if there are no events thats it thats all if len(speaking_events) == 0: return [] chunk_start = speaking_events[0]["speaking_start"] minutes = 60 chunk_len = n * minutes chunk_end = chunk_start + chunk_len chunk_counter = 0 for event in speaking_events: key = event["participant_key"] speaking_end = int(event["speaking_end"]) speaking_start = int(event["speaking_start"]) if speaking_start >= chunk_start and speaking_start < chunk_end: utils.increment(turns[chunk_counter], key, 1) elif speaking_end < chunk_end: utils.increment(turns[chunk_counter], key, 1) if speaking_start > chunk_end: chunk_counter += 1 chunk_start = chunk_end + 1 chunk_end = chunk_start + chunk_len turns.append({}) return turns
def prompting(speaking_events): """ Take a list of speaking events from a meeting Returns a json object of how many times a participant spoke after each participant. { <key>: { <key>: x, <key>: y, ... }, ... } """ prompts = {} if not speaking_events: #TODO raise exception? # this means we were given an empty list of events # probably shouldnt happen ever return {} sorted_events = sorted(speaking_events, key=lambda event: int(event['speaking_end'])) # need to keep track of who spoke last last_speaker = sorted_events[0]["participant_key"] # skip the first event since we already grabbed the first speaker for event in sorted_events[1:]: current_speaker = event["participant_key"] following = prompts[last_speaker] if last_speaker in prompts else {} utils.increment(following, current_speaker, 1) prompts[last_speaker] = following last_speaker = current_speaker return prompts
def speaking_time(speaking_events): """ Takes a list of speaking events from a meeting Returns a json object indicating the total speaking time in seconds for each participant """ time = {} for event in speaking_events: key = event["participant_key"] duration = int(event["speaking_end"]) - int(event["speaking_start"]) utils.increment(time, key, duration) return time
def backpropagate( self, reward ): # next_to_move = 0 if player 1 to move, and 1 if player 2 to move self.num_visits += 1 if isinstance(reward, list): if (reward[0] == 1) and (self.state.next_to_move == 1): # i won! reward = 1 else: reward = 0 increment(self.results, reward) if self.parent is not None: self.parent.backpropagate(reward)
def chunked_speaking_time(speaking_events, n=5): """ Takes a list of speaking events from a meeting and splits it into n-minute speaking time breakdowns :param speaking_events: speaking events JSON :param n: how long each chunk is, in minutes """ time = [{}] # if there are no events thats it thats all if len(speaking_events) == 0: return [] chunk_begin = speaking_events[0]["speaking_start"] minutes = 60 chunk_len = n * minutes chunk_end = chunk_begin + chunk_len chunk_counter = 0 for event in speaking_events: key = event["participant_key"] speaking_end = int(event["speaking_end"]) speaking_start = int(event["speaking_start"]) if speaking_end < chunk_end: # the entire speaking event is within the confines of this chunk #TODO DRY duration = speaking_end - speaking_start utils.increment(time[chunk_counter], key, duration) elif speaking_start < chunk_end: # the speaking event is split across two chunks # we will need to split the duration accordingly curr_chunk_duration = chunk_end - speaking_start utils.increment(time[chunk_counter], key, curr_chunk_duration) next_chunk_duration = speaking_end - chunk_end #TODO DRY chunk_counter += 1 chunk_begin = chunk_end + 1 chunk_end = chunk_begin + chunk_len time.append({}) utils.increment(time[chunk_counter], key, next_chunk_duration) else: # the event is entirely in the next chunk #TODO DRY chunk_counter += 1 chunk_begin = chunk_end + 1 chunk_end = chunk_begin + chunk_len time.append({}) #TODO DRY duration = speaking_end - speaking_start utils.increment(time[chunk_counter], key, duration) return time
def speaking_turns(speaking_events): """ Takes a list of speaking events from a meeting Returns a json object indicating the number of turns taken for each participant """ turns = {} last_speaker = "" sorted_events = sorted(speaking_events, key=lambda e: e["speaking_start"]) for event in sorted_events: key = event["participant_key"] if last_speaker == key: # if the last speaker was the same, we don't have a new turn continue utils.increment(turns, key, 1) last_speaker = key return turns
def increment(a: MutableSequence[bool], l: int, r: int) -> bool: if l == r: return False if a[l]: a[l] = False return increment(a, l + 1, r) else: a[l] = True return True
def limirizacaoLocal(imagem, tipoMedia='local', n=20, a=0, b=1): limit = int(n / 2) aux = np.shape(imagem) if np.size(aux) > 2: imagem = imagem[:, :, 0] aux = np.shape(imagem) segmImg = np.zeros(aux) for j in range(0, aux[0]): for i in range(0, aux[1]): area = imagem[utils.increment(-limit, j, aux[0] ):utils.increment(limit, j, aux[0]), utils.increment(-limit, i, aux[1]):utils. increment(limit, i, aux[1])] Txy = a * np.var(area) + b * (np.mean(area) if tipoMedia == 'local' else np.mean(imagem)) segmImg[j][i] = 1 if imagem[j][i] > Txy else 0 return segmImg # def dividirFundirRegioes(imagem) # TODO # usará os metodos dividiRegiao e uniRegiao em utils
def on_status(self, tweet): if utils.is_Invalid_tweet(tweet, self.latest_tweet_id, self.me.id, self.file_name): return try: tweet.retweet() logger.info("Tweet Retweeted") tweet_number = utils.increment(self.nr_tweets) logger.info(tweet.id) utils.write_to_file(self.file_name, tweet.text) wait_minutes = 7 logger.info(f"{datetime.datetime.now()} Tweet {tweet_number}: " f"{tweet.text}") if not self.follow_limit_reached(): if not tweet.user.following: logger.info( f'Follow user {tweet.user.name.encode("utf-8")}') tweet.user.follow() self.follow_counter = self.follow_counter + 1 if utils.is_retweeted_tweet(tweet): logger.info( f'Follow user {tweet.retweeted_status.user.name.encode("utf-8")}' ) tweet.retweeted_status.user.follow() self.follow_counter = self.follow_counter + 1 self.reset_limit_counters() self.set_tweet_id(tweet.id) logger.info(f" waiting for {wait_minutes} minutes ...") time.sleep(wait_minutes * 60) except tweepy.TweepError as e: logger.error(e.reason) except UnicodeEncodeError as e: logger.error(e.reason) pass except ConnectionResetError: logger.error("Error detected") pass
l2A = hstack(l2a, l2b) lA = hstack(vstack(l1A, l2A), ll) A = vstack(aA, bA, lA) B = vstack(abB, lB) print("A,B =") print(hstack(A, B)) m: List[bool] = np.zeros((a + b + n), dtype=bool) # mask m[-2] = 1 m[-1] = 1 # TODO: check that the stationary point is a minimum v: List[Tuple] = [] while increment(m, 0, a): while increment(m, a, a + b): print("m =", m) Am = A[m][:, m] # TODO: ? Bm = B[m] print("Am,Bm =") print(hstack(Am, Bm)) try: xm = np.linalg.solve(Am, Bm).T[0] except np.linalg.LinAlgError: print("Singular") else: print("xm =", xm) x: Sequence = distribute(xm, m) p1 = x[0:a] p2 = x[a:a + b]
def level(path): ''' Display, the question, validate answers, hints and increment user level. ''' if is_banned(get_db().cursor(), current_user.id): print 'here' return redirect('/logout') if not event_start(EVENT_DATA): if ENV_DEV: pass else: return redirect('/') level_index = routing(EVENT_DATA, path, 'index') user_index = get_user_level(get_db().cursor(), current_user.id) if level_index > user_index: return redirect(routing(EVENT_DATA, user_index, 'path')) data = get_level_data(EVENT_DATA, path) if data is None: return redirect('/') if request.method == 'POST': answer = request.form.get('answer') correct, hint, text = validate_answer(data, answer) if correct: if user_index == level_index: increment(get_db(), current_user.id, (level_index + 1)) if (level_index + 1) > len(EVENT_DATA['levels']): return redirect('/congratulations') return redirect(routing(EVENT_DATA, (level_index + 1), 'path')) elif hint: return render_template('level.html', year=YEAR, event=EVENT_DATA['name'], host=EVENT_DATA['host'], faq=EVENT_DATA['faq'], social=EVENT_DATA['social'], discuss=EVENT_DATA['discuss'], user=current_user.id, media=data['media'], hint=hint, hint_text=text, text=data['text'], level=level_index, title=data['title'], source=data['source']) return render_template('level.html', year=YEAR, event=EVENT_DATA['name'], host=EVENT_DATA['host'], faq=EVENT_DATA['faq'], social=EVENT_DATA['social'], discuss=EVENT_DATA['discuss'], user=current_user.id, media=data['media'], hint=False, hint_text='', text=data['text'], level=level_index, title=data['title'], source=data['source']) else: return render_template('level.html', year=YEAR, event=EVENT_DATA['name'], host=EVENT_DATA['host'], faq=EVENT_DATA['faq'], social=EVENT_DATA['social'], discuss=EVENT_DATA['discuss'], user=current_user.id, media=data['media'], hint=False, hint_text='', text=data['text'], level=level_index, title=data['title'], source=data['source'])