def test_register_existed_user(self): if not self.check_files_exist(): prepare() users = get_users() first_users_len = len(users) nickname = users[0] self.assertFalse(register_user(nickname)) users = get_users() self.assertEqual(len(users), first_users_len)
def test_register_new_user(self, mock_record): prepare() users = get_users() first_users_len = len(users) new_user = '******' mock_record.return_value = wavfile.read('speakers/liza_register.wav') self.assertFalse(new_user in users) self.assertTrue(register_user(new_user)) users = get_users() self.assertEqual(len(users), first_users_len + 1) self.assertTrue(new_user in users)
def test_login_legal_user_not_from_training_set(self, mock_record): if not self.check_files_exist(): prepare() users = get_users() speaker_file = join(users[0], listdir(users[0])[-1]) mock_record.return_value = wavfile.read(speaker_file) self.assertTrue(login_user())
def test_login_illegal_user_not_from_training_set(self, mock_record): if not self.check_files_exist(): prepare() users = get_users() illegal_user = '******' self.assertFalse(illegal_user in users) mock_record.return_value = wavfile.read(join(illegal_user, 'ru_0014.wav')) self.assertFalse(login_user())
def test_login_unknown_illegal_user(self, mock_record): if not self.check_files_exist(): prepare() users = get_users() illegal_user = '******' self.assertFalse(illegal_user in users) mock_record.return_value = wavfile.read(join(illegal_user, 'ru_0042.wav')) self.assertFalse(login_user())
def test_prepare(self): for file in self.files: if os.path.isfile(file): os.remove(file) prepare() for file in self.files: self.assertTrue(pathlib.Path(file).is_file()) users = get_users() self.assertTrue(len(users) > 0)
opt_ins = self.get_weekly_opt_ins() user_ids = [u.user_id for u in self.users] for opt_in in opt_ins: if str(opt_in) not in user_ids: msg = msg_no_name % (opt_ins[opt_in]) if debug: print msg else: print message_client.send(msg,str(opt_in)) def send_pair_assignment_messages(self,finish_date,pairs,debug=True): msg_no_names = Text(self.group_id).assign_pair for pair in pairs: msg = msg_no_names % (finish_date,pair[0].name,pair[1].name) if debug: print msg else: self.message_client.send2(msg,[str(p.user_id) for p in pair]) if __name__ == "__main__": spam_missing_surveys = True for group_id in Config.groups: main = Main(group_id) main.get_users() if spam_missing_surveys: main.send_missing_survey_messages() pairs = main.analyze_pairs() main.send_pair_assignment_messages("April 17th", pairs)
print self.message_client.send(msg,str(opt_in)) print msg def send_pair_assignment_messages(self,finish_date,pairs,debug=True): """Send message to pairs of users alerting them to their pairings""" msg_no_names = Text(self.group_id).assign_pair if raw_input('Continue Sending Messages - T or F : ') != "T": return for pair in pairs: msg = msg_no_names % (finish_date,pair[0].name,pair[1].name) if raw_input("Send Pair %s -- %s -- T or F: " % (pair[0].name,pair[1].name)) != "T": print "Skipping %s -- %s" % (pair[0].name,pair[1].name) continue else: if debug: print "DEBUG ONLY - NOT ACTUALLY SENDING" print msg else: self.message_client.send2(msg,[str(p.user_id) for p in pair]) if __name__ == "__main__": spam_missing_surveys = False for group_id in Config.groups: main = Main(group_id) main.get_users() if spam_missing_surveys: main.send_missing_survey_messages() pairs = main.analyze_pairs() # main.send_pair_assignment_messages("May 29th", pairs,False)
freqs = get_full_frequencies(users_tokens) freq_pairs = freqs.items() wc = WordCloud(max_words=2000, mask=trump_coloring, max_font_size=40, random_state=42) wc.generate_from_frequencies(freq_pairs) image_colors = ImageColorGenerator(trump_coloring) # plt.imshow(wc) # plt.axis("off") # # plt.figure() plt.imshow(wc.recolor(color_func=image_colors)) # recolor wordcloud and show # we could also give color_func=image_colors directly in the constructor # plt.imshow(trump_coloring, cmap=plt.cm.gray) plt.axis("off") plt.show() if __name__ == "__main__": df_users = main.get_users() # df_users = df_users[:1000] users, users_tokens = collect_users_tokens(df_users) token_set = get_full_token_set(users_tokens) v = DictVectorizer() vs = v.fit_transform(users_tokens) np.savez("files/out_4.dat", data=vs, users=users, users_tokens=list(token_set)) draw_tag_cloud(users_tokens)
sim = Simulator() sim.simulate(200) ## By adding a seed parameter, you can have reproducible sims self.users = sim.get_users() # ## Print some summaries # for user in users: # user.to_string() # Print some descriptive stats print "# Users", len(self.users), [u.name for u in self.users] def analyze_pairs(self): # Analyze pairs ## This is a very basic algorithm that only makes use of geography ## TODO: Update algorithm to incorporate more than geography analyze = Analyze(self.users) analyze.analyze_easy_potentials() analyze.get_best_matches() potential_pairs = analyze.get_potential_pairs() # for user in users: # if user.user_id not in potential_pairs: # print "No Matches for:", user.name # print user.user_id,user.name if __name__ == "__main__": for group_id in Config.groups: main = Main() main.get_users(group_id) main.analyze_pairs()
def test_request_response(self): response = get_users() # Assert that the request-response cycle completed successfully with status code 200. self.assertEqual(response.status_code, 200)