def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) for field in ['contact', 'npc']: if not hasattr(self, field): setattr(self, field, NPC(self.redis)) if not hasattr(self, 'business'): setattr(self, 'business', Business(self.redis)) if not hasattr(self, 'text'): for field in ['hook', 'request']: if hasattr(self, field): self.template = getattr(self, field) + ' ' + self.template for field in ['requirement', 'disclaimer', 'payment']: if hasattr(self, field): self.template = self.template + ' ' + getattr(self, field) self.template = self.template + ' Contact ' + self.contact.name.fullname self.template = self.template + ' at the ' + self.business.name.fullname if hasattr(self, 'detail'): self.template = self.template + ' ' + self.detail self.template += '.' self.text = self.render_template(self.template) self.text = self.render_template(self.text) self.text = self.text[0].capitalize() + self.text[1:]
def __init__(self, operator_skeleton, problem_env, explr_p): Generator.__init__(self, operator_skeleton.type, problem_env) self.explr_p = explr_p self.x_min = copy.deepcopy(self.domain[0]) self.x_max = copy.deepcopy(self.domain[1]) self.domain[0] = self.normalize_x_value(self.domain[0]) # (self.domain[0] - self.x_min) / (self.x_max-self.x_min) self.domain[1] = self.normalize_x_value(self.domain[1]) # (self.domain[1] - self.x_min) / (self.x_max-self.x_min) self.idx_to_update = None operator_name = operator_skeleton.type if operator_name == 'two_arm_pick': target_object = operator_skeleton.discrete_parameters['object'] if type(target_object) == str: target_object = self.problem_env.env.GetKinBody(target_object) dist_fn = lambda x, y: pick_parameter_distance(target_object, x, y) elif operator_name == 'two_arm_place': dist_fn = place_parameter_distance elif operator_name.find('_paps') != -1: n_actions = int(operator_name.split('_')[0]) def dist_fn(x, y): x_obj_placements = np.split(x, n_actions) y_obj_placements = np.split(y, n_actions) dist = 0 for x, y in zip(x_obj_placements, y_obj_placements): dist += place_parameter_distance(x, y, 1) return dist elif operator_name.find('synthe') != -1: def dist_fn(x, y): return np.linalg.norm(x - y) else: print "Wrong operator name" raise ValueError self.doo_tree = BinaryDOOTree(self.domain, self.explr_p, dist_fn) self.update_flag = 'update_me'
def __init__(self, file_path): Generator.__init__(self, file_path) self.faker = Faker() self.local = get_localzone() self.response = ["200", "404", "500", "301", '401', '403'] self.verb = ["GET", "POST", "DELETE", "PUT"] self.resources = ["/bank", "/bank/account", "/bank/account/balance?acc-id=", "/bank/login", "/bank/account/withdraw?acc-id=", "/bank/account/payments?acc-id=", "/bank/account/deposit?acc-id=", "/bank/account/account-security?acc-id="] self.ualist = [self.faker.firefox, self.faker.chrome, self.faker.safari, self.faker.internet_explorer, self.faker.opera]
def __init__(self, redis, features={}, namekey=None): Generator.__init__(self, redis, features, namekey) self.logger = logging.getLogger(__name__) if self.race not in self.redis.lrange('npc_race', 0, -1): raise Exception( ' %s is not a valid race and has no associated data' % self.race) self.generate_features(self.race) self.generate_features(self.covering) self.coveringtext = self.render_template(self.covertemplate) self.details = json.loads(self.details) self.name = Name(self.redis, self.race) if hasattr(self, 'subrace'): self.race = self.subrace_description['subrace'].lower() if not hasattr(self, 'phobia'): self.phobia = phobia.Phobia(self.redis) if not hasattr(self, 'motivation'): self.motivation = motivation.Motivation(self.redis, {'npc': self})
def __init__(self, generators=[], container=SimpleContainer(), database=CassandraConnection()): Generator.__init__(self) if isinstance(container, OrderContainer): self.container = container if isinstance(database, DatabaseConnection): self.database = database self.database.connect() if len(generators) > 0: self.generators = generators else: self.generators = [ CommentLenGenerator(), CommentGenerator(), CurrencyPairGenerator(), DateTimeGenerator(), DescriptionGenerator(), DirectionGenerator(), DurationGenerator(), IdGenerator(), MagicalNumberGenerator(), PriceGenerator(), StatusGenerator(), TagLenGenerator(), TagGenerator(), TypeGenerator(), ] self.data = {}
def __init__(self, abstract_state, abstract_action, sampler, n_parameters_to_try_motion_planning, n_iter_limit, problem_env, pick_action_mode, place_action_mode): self.pick_action_mode = pick_action_mode self.place_action_mode = place_action_mode Generator.__init__(self, abstract_state, abstract_action, sampler, n_parameters_to_try_motion_planning, n_iter_limit, problem_env)
def __init__(self, collection_in): Generator.__init__(self) self.collection = collection_in self.complex = False if(isinstance(collection_in, dict)): self.complex = True self.default_gvars = {"contingent": []}
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) if not hasattr(self, 'text'): self.text = self.render_template(self.template) self.text = self.render_template(self.text) self.text = self.text[0].capitalize() + self.text[1:]
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) if not hasattr(self, 'text'): self.text = self.render_template(self.template) self.text = self.text[0].capitalize() + self.text[1:]
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) self.name=Name(self.redis,'street')
def __init__(self, file_path): Generator.__init__(self, file_path) self.actions = ["ALLOW", "DROP", "REJECT"] self.protocols = ["TCP", "UDP", "ICMP", "ICMPv6"] self.tcp_flags = ["Ack", "Fin", "Psh", "Rst", "Syn", "Urg", "-"] self.paths = ["SEND", "RECEIVE"] self.ip_adresses = "89.216.18.1,89.216.18.2,89.216.18.3,89.216.18.4,89.216.18.5,89.216.18.6,89.216.18.7,89.216.18.8,89.216.18.9,89.216.18.10,89.216.18.11,89.216.18.12,89.216.18.13,89.216.18.14,89.216.18.15,89.216.18.16,89.216.18.17,89.216.18.18,89.216.18.19,89.216.18.20" self.ip_adresses = self.ip_adresses.split(",") random.seed(43)
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) self.select_colors() self.overlay_stripe_countselected = random.randint(0, int(self.overlay_stripe_count)) if not hasattr(self, 'letter'): self.letter = random.choice(string.ascii_uppercase)
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) for person in ['npc', 'victim']: if not hasattr(self, person): setattr(self, person, NPC(self.redis)) self.headline = self.render_template(self.headline) self.lastseen = self.render_template(self.lastseen)
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) # Double parse the template to fill in templated template values. if not hasattr(self, 'text'): self.text = self.render_template(self.template) self.text = self.render_template(self.text) self.text = self.text[0].capitalize() + self.text[1:]
def __init__(self, abstract_state, abstract_action, sampler, n_parameters_to_try_motion_planning, n_iter_limit, problem_env, pick_action_mode, place_action_mode): self.pick_action_mode = pick_action_mode self.place_action_mode = place_action_mode self.basic_tested_samples = [] self.basic_tested_sample_values = [] self.mp_infeasible_samples = [] self.mp_infeasible_labels = [] Generator.__init__(self, abstract_state, abstract_action, sampler, n_parameters_to_try_motion_planning, n_iter_limit, problem_env)
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) self.generate_features('motivation' + self.kind) if not hasattr(self, 'npc'): self.npc = npc.NPC(self.redis, {'motivation': self}) self.text = self.render_template(self.text)
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) self.select_colors() self.overlay_stripe_countselected = random.randint( 0, int(self.overlay_stripe_count)) if not hasattr(self, 'letter'): self.letter = random.choice(string.ascii_uppercase)
def __init__(self, xml): Generator.__init__(self) if os.path.isfile(xml): plugin_tree = etree.parse(xml) plugins = plugin_tree.xpath("/plugins/plugin") for plugin in plugins: self.__generate_plugin__(plugin, xml) else: print "XML file: " + xml + " not valid !"
def __init__(self, level): Generator.__init__(self, level) self.size = 80 self.width = random.randint(self.size*0.4, self.size*0.6) * 2 self.height = random.randint(self.size*0.4, self.size*0.6) * 2 self.orientation = random.randint(0,3) self.corridor_size = random.randint(self.size*0.2, self.size*0.3) self.room_size = random.randint(4, 6) self.randomness = 0#random.randint(0, 4) self.reflect_axis = HORIZONTAL self.reflect_centre = 0.5
def __init__(self, redis, features={}): """ Generate a Rogue-like dungeon """ Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) self.generate_features('dungeon') self.generate_grid() self.generate_rooms() self.generate_halls() self.name=Name(self.redis, 'dungeon')
def __init__(self, operator_name, problem_env, explr_p, c1, sampling_mode, counter_ratio): Generator.__init__(self, operator_name, problem_env) self.explr_p = explr_p self.evaled_actions = [] self.evaled_q_values = [] self.c1 = c1 self.idx_to_update = None self.robot = self.problem_env.robot self.sampling_mode = sampling_mode self.counter_ratio = 1.0 / counter_ratio
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) if not hasattr(self, 'regioncount'): self.regioncount = random.randint(self.regiondetails['mincount'], self.regiondetails['maxcount']) if not hasattr(self, 'leader'): self.leader = leader.Leader(self.redis, {"location":self}) #self.leader = Leader(self.redis) if not hasattr(self, 'name'): self.name = Name(self.redis, 'country')
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) if not hasattr(self, 'leader'): self.leader = leader.Leader(self.redis, {"location": self}) #self.leader = Leader(self.redis) if not hasattr(self, 'text'): self.text = self.render_template(self.template) self.name = Name(self.redis, 'organization', {'leader': self.leader})
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) if not hasattr(self, 'leader'): self.leader = leader.Leader(self.redis, {"location":self}) #self.leader = Leader(self.redis) if not hasattr(self, 'text'): self.text = self.render_template(self.template) self.name=Name(self.redis, 'organization', {'leader':self.leader})
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) for person in ['npc', 'villain']: if not hasattr(self, person): setattr(self, person, NPC(self.redis)) if not hasattr(self, 'text'): self.text = self.render_template(self.template) self.text = self.render_template(self.text) self.text = self.text[0].capitalize() + self.text[1:]
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) if not hasattr(self, 'deity'): self.deity = deity.Deity(redis) if not hasattr(self, 'domain'): portfolio = self.deity.portfolios random.shuffle(portfolio) self.domain = portfolio[0] self.name="sect name placeholder"
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) if not hasattr(self, 'text'): # TODO move this to the data file # self.text=self.render_template("{{params.quality['name']|article}} # {{params.kind}}, {{params.repair['name']}}") self.text = self.render_template(self.template) self.text = self.text[0].capitalize() + self.text[1:]
def __init__(self, level): Generator.__init__(self, level) self.size = 50 self.width = random.randint(self.size*0.4, self.size*0.6) * 2 self.height = random.randint(self.size*0.4, self.size*0.6) * 2 self.orientation = random.randint(0,3) self.turretsize = random.randint(6,10) self.gatesize = random.randint(1,4) self.wallwidth = random.randint(3,4) self.turret_project = random.randint(2, min(4, self.turretsize-3)) self.gatehouse_project = random.randint(0,4) if self.gatesize % 2 == 1: self.width -= 1
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) if not hasattr(self, 'deity'): self.deity = deity.Deity(redis) if not hasattr(self, 'domain'): portfolio = self.deity.portfolios random.shuffle(portfolio) self.domain = portfolio[0] self.name = "sect name placeholder"
def __init__(self, level, size=80, house_size=9, house_chance=0.5, branchiness=0.8, **params): Generator.__init__(self, level) self.size = size self.road_width = 1 self.house_size = house_size self.house_chance = house_chance self.branchiness = branchiness self.road_length = house_size*2 self.num_roads = size/house_size for param in params: self.setattr(param, params[param])
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) for person in ["victim", "culprit", "source", "believer"]: if not hasattr(self, person): setattr(self, person, NPC(self.redis).name.fullname) if not hasattr(self, "text"): self.text = self.render_template(self.template) self.text = self.render_template(self.text) self.text = self.text[0].capitalize() + self.text[1:]
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) for person in ['victim', 'culprit', 'source', 'believer']: if not hasattr(self, person): setattr(self, person, NPC(self.redis).name.fullname) if not hasattr(self, 'text'): self.text = self.render_template(self.template) self.text = self.render_template(self.text) self.text = self.text[0].capitalize() + self.text[1:]
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) # If we're passing in a list of countries, we're hard-setting the country count. if hasattr(self,'countries'): self.countrycount=len(self.countries) if not hasattr(self,'name'): self.name=Name(self.redis, 'continent') # set a random count if not hasattr(self, 'countrycount'): self.countrycount = random.randint(self.countrydetails['mincount'], self.countrydetails['maxcount'])
def __init__(self, operator_name, problem_env, explr_p): Generator.__init__(self, operator_name, problem_env) self.explr_p = explr_p self.evaled_actions = [] self.evaled_q_values = [] if operator_name == 'two_arm_pick': dim_x = 6 else: dim_x = 3 self.gp = StandardContinuousGP(dim_x) self.acq_fcn = UCB(zeta=explr_p, gp=self.gp) self.gp_format_domain = Domain(0, self.domain) self.gp_optimizer = BO(self.gp, self.acq_fcn, self.gp_format_domain) # this depends on the problem
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) if not hasattr(self, 'count'): self.count = random.randint(self.amount['min'], self.amount['max']) if not hasattr(self, 'color'): self.color = random.choice(self.kind_description['color']) if not hasattr(self, 'text'): self.text = self.render_template(self.template) self.text = self.render_template(self.text) self.text = self.text[0].capitalize() + self.text[1:]
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) self.generate_features('govt' + self.kind) if not hasattr(self, 'body'): # TODO this should have an if statement on kind and also do cities if self.kind == 'city': self.body = City(self.redis) elif self.kind == 'country': self.body = Country(self.redis) else: self.body = Country(self.redis)
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) # If we're passing in a list of countries, we're hard-setting the country count. if hasattr(self, 'countries'): self.countrycount = len(self.countries) if not hasattr(self, 'name'): self.name = Name(self.redis, 'continent') # set a random count if not hasattr(self, 'countrycount'): self.countrycount = random.randint(self.countrydetails['mincount'], self.countrydetails['maxcount'])
def __init__(self, server, namesource, features={}): """ Given a namesource, generate features for it: e.g. human -> humanname_* Next, query redis and ensure that templates exist for the three basic names (full, short, formal). Finally, render the templates using the naming features already generated. """ Generator.__init__(self, server, features) self.logger = logging.getLogger(__name__) self.namesource=namesource #Generate the content for a name, e.g. humanname_* self.generate_features(namesource+"name") #Now that we have the features, render the names self.render()
def __init__(self, redis, features={}): """ Generate a Geomorph-like dungeon """ #FIXME geomorph and rogue should share a parent DungeonGenerator #FIXME move the dungeon_template to a dungeon_name object or something Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) #These are generic dungon features shared with RogueDungeon self.generate_features('dungeon') self.name=Name(self.redis,'dungeon') self.width = self.gridwidth['tiles'] self.height = self.gridheight['tiles'] self.generate_grid() self.generate_connections() self.set_tiletypes()
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) if not hasattr(self, 'place'): self.place = Region(self.redis) self.subkind = self.kind + '_' + self.rand_value(self.kind + '_kind') self.generate_features(self.subkind) if not hasattr(self, 'text'): self.text = self.render_template(self.template) self.text = self.render_template(self.text) self.text = self.text[0].capitalize() + self.text[1:]
def __init__(self, redis, features={}): """ Generate a Geomorph-like dungeon """ #FIXME geomorph and rogue should share a parent DungeonGenerator #FIXME move the dungeon_template to a dungeon_name object or something Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) #These are generic dungon features shared with RogueDungeon self.generate_features('dungeon') self.name = Name(self.redis, 'dungeon') self.width = self.gridwidth['tiles'] self.height = self.gridheight['tiles'] self.generate_grid() self.generate_connections() self.set_tiletypes()
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) if not hasattr(self, 'count'): self.count = random.randint(self.amount['min'], self.amount['max']) if not hasattr(self, 'name'): self.name=Name(self.redis,'currency') # Double parse the template to fill in templated template values. if not hasattr(self, 'text'): self.text = self.render_template(self.template) self.text = self.render_template(self.text) self.text = self.text[0].capitalize() + self.text[1:]
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) self.generate_features(self.kind) self.npc = NPC(redis) self.curse_chance_roll = random.randint(1, 100); if self.curse_chance_roll < self.curse_chance : self.curse = Curse(redis) else: del self.curse self.build_creator() text = self.render_template(self.name_template) self.name = self.render_template(text)
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) # if self.you and self.other are not set, set them to defaults. if not hasattr(self, 'you'): self.you = 'you' # a random NPC if not hasattr(self, 'other'): self.other = npc.NPC(self.redis).name.fullname # We put you and other in an array so we can randomly select # who is the subject and who is the object. members = [self.you, self.other] random.shuffle(members) if not hasattr(self, 'either'): self.either = members[0] random.shuffle(members) # We use partyA/partyB syntax in the templates if not hasattr(self, 'partyA'): self.partyA = members.pop() if not hasattr(self, 'partyB'): self.partyB = members.pop() # If we don't already have text, we need to render a template if not hasattr(self, 'text'): # if we have it, we need to add a "when" as well if hasattr(self, 'when'): self.template = self.when + ', ' + self.template self.text = self.render_template(self.template) # final sentence is stored as self.text. # note the need for capitalization of the first character self.text = self.text[0].capitalize() + self.text[1:]
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) self.generate_features(self.kind) self.senses = [] # originally I was going to move these to a for loop, but the verb # doesn't match the variable name, so it would require refactoring # of the dataset and every other damn thing. Meh. if hasattr(self, 'smell'): self.smell = 'you smell ' + self.smell self.senses.append(self.smell) if hasattr(self, 'sound'): self.sound = 'you hear ' + self.sound self.senses.append(self.sound) if hasattr(self, 'sight'): self.sight = 'you see ' + self.sight self.senses.append(self.sight) if not hasattr(self, 'owner'): self.owner = NPC(redis) # TODO patrons should be better calculated if not hasattr(self, 'patroncount'): self.patroncount = random.randint(1, 10) # Business is one of the few classes where trailer doesn't start as part of the name # So we have to add it here. self.name = Name(self.redis, 'business', {'trailer': self.trailer}) # If maxfloors isn'd designated, set it to 1 if not hasattr(self, 'maxfloors'): self.maxfloors = 1 # don't set floors if it already exists if not hasattr(self, 'floor'): self.floor = random.randint(1, int(self.maxfloors))
def __init__(self, redis, features={}): Generator.__init__(self, redis, features) self.logger = logging.getLogger(__name__) self.generate_features(self.kind) self.senses = [] # originally I was going to move these to a for loop, but the verb # doesn't match the variable name, so it would require refactoring # of the dataset and every other damn thing. Meh. if hasattr(self, 'smell'): self.smell = 'you smell ' + self.smell self.senses.append(self.smell) if hasattr(self, 'sound'): self.sound = 'you hear ' + self.sound self.senses.append(self.sound) if hasattr(self, 'sight'): self.sight = 'you see ' + self.sight self.senses.append(self.sight) if not hasattr(self, 'owner'): self.owner = NPC(redis) # TODO patrons should be better calculated if not hasattr(self, 'patroncount'): self.patroncount = random.randint(1, 10) # Business is one of the few classes where trailer doesn't start as part of the name # So we have to add it here. self.name=Name(self.redis, 'business', {'trailer': self.trailer}) # If maxfloors isn'd designated, set it to 1 if not hasattr(self, 'maxfloors'): self.maxfloors = 1 # don't set floors if it already exists if not hasattr(self, 'floor'): self.floor = random.randint(1, int(self.maxfloors))