def Swapper(): x = input('enter number x : ') y = input('enter number y : ') print('Pre-Swap : {} & {}'.format(x, y)) print('Post-Swap : {} & {}'.format(Practice.Swapper(x, y), Practice.Swapper(y, x)))
def __init__(self, filename): self.p = Practice(filename, False, False, False) self.fig = plt.figure() self.ax = self.fig.add_subplot(131) self.ax2 = self.fig.add_subplot(132) self.ax3 = self.fig.add_subplot(133) self.words = [] self.ax2.plot([0], [0]) self.ax3.barh(['x'], [5]) self.ax.plot([0], [0])
def OddEven(): x = input('Enter a number : ') if Practice.OddEven(x) == True: print('even') else: print('odd')
def main(): os.system('cls') Practice.Greet() PrintMenu() Activity = int(input('Select Activity : ')) Selector(Activity) time.sleep(2) main()
class Analyze: def __init__(self, filename): self.p = Practice(filename, False, False, False) self.fig = plt.figure() self.ax = self.fig.add_subplot(131) self.ax2 = self.fig.add_subplot(132) self.ax3 = self.fig.add_subplot(133) self.words = [] self.ax2.plot([0], [0]) self.ax3.barh(['x'], [5]) self.ax.plot([0], [0]) def animate_sent(self, i): # global p # p = Practice("C:\\Users\\Murali Sai Chand\\PycharmProjects\\Twitterai\\tweets2.json") # p1 = get_obj() words = self.words x = self.p.sentiments(words) self.ax2.clear() for n, i in enumerate(x): xs1 = i.index ys1 = i.values self.ax2.plot(xs1, ys1, 'C' + str(n + 3), label=words[n]) self.ax2.set_ylabel('Sentiment rate(per minute)') self.ax2.set_title("Sentiment Analyser.") self.ax2.legend() for i in self.ax2.get_xticklabels(): i.set_rotation(90) self.fig.canvas.draw() def animate(self, i): # global p # p = Practice("C:\\Users\\Murali Sai Chand\\PycharmProjects\\Twitterai\\tweets2.json") # p1 = get_obj() self.p.reflat() dfs, names = self.p.finalize(self.words) self.ax.clear() for j, i in enumerate(dfs): x = i.index y = i.values self.ax.plot(x, y, label=names[j]) self.ax.set_ylabel('Mean Tweets(per minute)') self.ax.set_title("Trends") self.ax.legend() for i in self.ax.get_xticklabels(): i.set_rotation(90) self.fig.canvas.draw() def viz_top(self, i): # p = Practice("C:\\Users\\Murali Sai Chand\\PycharmProjects\\Twitterai\\tweets2.json") # p1 = get_obj() d = self.p.top_words() # set_obj() n = 0 for i in d: n += i[1] x = [i[0] for i in d] y = [(i[1] / n) * 100 for i in d] self.ax3.clear() self.ax3.barh(x, y, color=[str(i / 100) for i in y]) for i, v in enumerate(y): self.ax3.text(v, i, str(round(v, 1)) + "%") self.ax3.set_xlabel("Word Percentage") self.ax3.set_title("Top Words. Total tweets{}".format(self.p.n)) plt.xticks(rotation=75) self.fig.canvas.draw() def show_viz(self, words=[]): self.words = words ani2 = animation.FuncAnimation(self.fig, self.animate, interval=3000) ani = animation.FuncAnimation(self.fig, self.animate_sent, interval=3000) ani3 = animation.FuncAnimation(self.fig, self.viz_top, interval=3000) plt.show()
def main(): pygame.init() pygame.display.set_caption("DanbiHackathon") screen = pygame.display.set_mode(screen_res) img_res_path = 'resources/images/{}' audio_res_path = 'resources/audio/{}' menu_background_path = img_res_path.format('menu_bg.png') menu_challenge_bt_path = img_res_path.format('menu_challenge_bt.png') menu_practice_bt_path = img_res_path.format('menu_practice_bt.png') menu_exit_bt_path = img_res_path.format('menu_exit_bt.png') practice_01_path = img_res_path.format('practice_01.png') back_bt_path = img_res_path.format('back_bt.png') Story_PT_card_01_path = img_res_path.format('Story_PT_card_01.png') Story_PT_card_02_path = img_res_path.format('Story_PT_card_02.png') Story_PT_card_03_path = img_res_path.format('Story_PT_card_03.png') Story_PT_card_04_path = img_res_path.format('Story_PT_card_04.png') Story_PT_card_05_path = img_res_path.format('Story_PT_card_05.png') Story_PT_card_06_path = img_res_path.format('Story_PT_card_06.png') Story_PT_card_07_path = img_res_path.format('Story_PT_card_07.png') Story_PT_card_08_path = img_res_path.format('Story_PT_card_08.png') Story_PT_card_09_path = img_res_path.format('Story_PT_card_09.png') popup_bg_path = img_res_path.format('popup_bg.png') practice_pu_mic_path = img_res_path.format('practice_pu_mic.png') practice_pu_mic_effect_path = img_res_path.format('practice_pu_mic_effect.png') practice_pu_mic = pygame.image.load(practice_pu_mic_path) practice_pu_mic_effect = pygame.image.load(practice_pu_mic_effect_path) back_bt = pygame.image.load(back_bt_path) Story_PT_card_01 = pygame.image.load(Story_PT_card_01_path) Story_PT_card_02 = pygame.image.load(Story_PT_card_02_path) Story_PT_card_03 = pygame.image.load(Story_PT_card_03_path) Story_PT_card_04 = pygame.image.load(Story_PT_card_04_path) Story_PT_card_05 = pygame.image.load(Story_PT_card_05_path) Story_PT_card_06 = pygame.image.load(Story_PT_card_06_path) Story_PT_card_07 = pygame.image.load(Story_PT_card_07_path) Story_PT_card_08 = pygame.image.load(Story_PT_card_08_path) Story_PT_card_09 = pygame.image.load(Story_PT_card_09_path) menu_challenge_bt = pygame.image.load(menu_challenge_bt_path) menu_practice_bt = pygame.image.load(menu_practice_bt_path) menu_exit_bt = pygame.image.load(menu_exit_bt_path) challenge_background_path = img_res_path.format('challenge_bg.png') menu_items = { 'challenge_bt': menu_challenge_bt, 'practice_bt': menu_practice_bt, 'exit_bt': menu_exit_bt } font = pygame.font.Font(None, 50) main_menu = Menu('DanbiHackathon V0.1', menu_background_path, screen_res, None, None) for item_name, item in menu_items.items(): main_menu.add_item(item_name, item) practice_items = { "back_bt": back_bt, "Story_PT_card_01": Story_PT_card_01, "Story_PT_card_02": Story_PT_card_02, "Story_PT_card_03": Story_PT_card_03, "Story_PT_card_04": Story_PT_card_04, "Story_PT_card_05": Story_PT_card_05, "Story_PT_card_06": Story_PT_card_06, "Story_PT_card_07": Story_PT_card_07, "Story_PT_card_08": Story_PT_card_08, "Story_PT_card_09": Story_PT_card_09 } practice_game = Practice('DanbiHackathon V0.1', practice_01_path, screen_res, None, None) for item_name, item in practice_items.items(): practice_game.add_item(item_name, item) popup_items = { "practice_pu_mic": practice_pu_mic, "exit_bt": menu_exit_bt } challenge_game = Challenge('DanbiHackathon V0.1', challenge_background_path, screen_res, None, None) Story_ch_card_01_image_path = img_res_path.format('Story_ch_card_01_image.png') Story_ch_card_01_text_path = img_res_path.format('Story_ch_card_01_text.png') Story_ch_card_01_image = pygame.image.load(Story_ch_card_01_image_path) Story_ch_card_01_text = pygame.image.load(Story_ch_card_01_text_path) challenge_bg_nice_path = img_res_path.format('challenge_bg_nice.png') challenge_bg_nice = pygame.image.load(challenge_bg_nice_path) challenge_items = { "practice_pu_mic": practice_pu_mic, "exit_bt": menu_exit_bt, "Story_ch_card_01_image": Story_ch_card_01_image, "Story_ch_card_01_text": Story_ch_card_01_text } for item_name, item in challenge_items.items(): challenge_game.add_item(item_name, item) while True: display_menu = True practice = False challenge = False while display_menu: main_menu.show(screen) pygame.display.flip() event = pygame.event.wait() user_input = main_menu.check_input(event) if user_input == 'challenge_bt': display_menu = False challenge = True challenge_game.show(screen) pygame.display.flip() elif user_input == 'practice_bt': display_menu = False practice = True practice_game.show(screen) pygame.display.flip() elif user_input == 'exit_bt' or event.type == pygame.QUIT: # quit exit() while practice: event = pygame.event.wait() user_input = practice_game.check_input(event) if user_input == 'back_bt': display_menu = True practice = False elif event.type == pygame.QUIT: exit() elif user_input and user_input.startswith('Story'): popup = True game_popup = Popup('DanbiHackathon V0.1', popup_bg_path, screen_res, None, None) text_name = '{}_text'.format(user_input) image_name = '{}_image'.format(user_input) text_path = img_res_path.format('{}.png'.format(text_name)) image_path = img_res_path.format('{}.png'.format(image_name)) text = pygame.image.load(text_path) image = pygame.image.load(image_path) in_pop_up_items = popup_items in_pop_up_items.update({text_name: text, image_name: image}) for item_name, item in in_pop_up_items.items(): game_popup.add_item(item_name, item) game_popup.show(screen) pygame.display.flip() while popup: event = pygame.event.wait() popup_user_input = game_popup.check_input(event) if popup_user_input == 'exit_bt': popup = False practice_game.show(screen) pygame.display.flip() elif event.type == pygame.QUIT: exit() elif popup_user_input == 'Story_PT_card_01_text': pygame.mixer.music.load('resources/audio/Story_PT_card_01_audio.wav') pygame.mixer.music.set_volume(0.5) pygame.mixer.music.play() elif popup_user_input == 'practice_pu_mic': game_popup.add_item("practice_pu_mic_effect", practice_pu_mic_effect) game_popup.show(screen) pygame.display.flip() r = sr.Recognizer() mic = sr.Microphone(device_index=sr.Microphone.list_microphone_names().index('default')) with mic as source: audio = r.record(source, duration=3) try: result = r.recognize_google(audio) except: result = None game_popup.remove_item("practice_pu_mic_effect") game_popup.show(screen) pygame.display.flip() if result: full = "alligator" part_sc = 100 / len(full) result_sc = 0 for i in range(len(full)): try: if result[i] == full[i]: result_sc += part_sc except: pass if result_sc > 0: text = "Your Score : {}".format(str(int(result_sc))) text_0 = result text_result_0 = font.render(text_0, True, (0, 40, 0)) textRect = text_result_0.get_rect() textRect.centerx = 1020 textRect.centery = 250 screen.blit(text_result_0, textRect) else: text = "RETRY!!!" else: text = "RETRY!!!" text_result = font.render(text, True, (0, 40, 0)) textRect = text_result.get_rect() textRect.centerx = 1020 textRect.centery = 300 screen.blit(text_result, textRect) pygame.display.flip() while challenge: event = pygame.event.wait() user_input = challenge_game.check_input(event) if user_input == 'exit_bt': display_menu = True challenge = False elif event.type == pygame.QUIT: exit() elif user_input == 'Story_ch_card_01_text': pygame.mixer.music.load('resources/audio/Story_PT_card_01_audio.wav') pygame.mixer.music.set_volume(0.5) pygame.mixer.music.play() elif user_input == 'practice_pu_mic': challenge_game.add_item("practice_pu_mic_effect", practice_pu_mic_effect) challenge_game.show(screen) pygame.display.flip() r = sr.Recognizer() mic = sr.Microphone(device_index=sr.Microphone.list_microphone_names().index('default')) with mic as source: audio = r.record(source, duration=3) try: result = r.recognize_google(audio) except: result = None challenge_game.remove_item("practice_pu_mic_effect") challenge_game.show(screen) pygame.display.flip() if result: full = "alligator" part_sc = 100 / len(full) result_sc = 0 for i in range(len(full)): try: if result[i] == full[i]: result_sc += part_sc except: pass if result_sc > 0: if result_sc >= 60: text = None for key in challenge_items.keys(): challenge_game.remove_item(key) challenge_game.add_item("challenge_bg_nice", challenge_bg_nice) challenge_game.show(screen) pygame.display.flip() sleep(1) challenge_game.remove_item("challenge_bg_nice") for item_name, item in challenge_items.items(): challenge_game.add_item(item_name, item) challenge_game.show(screen) else: text = "Your Score : {}".format(str(int(result_sc))) text_0 = result text_result_0 = font.render(text_0, True, (0, 40, 0)) textRect = text_result_0.get_rect() textRect.centerx = 800 textRect.centery = 250 screen.blit(text_result_0, textRect) else: text = "RETRY!!!" else: text = "RETRY!!!" if text: text_result = font.render(text, True, (0, 40, 0)) textRect = text_result.get_rect() textRect.centerx = 800 textRect.centery = 300 screen.blit(text_result, textRect) pygame.display.flip()
def NumberReverse(): x = input("enter a number : ") print('Reversed number : {}'.format(Practice.Reverser(x)))
def SumOfDigits(): x = input("enter a number : ") print('sum : {}'.format(Practice.SumOfDigits(x)))
practice_codes = PracticeCodeLoader(ENV['NOMENCLATOR']).practices practiceLoader = ExcelLoader(ENV['BASE']) ws = practiceLoader.sheet('nuevo arbol') rows = list(ws.iter_rows())[1:] c = 0 practices = [] for row in rows: super_type = row[0].value if row[0].value else super_type type = row[1].value if row[1].value else type name = row[2].value #price = round(row[3].value, 2) if row[3].data_type == 'n' else None practice_code = find_practice(name, practice_codes) if practice_code is None: print("No encontre " + name) c = c + 1 else: practice = Practice(practice_code.code, name, type, super_type, practice_code.price) practices.append(practice) print('No encontrados %d' % c) for practice in practices: print(practice.to_json()) practice_collenction.insert_many(map(map_practice_to_mongo, practices))