def go_to_room_web_cb(self, result): if result.error: if result.error == web.Error.SERVER and result.code == 404: self.the_room_doesnt_exist() else: self.error_try_again_later() return data = DictClass(result.data) self.title = data.title self.layers.room.title.set_text(self.title) self.layers.room.description.set_text(data.description) self.layers.room.code.set_text(self.layers.room.code.data.text % self.layers.main.room_input.get_text()) self.layers.logged.login_name.set_text( self.layers.main.name_input.get_text()) data = [DictClass(item) for item in data.posts] self.posts = data items = [] self.load_items(data, items) self.paginator = Paginator(self.stage, items, self.data.pager) if self.go_to_last: self.go_to_last = False self.paginator.go_to_last() self.change_layer([self.layers.room.layer] + self.paginator.get_layers() + [self.layers.logged.layer])
def __init__(self, stage, tests): self.layer = Layer() self.stage = stage self.tests = tests data = DictClass(load(file('data/common/tests_viewer.yaml'))) layers = [test.get_layer() for test in tests] self.paginator = Paginator(self.stage, layers, data.get("pagination", None)) for item in self.stage.create_items_from_yaml(data.other, self): self.layer.add(item)
def set_up_data(self): """ Set types """ self.contents = DictClass(load(file('data/common/contents.yaml'))) self.tests = DictClass(load(file('data/common/tests.yaml'))) self.levels = DictClass(load(file('data/common/level_contents.yaml'))) self.datamodel = datamodel.Datamodel() self.load()
def __init__(self, stage, title, description, fromm, to, correct_pairs, visualization=None): data = DictClass(load(file('data/common/joining.yaml'))) if visualization: data.deep_update(visualization) Question.__init__(self, stage, title, description, data) self.fromm = fromm self.to = to self.correct_pairs = set(correct_pairs) self.__load_items(data)
def arg_parse(): parser = argparse.ArgumentParser(description='Preprocessing text files.') parser.add_argument('--data_folder', default='20180805/', help='directory of data folder') parser.add_argument('--data_out_file', default='data.msgpack') parser.add_argument('--meta_out_file', default='meta.msgpack') parser.add_argument('--is_test', type=int, default=0) parser.add_argument('--log_file', default='log/pre_process.log') # mode parser.add_argument('--mode', default='concat_and_pad') # specification parser.add_argument('--sent_len', type=int, default=20) parser.add_argument('--list_len', type=int, default=10) parser.add_argument('--embedding_file', type=str, default='embedding_file/sgns.sogounews.bigram-char') parser.add_argument('--words_file', type=str, default='embedding_files/words.txt') parser.add_argument('--num_workers', type=int, default=4) args = parser.parse_args() return DictClass(vars(args))
def create_elements(self, data, elements): self.elements = [] start_top = data["elements_pos"]["top"] inter = data["elements_pos"]["interspace"] element_data = DictClass(load(file('data/common/books.yaml'))) current = 0 for page in xrange(0, len(elements) / self.ITEMS_PER_PAGE + 1): start_left = 0 for element in elements[page * self.ITEMS_PER_PAGE:(page + 1) * self.ITEMS_PER_PAGE]: element_data[element.type]['action'] = 'click' new = self.stage.create_button(element_data[element.type], manager=self)[0] new.set_top(start_top) new.set_left(start_left) new.add_event_handler(ItemEvent.MOUSE_ENTER, self.handle_element_enter) new.add_event_handler(ItemEvent.MOUSE_LEAVE, self.handle_element_leave) new.info = element start_left += new.get_width() + inter self.elements.append(new) current += 1 start_left -= inter new_left = (data["elements_pos"]["width"] - start_left) / 2 + data["elements_pos"]["left"] for element in self.elements[page * self.ITEMS_PER_PAGE:(page + 1) * self.ITEMS_PER_PAGE]: element.set_left(element.get_left() + new_left)
def create_initial_dialog(self, data): data = DictClass(data) self.dialog_items = [] self.dialog_animations = {} self.dialog_animation_items = [] for (name, animation_data) in data["animations"].items(): if "both" in animation_data: animation_data = animation_data["both"] else: animation_data = animation_data[ self.game.datastore.datamodel.character] self.dialog_animations[name] = animation = Animation( load_animation("", animation_data["animation"])) animation_item = ItemImage(animation_data["left"], animation_data["top"], animation.get_image()) self.dialog_animation_items.append(animation_item) animation.item = animation_item for dialog_data in data["items"]: dialog = self.create_image(dialog_data["dialog"])[0] dialog.animation_name = dialog_data["animation"] self.dialog_items.append(dialog) self.dialog_animation_items.append(animation_item) self.dialog_mask = ItemMask(0, 0, (600, 450)) self.dialog_mask.add_event_handler(ItemEvent.CLICK, lambda *args, **kwargs: None) self.dialog_mask.add_event_handler(ItemEvent.MOUSE_ENTER, lambda *args, **kwargs: None) self.current_dialog_frame = 0 return self.dialog_items[:1] + [self.dialog_mask ] + self.dialog_animation_items
def arg_parse(): parser = argparse.ArgumentParser( description='Convlutional nerual net for sentence classification.') parser.add_argument('--data_file', default='20180805/data.msgpack') parser.add_argument('--meta_file', default='20180805/meta.msgpack') parser.add_argument('--log_file', default='log/training_test.log') parser.add_argument('--best_in_valid_model_name', default='best_in_valid.param') parser.add_argument('--resume', action='store_true') parser.add_argument('--saved_model_name', default=None) # training parser.add_argument('--max_epoch', type=int, default=10) parser.add_argument('--log_per_batch', type=int, default=5) parser.add_argument('--batch_size', type=int, default=50) parser.add_argument('--learning_rate', type=float, default=5e-4) parser.add_argument('--no_update_embedding', action='store_true') # model parser.add_argument('--dropout_rate', type=float, default=0.5) parser.add_argument('--kernel_size', nargs='+', type=int, default=[3]) parser.add_argument('--title_len', type=int, default=20) parser.add_argument('--num_neighbor', type=int, default=10) parser.add_argument('--feature_map', type=int, default=64) parser.add_argument('--hidden_dim', type=int, default=128) parser.add_argument('--activation', default='relu') parser.add_argument('--num_classes', type=int, default=2) args = parser.parse_args() return DictClass(vars(args))
def view_post_web_cb(self, result): if result.error: self.error_try_again_later() return data = DictClass(result.data) self.layers.view_post.title.set_text(self.title) self.layers.view_post.author.set_text(data.author_name + ":") # Usamos una clase que tiene el metodo set_text para saber si hay que dividir el texto items = [] next = Next() layer = Layer() def create_text(stage, next, text, data): text_item = stage.create_text(data)[0] set_text(next, text, text_item) return text_item layer.add( create_text(self.stage, next, data.text, self.layers.view_post.post.data)) items.append(layer) while next.text: layer = Layer() layer.add( create_text(self.stage, next, next.text, self.layers.view_post.post.data)) items.append(layer) paginator = Paginator(self.stage, items, self.data.pager_post) self.change_layer([self.layers.view_post.layer] + paginator.get_layers() + [self.layers.logged.layer])
def __init__(self, stage, title, text): self.layer = Layer() self.stage = stage data = DictClass(load(file('data/common/content_viewer.yaml'))) title_item = self.title_text = stage.create_text(data.title)[0] title_item.set_top(data.container.top) self.title_text.set_text(title) text_top = title_item.get_top() + title_item.get_height() + 10 text_height = data.container.height - (text_top - data.container.top) self.close = stage.create_button(data.close, self)[0] self.__load_items(text, data, text_top, text_height) self.paginator = Paginator(self.stage, self.items, data.get("pagination", None)) for item in self.stage.create_items_from_yaml(data.other): self.layer.add(item) self.layer.add(self.title_text) self.layer.add(self.close)
def __init__(self, stage, title, description, options, right_answers): data = DictClass(load(file('data/common/multiple_choice.yaml'))) Question.__init__(self, stage, title, description, data) self.options = options self.right_answers = set(right_answers) if len(self.right_answers) > 1: self.option_group = None else: self.option_group = OptionGroup() self.__load_items(data)
def create_items(self, data): items = DictClass() layer = Layer() self.stage._items_manager = self for i in data: item = items[i.name] = self.stage.create_item(i)[0] item.data = i layer.add(item) self.stage._items_manager = None items["layer"] = layer return items
def __init__(self, stage, on_ok=None): self.stage = stage layer = self.layer = Layer() data = self.get_data() items = stage.create_items_from_yaml(data['items'], self) self.on_ok = on_ok self.items = DictClass() for item in items: layer.add(item) self.message = stage.create_item(data["message"])[0] layer.add(self.message)
def __init__(self, stage): self.layer = Layer() self.stage = stage data = DictClass(load(file('data/common/games_viewer.yaml'))) for item in stage.create_items_from_yaml(data.other): self.layer.add(item) self.close = stage.create_button(data.close, self)[0] self.layer.add(self.close) quantity = stage.game.datastore.datamodel.unlocked_level - 1 if quantity == 1: data.header['text'] = data.header.singular.pre + str( quantity) + data.header.singular.pos else: data.header['text'] = data.header.plural.pre + str( quantity) + data.header.plural.pos self.header = stage.create_text(data.header)[0] self.layer.add(self.header) self.footer = stage.create_text(data.footer)[0] for data_game in data.games: Game(stage, self.layer, data_game, self.footer)
def __init__(self, stage): global DEFAULT_NAME, DEFAULT_ROOM self.go_to_last = False self.dialog = None self.paginator = None self.background = Layer() self.foreground = Layer() self.focus_group = FocusGroup() self.stage = stage self.current_callback = None self.current_id = None data = self.data = DictClass(load(file('data/common/activity.yaml'))) self.clock_image = ItemImage(0, 0, assets.load_image(data.clock.src)) layers = self.layers = DictClass() for k, i in data.layers.items(): layers[k] = self.create_items(i) self.layers.main.name_input.set_focus_group(self.focus_group) self.layers.main.name_input.set_on_enter(self.handle_next) self.layers.main.name_input.set_text(DEFAULT_NAME) self.layers.main.room_input.set_focus_group(self.focus_group) self.layers.main.room_input.set_on_enter(self.handle_next) self.layers.main.room_input.set_text(DEFAULT_ROOM) self.current_layers = [layers.main.layer] text_box = self.layers.post.text_box = self.create_text_box( data.text_box) self.layers.post.layer.add(text_box) for item in self.stage.create_items_from_yaml(data["background"], self): self.background.add(item) for item in self.stage.create_items_from_yaml(data["foreground"], self): self.foreground.add(item) self.stage.start_timer('msgclock', 15000, self.update_messages_tick)
def __init__(self, stage): self.stage = stage layer = self.layer = Layer() data = DictClass(load(file('data/common/next_level.yaml'))) items = stage.create_items_from_yaml(data.other, self) for item in items: layer.add(item) text = stage.create_text(data.text)[0] text.set_text( data.text.texts[self.stage.game.datastore.datamodel.level]) layer.add(text) # Load the sound item_found_sound = assets.load_sound('DGI_item_found.ogg') item_found_sound.play()
def create_contents(self, data): data = DictClass(data) items = [] icons = [] contents = self.game.datastore.contents left = data.left width = data.width top = data.top inter = data.inter bb_left = data.blackboard.left bb_top = data.blackboard.top bb_inter = data.blackboard.interline bb_width = data.blackboard.width for content in data.contents: item = self.create_text_selectable(content.item)[0] item.set_left(bb_left) item.set_top(bb_top) item.set_dimensions(bb_width, -1) item.set_text(self.game.datastore.contents[content.name].title) bb_top += bb_inter + item.get_height() item.content = content.name other_dict = dict(self.item_data[contents[item.content].type]) other_dict["action"] = "item_click" hidden = self.create_image(dict(src=other_dict["hidden_src"]))[0] hidden.set_top(top) icon = self.create_button(other_dict)[0] icon.set_top(top) icon.content = item.content items.append(item) item.icon_item = icon icons.append((icon, hidden)) start = left + width icons_list = [] for icon, hidden in icons: width = icon.get_width() hidden.set_left(start - width) icon.set_visible(icon.content in self.game.datastore.datamodel. backpack[self.game.datastore.datamodel.level - 1]) icon.set_left(start - width) start -= width + inter icons_list += [hidden, icon] return items + icons_list
def __init__(self, stage, amount): self.stage = stage layer = self.layer = Layer() self.amount = amount data = DictClass(load(file('data/common/fail_tests.yaml'))) text = stage.create_text(data.text)[0] if amount == 1: text.set_text(data.text.singular) else: text.set_text(data.text.plural % dict(amount=amount)) items = stage.create_items_from_yaml(data.other, self) for item in items: layer.add(item) layer.add(text) # Load the sound wrong_sound = assets.load_sound('DGI_wrong.ogg') wrong_sound.play()
def refresh_cb(self, result): if result.error: return data = [DictClass(item) for item in result.data["posts"]] # Check if the data change, only update the screen if changed if data != self.posts: self.posts = data items = [] self.load_items(self.posts, items) current = self.paginator.get_current() self.paginator = Paginator(self.stage, items, self.data.pager) self.paginator.go_to(current) self.change_layer([self.layers.room.layer] + self.paginator.get_layers() + [self.layers.logged.layer])
def __init__(self, left=0, top=0, base=None, standing=None, walking=None, jumping=None): self.first_jumping = True self.first_walking = True # Load the sound self.footsteps_concrete_sound = assets.load_sound( 'DGI_footsteps_concrete.ogg') self.jump_sound = assets.load_sound('DGI_jump.ogg') self.standing_still = assets.load_image(base + standing.src) if "wait" in standing: self.standing_wait = Animation( self.load_animation(base, [ DictClass({ 'src': standing.src, 'duration': standing.duration }) ] + standing.wait)) if jumping: self.jumping = assets.load_image(base + jumping.src) if walking: if "sideways" in walking: sideways = self.load_animation(base, walking.sideways) self.walking_sideways_left = Animation(sideways) self.walking_sideways_right = Animation([ self.Frame(frame.image.flip_h_copy(), frame.to) for frame in sideways ]) if "front" in walking: self.walking_front = Animation( self.load_animation(base, walking.front)) if "back" in walking: self.walking_back = Animation( self.load_animation(base, walking.back)) self.item = ItemImage(left, top, self.standing_still)
def create_contents(self, data): data = DictClass(data) items = [] icons = [] contents = self.game.datastore.contents left = data.left width = data.width top = data.top inter = data.inter for content in data.contents: item = self.create_button(content.item)[0] if content.name in self.game.datastore.datamodel.backpack[self.game.datastore.datamodel.level - 1]: item.remove_event_handler(ItemEvent.CLICK, self.handle_select_item) item.set_rollover_image(None) item.content = content.name other_dict = dict(self.item_data[contents[item.content].type]) other_dict.update({"action":"item_click"}) hidden = self.create_image(dict(src = other_dict["hidden_src"]))[0] hidden.set_top(top) icon = self.create_button(other_dict)[0] icon.set_top(top) icon.content = item.content items.append(item) item.icon_item = icon icons.append((icon, hidden)) start = left + width icons_list = [] for icon, hidden in icons: width = icon.get_width() hidden.set_left(start - width) icon.set_visible(icon.content in self.game.datastore.datamodel.backpack[self.game.datastore.datamodel.level - 1]) icon.set_left(start - width) start -= width + inter icons_list += [hidden, icon] return items + icons_list
def prepare(self): data = DictClass(load(file('data/map/common.yaml'))) self.gui = Layer() for item in self.create_items_from_yaml(data.gui): self.gui.add(item) self.create_selected_map_character(data.character) self.load_quadrant() self.tests_counter = self.create_text(data.counters.tests)[0] self.backpack_counter = self.create_text(data.counters.backpack)[0] self.games_counter = self.create_text(data.counters.games)[0] self.gui.add(self.tests_counter) self.gui.add(self.backpack_counter) self.gui.add(self.games_counter) self.backpack_counter.set_text( str( len(self.game.datastore.datamodel.backpack[ self.game.datastore.datamodel.level - 1]))) self.tests_counter.set_text( str( len(self.game.datastore.levels[ self.game.datastore.datamodel.level].tests))) self.games_counter.set_text( str(self.game.datastore.datamodel.unlocked_level - 1))
def get_data(self): return DictClass(load(file("data/activity/error_dialog.yaml")))
def initialize(self): GameStage.initialize(self) stream = file('data/fonts.yaml', 'r') fonts = load(stream) for font in fonts: setattr( self, font, assets.load_font(fonts[font]['file_name'], fonts[font]['size'])) self.data = DictClass(load(file('data/invaders.yaml'))) self.good = self.data.start.good self.velocity = self.data.start.velocity self.interval = self.data.start.interval self.game_over_layer = Layer() image = assets.load_image( self.data.bad[self.game.datastore.datamodel.character].src) item = ItemImage(self.data.bad.left, self.data.bad.top, image) self.game_over_layer.add(item) image = assets.load_image( self.data.game_over[self.game.datastore.datamodel.character].src) item = ItemImage(self.data.game_over.left, self.data.game_over.top, image) self.game_over_layer.add(item) image = assets.load_image( self.data.good[self.game.datastore.datamodel.character].src) self.good_indicator = ItemImage(self.data.good.left, self.data.good.top, image) self.text_indicators = [] self.main_layer = Layer() self.top_layer = Layer() self.score = 0 self.score_board = DictClass({}) image = assets.load_image(self.data.score.src) self.score_board['skin'] = ItemImage(self.data.score.left, self.data.score.top, image) self.score_board['value'] = ItemText(self.data.score.left, self.data.score.top, self.font, 0, str(self.score), width=image.get_width(), height=image.get_height(), h_align=2, v_align=2) self.top_layer.add(self.score_board.skin) self.top_layer.add(self.score_board.value) data = DictClass(load(file('data/map/common.yaml'))) params = data.character[self.game.datastore.datamodel.character] params['base'] = data.character.base[ self.game.datastore.datamodel.character].big self.character_animation = Character(**params) self.character = self.character_animation.item self.character.set_left( (SCREEN_WIDTH - self.character.get_width()) / 2) self.character.set_top(SCREEN_HEIGHT - self.character.get_height()) left = self.character.get_left() + self.data.collision.left top = self.character.get_top() + self.data.collision.top width = self.character.get_width( ) - self.data.collision.left - self.data.collision.right height = self.character.get_height( ) - self.data.collision.top - self.data.collision.bottom if DEBUG: self.debug_character = ItemRect(left, top, width, height, border=(255, 255, 255)) self.invaders = [] # Load the sound self.item_found_sound = assets.load_sound('DGI_item_found.ogg') self.lose_hit_sound = assets.load_sound('DGI_lose_hit.ogg') self.lose_music_sound = assets.load_sound('DGI_lose_music.ogg')
def load_quadrant(self): # remove the character before it gets destroyed if self.named_layers and hasattr(self.named_layers, "character"): self.named_layers.character.remove(self.map_character.item) if self.layers: self.remove_layer(self.gui) for layer in self.layers: layer.exit() self.empty_layers() data = DictClass( load(file('data/map/quadrant_%d.yaml' % self.current_map_index))) self.named_layers, layers = self.create_layers(data["layers"]) self.named_layers.character.add(self.map_character.item) if self.game.datastore.datamodel.map_character_left: self.map_character.item.set_left( self.game.datastore.datamodel.map_character_left) self.game.datastore.datamodel.map_character_left = None if self.game.datastore.datamodel.map_character_top: self.map_character.item.set_top( self.game.datastore.datamodel.map_character_top) self.game.datastore.datamodel.map_character_top = None class Collision(): def __init__(self, collision_map, trans_x=0, trans_y=0): self.collision_map = collision_map self.trans_x = trans_x self.trans_y = trans_y def get_at(self, pos): return self.collision_map.get_at( (pos[0] + self.trans_x, pos[1] + self.trans_y)) def bottom(self): return self.collision_map.get_height() - self.trans_y def left(self): return -self.trans_x def right(self): return self.collision_map.get_width() - self.trans_x def top(self): return -self.trans_y def exit(self): self.collision_map = None if "collision" in data: if self.collisions: for col in self.collisions: col.exit() self.collisions = [] base_data = data.collision.base self.collisions.append( Collision(assets.load_mask(base_data.src), base_data.get("trans_x", 0), base_data.get("trans_y", 0))) if self.game.datastore.datamodel.unlocked_level >= 3: self.collisions.append( Collision(assets.load_mask(data.collision.trash.src))) if self.game.datastore.datamodel.unlocked_level >= 4: self.collisions.append( Collision(assets.load_mask(data.collision.lights.src))) if self.game.datastore.datamodel.unlocked_level >= 5 and "vegetation" in data.collision: self.collisions.append( Collision(assets.load_mask(data.collision.vegetation.src))) else: self.collisions = [] if "entrance" in data: self.entrance = assets.load_mask(data.entrance.src) to = data.entrance.to index = to.rfind(".") if (index > 1): self.entrance_class = getattr( __import__(to[:index], globals(), locals(), to[index + 1:]), to[index + 1:]) else: self.entrance_class = globals()[to] else: self.entrance = None if self.map_manager: self.map_manager.exit() self.map_manager = MapManager(self, self.map_character.item, self.named_layers.character) for layer in layers: self.add_layer(layer) self.add_layer(self.gui) # Start processing events after everything is loaded self.start_timer(0, self.INTERVAL, self.manage_key)
def initialize(self): GameStage.initialize(self) stream = file('data/fonts.yaml', 'r') fonts = load(stream) for font in fonts: setattr( self, font, assets.load_font(fonts[font]['file_name'], fonts[font]['size'])) self.data = DictClass(load(file('data/asteroids.yaml'))) self.game_over_layer = Layer() image = assets.load_image( self.data.game_over[self.game.datastore.datamodel.character].src) item = ItemImage(self.data.game_over.left, self.data.game_over.top, image) self.game_over_layer.add(item) self.main_layer = Layer() self.top_layer = Layer() self.time = self.data.time.max self.timer = DictClass({}) image = assets.load_image(self.data.time.src) self.timer['skin'] = ItemImage(self.data.time.left, self.data.time.top, image) self.timer['value'] = ItemText(self.data.time.left, self.data.time.top, self.font, 0, format_time(self.time), width=image.get_width(), height=image.get_height(), h_align=2, v_align=2) self.top_layer.add(self.timer.skin) self.top_layer.add(self.timer.value) self.score = 0 self.score_board = DictClass({}) image = assets.load_image(self.data.score.src) self.score_board['skin'] = ItemImage(self.data.score.left, self.data.score.top, image) self.score_board['value'] = ItemText(self.data.score.left, self.data.score.top, self.font, 0, str(self.score), width=image.get_width(), height=image.get_height(), h_align=2, v_align=2) self.top_layer.add(self.score_board.skin) self.top_layer.add(self.score_board.value) self.level = self.data.start self.asteroids = [] self.max_width = 0 self.max_height = 0 for a in self.data.asteroids: item = assets.load_image(a) if self.max_width < item.get_width(): self.max_width = item.get_width() if self.max_height < item.get_height(): self.max_height = item.get_height() self.max_col = int(SCREEN_WIDTH / self.max_width) self.max_row = int(SCREEN_HEIGHT / self.max_height) self.margin_left = (SCREEN_WIDTH % self.max_width) / 2 self.margin_top = (SCREEN_HEIGHT % self.max_height) / 2 # Load the sound self.click_sound = assets.load_sound('DGI_Click.ogg') self.item_found_sound = assets.load_sound('DGI_item_found.ogg') self.wrong_sound = assets.load_sound('DGI_wrong.ogg') self.lose_bell_sound = assets.load_sound('DGI_lose_bell.ogg') self.lose_music_sound = assets.load_sound('DGI_lose_music.ogg')
def initialize(self): GameStage.initialize(self) stream = file('data/fonts.yaml', 'r') fonts = load(stream) for font in fonts: setattr( self, font, assets.load_font(fonts[font]['file_name'], fonts[font]['size'])) self.data = DictClass(load(file('data/memory.yaml'))) self.game_over_layer = Layer() image = assets.load_image( self.data.game_over[self.game.datastore.datamodel.character].src) item = ItemImage(self.data.game_over.left, self.data.game_over.top, image) self.game_over_layer.add(item) self.main_layer = Layer() self.top_layer = Layer() self.time = self.data.time.max self.timer = DictClass({}) image = assets.load_image(self.data.time.src) self.timer['skin'] = ItemImage(self.data.time.left, self.data.time.top, image) self.timer['value'] = ItemText(self.data.time.left, self.data.time.top, self.font, 0, format_time(self.time), width=image.get_width(), height=image.get_height(), h_align=2, v_align=2) self.top_layer.add(self.timer.skin) self.top_layer.add(self.timer.value) self.score = 0 self.score_board = DictClass({}) image = assets.load_image(self.data.score.src) self.score_board['skin'] = ItemImage(self.data.score.left, self.data.score.top, image) self.score_board['value'] = ItemText(self.data.score.left, self.data.score.top, self.font, 0, str(self.score), width=image.get_width(), height=image.get_height(), h_align=2, v_align=2) self.top_layer.add(self.score_board.skin) self.top_layer.add(self.score_board.value) self.deck = [] image_back = assets.load_image(self.data.board.card_back) for k in range(0, len(self.data.board.cards)): image = assets.load_image(self.data.board.cards[k]) self.deck.append([ Card(self, k, image, image_back), Card(self, k, image, image_back) ]) self.range = self.data.start self.cards = [] self.deal() # Load the sound self.card_flip_sound = assets.load_sound('DGI_card_flip.ogg') self.item_found_sound = assets.load_sound('DGI_item_found.ogg') self.wrong_sound = assets.load_sound('DGI_wrong.ogg') self.lose_bell_sound = assets.load_sound('DGI_lose_bell.ogg') self.lose_music_sound = assets.load_sound('DGI_lose_music.ogg')
def show_next_item(self): self.item_data = DictClass(load(file('data/common/books.yaml'))) GameStage.show_next_item(self) self.item_data = None
return out if __name__ == '__main__': from utils import DictClass config = { 'hidden_dim': 3, 'activation': 'relu', 'dropout_rate': 0.5, 'vocab_size': 10, 'embedding_dim': 300, 'num_classes': 2, 'feature_map': 64, 'kernel_size': [5], } config = DictClass(config) net = SelfAttentionNet(config) from model import TextCNN net = TextCNN(config) # 4 words, embedding_dim = 3 data = nd.array([[np.random.randint(10) for _ in range(200)] for _ in range(1000)]) label = nd.array([np.random.randint(2) for _ in range(1000)]) dataset_train = gluon.data.ArrayDataset(data, label) train_data = gluon.data.DataLoader(dataset_train, batch_size=50, shuffle=True, last_batch='rollover') embedding = text.embedding.CustomEmbedding( 'embedding_files/dummy.embedding', elem_delim=' ')
def __init__(self, stage, title, description, statements, answers): data = DictClass(load(file('data/common/true_false.yaml'))) Question.__init__(self, stage, title, description, data) self.statements = statements self.answers = answers self.__load_items(data)