def test_init_uses_connection_pooling(self): lb0 = leaderboard.Leaderboard('lb0', db=0) lb1 = leaderboard.Leaderboard('lb1', db=0) lb2 = leaderboard.Leaderboard('lb2', db=1) self.assertEquals(lb0.redis_connection.connection_pool, lb1.redis_connection.connection_pool) self.assertNotEquals(lb0.redis_connection.connection_pool, lb2.redis_connection.connection_pool)
async def leaderboard(self, ctx): owner_id = database.get_owner_id(self.client.db, ctx.guild.id) session_cookie = database.get_session_cookie(self.client.db, ctx.guild.id) leaderboard = lb.Leaderboard(owner_id, session_cookie) await ctx.send(embed=await leaderboard.make_embed( ctx, self.client, from_cached=False))
def __init__(self, screen, clock): self.screen = screen self.clock = clock self.game_started = False self.quit_button = menu.MenuButton(display_width / 2 - 150, display_height / 2, quit_button_img, "quit") self.start_button = menu.MenuButton(display_width / 2 - 150, display_height / 4, start_button_img, "start") self.leaderboard_button = menu.MenuButton(display_width / 2 - 450, display_height / 6, leaderboard_button_img, "leaderboard") self.back_button = menu.MenuButton(display_width / 4, display_height - 100, back_button_img, "back") self.menu_table = menu.MainMenu(self.screen, self.quit_button, self.start_button, self.leaderboard_button) self.leaderboard_table = leaderboard.Leaderboard( leaderboard_storage, screen) self.create_start_leaderboard() self.death_screen_table = death_screen.Death_screen( screen, self.back_button) self.game_surface = terrain.Terrain() self.player = player.Player(PLAYER_POS_X, PLAYER_POS_Y, self.screen) self.army = player.AlienArmy(self.player, self.screen)
async def leaderboard_error(self, ctx, error): if isinstance(error, commands.CommandOnCooldown): owner_id = database.get_owner_id(self.client.db, ctx.guild.id) session_cookie = database.get_session_cookie( self.client.db, ctx.guild.id) leaderboard = lb.Leaderboard(owner_id, session_cookie) await ctx.send(embed=await leaderboard.make_embed( ctx, self.client, from_cached=True))
def test_leaders_ascending(self): lb = leaderboard.Leaderboard('asc', order='asc') for index in range(1, 11): lb.rank_member("member_%d" % index, index) leaders = lb.leaders(1) self.assertEquals(10, len(leaders)) self.assertEquals('member_1', leaders[0]['member']) self.assertEquals('member_10', leaders[-1]['member'])
def test_match_history_recording(self): rob = player.Player("Rob", 1200) zak = player.Player("Zak", 1200) board = leaderboard.Leaderboard() board.add_player(rob) board.add_player(zak) board.recordMatch(zak.name, 1, rob.name, 0) self.assertEqual(len(rob.matchHistory), 1) self.assertEqual(len(zak.matchHistory), 1)
def __init__(self, parent): super().__init__(parent) self.select_bar = surface_object( self.display_screen.w / 2.5, self.display_screen.h / 14, round((self.display_screen.w - self.display_screen.w / 2.5) / 2), 10, DGREY) self.leader_board_display = surface_object( self.display_screen.w / 1.3, self.display_screen.h / 1.3, round((self.display_screen.w - self.display_screen.w / 1.3) / 2), (self.display_screen.h - self.display_screen.h / 1.3) / 2, DDGREY) self.scroll_bar_frame = surface_object(self.w / 70, self.h / 1.55, self.x * 7.5, (self.h - self.h / 1.55) / 2, SGREY) self.refresh_button = button(self.display_screen, 'REFRESH', startpos=((self.display_screen.w - 200) / 2, self.display_screen.h + 27), size=(200, 50)) quicktype_scores = leaderboard.Leaderboard(user, 'quicktype', 'global', parent, self.leader_board_display.w, self.leader_board_display.h, self.leader_board_display.x, self.h / 3.9) integer_scores = leaderboard.Leaderboard(user, 'integerrecall', 'global', parent, self.leader_board_display.w, self.leader_board_display.h, self.leader_board_display.x, self.h / 3.9) self.select_scores = button_grouper( self.select_bar, ['QUICKTYPE', 'INTEGER RECALL'], button, frames=[quicktype_scores, integer_scores], pos=(0, self.display_screen.y + self.select_bar.y), sizes=(0, self.select_bar.h), centerx=True, style=1)
def __init__(self): self.window = 'start' self.username = '******' self.AI = 'user/no AI' self.mode = 'unique colors' self.sessionlogfile = '.mastermind_session.log' self.logfile = '.mastermind.log' #initiate screens #START self.select_username_button = button.Button(left, 50, width, height, GREY, BLACK, 'select username', BLACK) self.select_ai_button = button.Button(left, 150, width, height, GREY, BLACK, 'select AI', BLACK) self.toggle_color_button = button.Button(left, 250, width, height, GREY, BLACK, self.mode, BLACK) self.show_leaderboard_button = button.Button(left, 350, width, height, GREY, BLACK, 'show leaderboard', BLACK) self.start_game_button = button.Button(left, 450, width, height, GREY, BLACK, 'start game', BLACK) self.stop_game_button = button.Button(left, 550, width, height, GREY, BLACK, 'stop game', BLACK) #AI self.user_button = button.Button(left, 100, width, height, GREY, BLACK, 'user/no AI', BLACK) self.ai1_button = button.Button(left, 200, width, height, GREY, BLACK, 'simple AI', BLACK) self.ai2_button = button.Button(left, 300, width, height, GREY, BLACK, 'RL AI', BLACK) self.ai3_button = button.Button(left, 400, width, height, GREY, BLACK, 'RL DL AI', BLACK) self.back_button = button.Button(left, 500, width, height, GREY, BLACK, 'back', BLACK) #LEADERBOARD self.leadtable = leaderboard.Leaderboard() self.lb_show_button = button.Button(60, 600, 130, 40, GREY, BLACK, 'stats', BLACK) self.lb_back_button = button.Button(210, 600, 130, 40, GREY, BLACK, 'back', BLACK) self.lb_window = 'leaderboard' #USERNAME self.topnames = self.leadtable.top_names() self.username_list_buttons = [] for i,key in enumerate(self.topnames): x = 150 + 100*i self.username_list_buttons.append(button.Button(left, x, width, height, GREY, BLACK, key, BLACK)) self.text_input = text_inputbox.InputBox(200, 50, 150, 150, height, WHITE, BLACK, "enter username", BLACK, GREY) #self.ok_button = button.Button() #GAME self.thisgame = mastermindgame2.MastermindGame() # initiate game, reset all pygame.init() # choose font self.myfont = pygame.font.SysFont("arial", 17) size = (400, 650) self.screen = pygame.display.set_mode(size) pygame.display.set_caption("My MasterMind")
def feederboard_for(self, user_id, aggregate=None): """Retrieve a reference to the activity feed for a given `user_id`. :param user_id: [string] User ID. :param aggregate: [boolean, False] Whether to retrieve the aggregate feed for `user_id` or not. @return reference to the activity feed for a given `user_id`. """ if aggregate is None: aggregate = self.aggregate return leaderboard.Leaderboard(self.feed_key(user_id, aggregate), connection_pool=self.redis.connection_pool)
def __init__(self, data): """ In need of cleaning up """ self.sia = SIA() self.data = data # Raw JSON Data self.df = None # Dataframe self.total_negative = 0 self.total_positive = 0 self.total_compound = 0 self.unique_names = set() self.posts_per_user = {} self.leader_board = leaderboard.Leaderboard() self.add_sentiment_fields() self.blocks = self.create_time_blocks() self.populate_time_blocks()
def __init__(self, parent): super().__init__(parent) self.move_val = 0 self.display_screen = surface_object(self.w - self.w / 6, self.h, self.w / 6, self.y, DGREY) self.display_screen.surface.set_alpha(220) self.bg_picture = surface_object( self.display_screen.w / 1.2, 400, (self.display_screen.w - self.display_screen.w / 1.2) / 2, 100, DDGREY) self.bg_leader = surface_object( self.display_screen.w / 1.2, 400, (self.display_screen.w - self.display_screen.w / 1.2) / 2, 650 - (self.scroll_y - 163), DDGREY) self.bg_title = surface_object( self.display_screen.w / 1.2, 50, (self.display_screen.w - self.display_screen.w / 1.2) / 2, 10 - self.move_val, DDGREY) self.game_text = draw_text('QUICKTYPE', 40, True, WHITE) self.led_bg = surface_object( self.display_screen.w / 1.2, 50, (self.display_screen.w - self.display_screen.w / 1.2) / 2, 600 - self.move_val, DDGREY) self.led_text = draw_text('LEADERBOARDS', 35, True, WHITE) self.scroll_bar_frame = surface_object(self.w / 70, self.h / 1.3, self.x * 6.3, (self.h - self.h / 1.3) / 2, SGREY) self.play_button = button( self.display_screen, 'PLAY', text_color=WHITE, bold=True, font_size=60, startpos=((self.display_screen.w + self.display_screen.w / 15) / 2, 570 - (self.scroll_y - 163)), size=(self.display_screen.w / 3, 80), color=GREEN) self.image = pygame.image.load('materials/quicktype.png') self.image = pygame.transform.scale( self.image, (int(self.bg_picture.w), int(self.bg_picture.h + 190))) self.quicktype_scores = leaderboard.Leaderboard( user, 'quicktype', 'friends', parent, self.bg_leader.w, self.bg_leader.h, self.bg_leader.x, self.bg_leader.y)
def test_check_leaderboard_loads(self): # Arrange rob = player.Player("Rob", 1200) zak = player.Player("Zak", 1200) board = leaderboard.Leaderboard() board.add_player(rob) board.add_player(zak) # Act print(zak) print(rob) # Assert #self.assertEqual(main.try_load_leaderboard(), None) self.assertNotEqual(rob.name, zak.name)
def test_check_leaderboard_is_in_order_start(self): # Arrange cieran = player.Player("Cieran", 900) rob = player.Player("Rob", 1600) zak = player.Player("Zak", 1200) # Act board = leaderboard.Leaderboard() board.add_player(cieran) board.add_player(zak) board.add_player(rob) # Assert self.assertEqual(board.rankings[0].name, "Rob") self.assertEqual(board.rankings[1].name, "Zak") self.assertEqual(board.rankings[2].name, "Cieran")
def test_leaderboard_update(self): rob = player.Player("Rob", 1200) zak = player.Player("Zak", 1200) board = leaderboard.Leaderboard() board.add_player(rob) board.add_player(zak) board.recordMatch(zak.name, 1, rob.name, 0) self.assertEqual(board.rankings[0].name, zak.name) self.assertEqual(board.rankings[1].name, rob.name) board.recordMatch(zak.name, 0, rob.name, 1) board.recordMatch(zak.name, 0, rob.name, 1) self.assertEqual(board.rankings[0].name, rob.name) self.assertEqual(board.rankings[1].name, zak.name)
def test_check_match_recording(self): # Arrange rob = player.Player("Rob", 1200) zak = player.Player("Zak", 1200) board = leaderboard.Leaderboard() board.add_player(rob) board.add_player(zak) performances = [(rob.name, 1), (zak.name, 0)] testResults = ranking.calc_multiplayer_updates( performances, board.get_league_rankings(rob.name, zak.name)) board.recordMatch(rob.name, 1, zak.name, 0) elo1 = board.get_player_by_name(rob.name).eloRanking elo2 = board.get_player_by_name(zak.name).eloRanking testElo1 = 1200 + testResults[rob.name][0] testElo2 = 1200 + testResults[zak.name][0] self.assertAlmostEqual(elo1, testElo1) self.assertAlmostEqual(elo2, testElo2)
# Required Functionality: # List leaderboard # Record matches # Add players import logging import os.path import sys import leaderboard import match import player import ranking leaderboard = leaderboard.Leaderboard() def print_menu(): print("########## MENU ###########") print("# 1. Display League Table #") print("# 2. Record Match Result #") print("# 3. Add New Player #") print("# 4. List Match History #") print("# 5. Exit #") print("###########################\n") selection = 0 while selection not in range(1, 5): try:
def setUp(self): self.leaderboard = leaderboard.Leaderboard('name')
def test_redis_connection(self): lb = leaderboard.Leaderboard('name', connection=Redis()) self.assertEquals(0, len(lb.options))
def test_init_sets_page_size_to_default_if_set_to_invalid_value(self): self.leaderboard = leaderboard.Leaderboard('name', page_size=0) self.assertEquals(self.leaderboard.DEFAULT_PAGE_SIZE, self.leaderboard.page_size)
bot_prefix = "!" client = commands.Bot(command_prefix=bot_prefix) client.remove_command("help") # global variables active_player_list = [] database_loc = r"./db/database.sql" database = db.database.Database(database_loc) database.create_player_table() database.create_inventory_table() database.create_skills_table() database.update_all_player_status() leaderboard = leaderboard.Leaderboard(database) index = [ "shooting-range", "hull", "sheffield", "corral", "mines", "plains", "river", "lincoln" ] times_df = pd.read_csv("times.csv", index_col=['place']) # bot startup messages @client.event async def on_ready(): print("Bot is online") print("Name: Cowboy Simulator") print("TD: {}".format(client.user.id))
def runPsychopy(self): # make the marker stream. Must do before the window setup to be able to start Lab Recorder self.__marker_outlet = self.__createMarkerStream() # Get experiement details and filename filename, thisExp, expInfo = self.__getDatafilenameAndSetupWindow() # save a log file for detail verbose info # logFile = logging.LogFile(filename+'.log', level=logging.EXP) logging.console.setLevel( logging.WARNING) # this outputs to the screen, not a file ### ESC flag ### self.__endExpNow = False # flag for 'escape' or other condition => quit the exp # Create some handy timers globalClock = core.Clock( ) # to track the time since experiment started self.__routineTimer = core.CountdownTimer( ) # to track time remaining of each (non-slip) routine self.__kb = keyboard.Keyboard() experiment_components = [] experiment_components.append( self.__getMemeStim(meme_filenames[self.__current_meme])) random_start_meme_list_2 = rd.randint(0, len(meme_filenames2) - 1) experiment_components.append( self.__getMemeStim2(meme_filenames2[random_start_meme_list_2])) experiment_components.append(self.__getPointsStim()) self.__startRoutine(experiment_components) # Flag the start of the Psychopy experiment self.__marker_outlet.push_sample([PSYCHO_PY_MARKERS["psychopyStart"]]) # Show name of experiment and begin calibration self.__showTimedText(introductionText, 1) self.__showTextWithSpaceExit(calibrationText) self.__marker_outlet.push_sample( [PSYCHO_PY_MARKERS["calibrationStart"]]) self.__marker_outlet.push_sample([PSYCHO_PY_MARKERS["blinkStart"]]) self.__showTextWithSpaceExit(blinkText, add_instr=False) self.__marker_outlet.push_sample([PSYCHO_PY_MARKERS["blinkStop"]]) self.__marker_outlet.push_sample([PSYCHO_PY_MARKERS["openEyeStart"]]) self.__showTextWithSpaceExit(openEyeText, add_instr=False) self.__marker_outlet.push_sample([PSYCHO_PY_MARKERS["openEyeStop"]]) self.__marker_outlet.push_sample([PSYCHO_PY_MARKERS["closeEyeStart"]]) self.__showTextWithSpaceExit(closeEyeText, add_instr=False) self.__marker_outlet.push_sample([PSYCHO_PY_MARKERS["closeEyeStop"]]) self.__marker_outlet.push_sample([PSYCHO_PY_MARKERS["relaxStart"]]) self.__showTextWithSpaceExit(relaxText, add_instr=False) self.__marker_outlet.push_sample([PSYCHO_PY_MARKERS["relaxStop"]]) self.__showTextWithSpaceExit( "Enjoy These Memes\n\npress space to advance through", add_instr=False) for i in range(3): self.__setDrawOn([self.__meme_stim2]) self.__showTextWithSpaceExit("", add_instr=False) self.__endRoutine([self.__meme_stim2]) random_start_meme_list_2 = (random_start_meme_list_2 + 1) % len(meme_filenames) self.__meme_stim2.setImage( meme_filenames2[random_start_meme_list_2]) if (CALIBRATE_EYE): self.__showTextWithSpaceExit(calibrationText) self.__showTextWithSpaceExit(lookHereText, location=(LEFT_X_COORD, 0), add_instr=False, height=0.02) self.__showTextWithSpaceExit(lookHereText, location=(RIGHT_X_COORD, 0), add_instr=False, height=0.02) self.__showTextWithSpaceExit(lookHereText, location=(0, 0), add_instr=False, height=0.02) self.__showTextWithSpaceExit(lookHereText, location=(0, TOP_Y_COORD), add_instr=False, height=0.02) self.__showTextWithSpaceExit(lookHereText, location=(0, BOTTOM_Y_COORD), add_instr=False, height=0.02) self.__showTextWithSpaceExit(lookHereText, location=(0, 0), add_instr=False, height=0.02) self.__showTextWithSpaceExit(lookHereText, location=(RIGHT_X_COORD, TOP_Y_COORD), add_instr=False, height=0.02) self.__showTextWithSpaceExit(lookHereText, location=(RIGHT_X_COORD, BOTTOM_Y_COORD), add_instr=False, height=0.02) self.__showTextWithSpaceExit(lookHereText, location=(0, 0), add_instr=False, height=0.02) self.__showTextWithSpaceExit(lookHereText, location=(LEFT_X_COORD, TOP_Y_COORD), add_instr=False, height=0.02) self.__showTextWithSpaceExit(lookHereText, location=(LEFT_X_COORD, BOTTOM_Y_COORD), add_instr=False, height=0.02) self.__showTextWithSpaceExit(lookHereText, location=(0, 0), add_instr=False, height=0.02) ## CAUTION: data analysis uses the -3rd "(0, 0)" to calibrate for center looking eyes. self.__marker_outlet.push_sample( [PSYCHO_PY_MARKERS["calibrationStop"]]) if (SHOW_INTRO): self.__marker_outlet.push_sample( [PSYCHO_PY_MARKERS["instructionStart"]]) self.__showTextWithSpaceExit(instructionsText1) self.__showTextWithSpaceExit(instructionsText2) self.__showTextWithSpaceExit(instructionsText3) self.__marker_outlet.push_sample( [PSYCHO_PY_MARKERS["instructionStop"]]) # Create a text supplier textSupply = ts.TextSupplier(articles_path) self.__setDrawOn([self.__points_stim]) while (len(textSupply.files_read) < NUM_TO_READ) and (not textSupply.getAnotherArticle()): num_read = len(textSupply.files_read) to_meme = TO_MEME_OR_NOT_TO_MEME[(num_read - 1) % len(TO_MEME_OR_NOT_TO_MEME)] self.__marker_outlet.push_sample([PSYCHO_PY_MARKERS["newArticle"]]) self.__marker_outlet.push_sample([textSupply.getArticlePath()]) # Get the article targets targets = textSupply.getTargets() targetsString = "Identify any words with these letters by pressing 'space'\nPress 'm' to display the letters later:" for target in targets: targetsString = targetsString + "\n\n" + target self.__marker_outlet.push_sample( [PSYCHO_PY_MARKERS["memorizationStart"]]) self.__showTextWithSpaceExit(targetsString) self.__marker_outlet.push_sample( [PSYCHO_PY_MARKERS["memorizationStop"]]) targetsString = "" for target in targets: if (targetsString == ""): targetsString = target else: targetsString = targetsString + ", " + target self.__letters_stim = self.__getLettersStim(targetsString) self.__startRoutine([self.__letters_stim]) # Reset the timers self.__routineTimer.reset() self.__kb.clock.reset() time_shown = 0 self.__meme_being_shown = False self.__meme_should_be_shown = False self.__marker_outlet.push_sample( [PSYCHO_PY_MARKERS["responseStart"]]) secs_to_show = NUM_SECONDS_SHOW_MEME while textSupply.hasNext(): word = textSupply.getNext() # If there are supposed to be memes for this article... if to_meme != 0: self.__meme_should_be_shown = True time_shown += 1 # If shown for long enough, change meme if time_shown > secs_to_show: self.__current_meme = (self.__current_meme + 1) % len(meme_filenames) self.__meme_stim.setImage( meme_filenames[self.__current_meme]) self.__marker_outlet.push_sample( [PSYCHO_PY_MARKERS["newMeme"]]) self.__marker_outlet.push_sample( [meme_filenames[self.__current_meme]]) time_shown = 0 else: self.__meme_should_be_shown = False num_secs = int( (RAND_SECS_STARTBOUND - self.__performance) * 10 ) / 10 #rd.uniform(RAND_SECS_LOWERBOUND, RAND_SECS_UPPERBOUND) num_secs = RAND_SECS_LOWERBOUND if num_secs < RAND_SECS_LOWERBOUND else num_secs self.__showWordWithSpaceExitPoints(targetWord=word, seconds=num_secs, textSupply=textSupply) # Meme was previously shown if self.__meme_should_be_shown: self.__marker_outlet.push_sample( [PSYCHO_PY_MARKERS["memeHidden"]]) self.__endRoutine([self.__meme_stim]) self.__meme_being_shown = False self.__meme_should_be_shown = False self.__marker_outlet.push_sample( [PSYCHO_PY_MARKERS["responseStop"]]) self.__endRoutine([self.__meme_stim]) self.__endRoutine(experiment_components) # Flag the end of the Psychopy experiment self.__marker_outlet.push_sample([PSYCHO_PY_MARKERS["psychopyStop"]]) # Show leaderboard leaderboard = lb.Leaderboard(3) leaderboard.update(self.__points, expInfo['participant']) highest_scores_text = leaderboard.getHighscoresText() self.__showTextWithSpaceExit( "You have finished this part of the experiment.\nPlease notify your experimenter.\n\nPoints: " + str(self.__points) + "\n\n" + highest_scores_text) logging.flush() # make sure everything is closed down thisExp.abort() # or data files will save again on exit self.__win.close()
tts = gTTS(text=whatToSay, lang='en') tts.save("x.mp3") os.system("mpg321 -q x.mp3") else: print(whatToSay) name = raw_input("Enter your name: ") max_number = int(raw_input("Enter a maximum number for the game: ")) response = raw_input("Select (V)isual or (A)udio: ") if response == "V": mode = "visual" else: mode = "audio" game = gameplay.GamePlay(name, max_number, mode) first_line = "Guess a number between 1 and %d" % max_number saySomething(first_line, mode) #keep looping unil we guess correctly while (not game.solved): this_guess = input('?') game.guess(this_guess) print("You solved the puzzle in %d guesses." % game.guessCount) board = lb.Leaderboard() board.addGame(game) board.printleaderboard()
def __get_leaderboard(self, lid): return leaderboard.Leaderboard(lid)