def send_notify(self, tp=None): if tp: act = ACT_UPDATE tps = [tp] else: act = ACT_INIT tps = ConfigStoreType.INSTANCES.keys() notify = StoreNotify() notify.act = act for _t in tps: ri = RefreshInfo(self.server_id, self.char_id, _t) notify_type = notify.store_types.add() notify_type.tp = _t notify_type.auto_refresh_at = self.next_auto_refresh_timestamp(_t) notify_type.remained_refresh_times = ri.remained_refresh_times notify_type.refresh_cost = ri.refresh_cost for _g in self.doc['tp'][str(_t)]['goods'].keys(): _g_data = self.doc['tp'][str(_t)]['goods'][str(_g)] notify_type_goods = notify_type.goods.add() notify_type_goods.id = int(_g) notify_type_goods.content_index = _g_data['index'] notify_type_goods.remained_times = ConfigStore.get( int(_g)).times_limit - _g_data['times'] MessagePipe(self.char_id).put(msg=notify)
def send_notify(self, tp=None): if tp: act = ACT_UPDATE tps = [tp] else: act = ACT_INIT tps = ConfigStoreType.INSTANCES.keys() notify = StoreNotify() notify.act = act for _t in tps: ri = RefreshInfo(self.server_id, self.char_id, _t) notify_type = notify.store_types.add() notify_type.tp = _t notify_type.auto_refresh_at = self.next_auto_refresh_timestamp(_t) notify_type.remained_refresh_times = ri.remained_refresh_times notify_type.refresh_cost = ri.refresh_cost for _g in self.doc['tp'][str(_t)]['goods'].keys(): _g_data = self.doc['tp'][str(_t)]['goods'][str(_g)] notify_type_goods = notify_type.goods.add() notify_type_goods.id = int(_g) notify_type_goods.content_index = _g_data['index'] notify_type_goods.remained_times = ConfigStore.get(int(_g)).times_limit - _g_data['times'] MessagePipe(self.char_id).put(msg=notify)
def load_options(self): # TODO: move config to MemoryAddress class? # (depends on how monitoring of addresses should work) lines = self.address.get_lines() follow_pc = self.address.get_follow_pc() miss_is_error = False # needed for adding windows defaults = {"[General]": {"nLines": lines, "bFollowPC": follow_pc}} userconfdir = ".hatari" config = ConfigStore(userconfdir, defaults, miss_is_error) configpath = config.get_filepath("debugui.cfg") config.load(configpath) # set defaults try: self.address.set_lines(config.get("[General]", "nLines")) self.address.set_follow_pc(config.get("[General]", "bFollowPC")) except (KeyError, AttributeError): ErrorDialog(None).run( "Debug UI configuration mismatch!\nTry again after removing: '%s'." % configpath) self.config = config
def load_options(self): # TODO: move config to MemoryAddress class? # (depends on how monitoring of addresses should work) lines = self.address.get_lines() follow_pc = self.address.get_follow_pc() miss_is_error = False # needed for adding windows defaults = { "[General]": { "nLines": lines, "bFollowPC": follow_pc } } userconfdir = ".hatari" config = ConfigStore(userconfdir, defaults, miss_is_error) configpath = config.get_filepath("debugui.cfg") config.load(configpath) # set defaults try: self.address.set_lines(config.get("[General]", "nLines")) self.address.set_follow_pc(config.get("[General]", "bFollowPC")) except (KeyError, AttributeError): ErrorDialog(None).run("Debug UI configuration mismatch!\nTry again after removing: '%s'." % configpath) self.config = config
def buy(self, tp, goods_id): if tp not in ALL_TYPES: raise GameException(ConfigErrorMessage.get_error_id("INVALID_OPERATE")) config = ConfigStore.get(goods_id) if not config: raise GameException(ConfigErrorMessage.get_error_id("STORE_GOODS_NOT_EXIST")) try: data = self.doc['tp'][str(tp)]['goods'][str(goods_id)] except KeyError: raise GameException(ConfigErrorMessage.get_error_id("INVALID_OPERATE")) if data['times'] >= config.times_limit: raise GameException(ConfigErrorMessage.get_error_id("STORE_GOODS_NO_TIMES")) if config.condition_id == 1: # VIP 等级 VIP(self.server_id, self.char_id).check(config.condition_value) elif config.condition_id == 2: # 爬塔历史最高星 Tower(self.server_id, self.char_id).check_history_max_star(config.condition_value) elif config.condition_id == 3: # 竞技场当前排名 Arena(self.server_id, self.char_id).check_current_rank(config.condition_value) elif config.condition_id == 4: # 当前公会等级 Union(self.server_id, self.char_id).check_level(config.condition_value) item_id, item_amount, need_id, need_amount = config.content[data['index']] resource_classify = ResourceClassification.classify([(need_id, need_amount)]) resource_classify.check_exist(self.server_id, self.char_id) resource_classify.remove(self.server_id, self.char_id, message="Store.buy:{0}".format(goods_id)) resource_classify = ResourceClassification.classify([(item_id, item_amount)]) resource_classify.add(self.server_id, self.char_id, message="Store.buy:{0}".format(goods_id)) data['times'] += 1 MongoStore.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'tp.{0}.goods.{1}.times'.format(tp, goods_id): data['times'] }} ) self.send_notify(tp=tp) return resource_classify
def load_options(self): # TODO: move config to MemoryAddress class? # (depends on how monitoring of addresses should work) lines = self.address.get_lines() # ConfigStore does checks and type conversions based on names # of Hatari config sections and keys, so this needs to use # same names to avoid asserts, and it can't e.g. save # follow_pc option value, which will keep as run-time one defaults = { "[Debugger]": { "nDisasmLines": lines, } } userconfdir = ".hatari" config = ConfigStore(userconfdir, defaults) configpath = config.get_filepath(".debugui.cfg") config.load(configpath) # set defaults try: self.address.set_lines(config.get("[Debugger]", "nDisasmLines")) except (KeyError, AttributeError): ErrorDialog(None).run( "Debug UI configuration mismatch!\nTry again after removing: '%s'." % configpath) self.config = config
def buy(self, tp, goods_id): if tp not in ALL_TYPES: raise GameException( ConfigErrorMessage.get_error_id("INVALID_OPERATE")) config = ConfigStore.get(goods_id) if not config: raise GameException( ConfigErrorMessage.get_error_id("STORE_GOODS_NOT_EXIST")) try: data = self.doc['tp'][str(tp)]['goods'][str(goods_id)] except KeyError: raise GameException( ConfigErrorMessage.get_error_id("INVALID_OPERATE")) if data['times'] >= config.times_limit: raise GameException( ConfigErrorMessage.get_error_id("STORE_GOODS_NO_TIMES")) if config.condition_id == 1: # VIP 等级 VIP(self.server_id, self.char_id).check(config.condition_value) elif config.condition_id == 2: # 爬塔历史最高星 Tower(self.server_id, self.char_id).check_history_max_star(config.condition_value) elif config.condition_id == 3: # 竞技场当前排名 Arena(self.server_id, self.char_id).check_current_rank(config.condition_value) elif config.condition_id == 4: # 当前公会等级 Union(self.server_id, self.char_id).check_level(config.condition_value) item_id, item_amount, need_id, need_amount = config.content[ data['index']] resource_classify = ResourceClassification.classify([(need_id, need_amount)]) resource_classify.check_exist(self.server_id, self.char_id) resource_classify.remove(self.server_id, self.char_id, message="Store.buy:{0}".format(goods_id)) resource_classify = ResourceClassification.classify([(item_id, item_amount)]) resource_classify.add(self.server_id, self.char_id, message="Store.buy:{0}".format(goods_id)) data['times'] += 1 MongoStore.db(self.server_id).update_one({'_id': self.char_id}, { '$set': { 'tp.{0}.goods.{1}.times'.format(tp, goods_id): data['times'] } }) self.send_notify(tp=tp) return resource_classify
if __name__ == "__main__": a = argparse.ArgumentParser() a.add_argument("--image", help="path to image") a.add_argument("--image_url", help="url to image") a.add_argument("--model") a.add_argument('--config', help='Config key') args = a.parse_args() if not args.image and not args.image_url: a.print_help() sys.exit(1) if args.image: img = Image.open(args.image) else: response = requests.get(args.image_url) img = Image.open(BytesIO(response.content)) cfg_store = ConfigStore() config = cfg_store.get(args.config) model = load_model(config['model']) labels = config['labels'] preds = predict(model, img, target_size) result = [(x, y) for (x, y) in zip(labels, preds)] # Sort by probability result = sorted(result, key=lambda item: item[1], reverse=True)[:TOP_N] pprint(result)