def __init__(self, log): # Call parent init UserDict.__init__(self) # Turn first line into syslog if len(log) > 0: first_entry = log[0] else: sys.exit() # Local Variables counter = 0 self.second = 0 self.minute = 0 self.hour = 0 self.day = 1 self.month = str(first_entry.month) self.year = first_entry.year self.unit = "month" self.duration = 12 start_date = datetime.datetime( int(self.year), int(self.month), int(self.day), int(self.hour), int(self.minute), int(self.second) ) start_key = start_date.year + start_date.month # Zero out each entry, this will fill in blanks which # may be in the log, especially sparse logs. for i in range(0, self.duration): # Calculate the current date, the last one will be the end date end_date = start_date + datetime.timedelta(days=i * 365 / 12 + 1) end_key = str(end_date.year) + str("%.2d" % (end_date.month)) self.zero(end_key) logging.debug("End Date: " + str(end_date)) logging.debug("End Key: " + end_key) # Check for middle date and save if i == (self.duration / 2): middle_date = end_date # Save final values self.start_date = start_date self.middle_date = middle_date self.end_date = end_date # Create a dictionary with an entry for each line. Increment # the value for each time the word is found. Merge lines by # Removing numbers and replacing them with a single '#' for entry in log: # Create key rooted in time key = entry.year + entry.month # Check to make sure key is found in the list built above if key in self.keys(): self.increment(key) self.build_calculations()
def __init__(self, name = '', kind = 'module', ispkg = 0): UserDict.__init__(self) self.imports = {'plain': [], 'from': []} self.activated = 0 self.ispkg = ispkg self.name = name self.kind = kind
def __init__(self, defaults = {}, types = {}): """Constructor. If any filenames given tries to parse them Input: (string) filename. You can pass pultiple file names (dict) defaults: {'section': {'attrib': 'value'}}, (dict) types: {'section': {'attrib': 'type'}}; See Typecast.py for supported types. Output: (Config) class instance """ UserDict.__init__(self) # create self.data self.cliParser = None # we don't need CLI parser by default self.fileParser = SafeConfigParser() self._types = types self._defaults = defaults # set defaults in configfile parser fileParser = self.fileParser for (section, attributes) in defaults.items(): section = str(section) if not fileParser.has_section(section): fileParser.add_section(section) for (key, value) in attributes.items(): key = str(key) value = str(value) key = fileParser.optionxform(key) fileParser.set(section, key, value) # store parsed default values self.storeParsedFileItems()
def __init__(self, name): """ Class which serves as a placeholder for player's data """ UserDict.__init__(self) self.dict_file = DictFile(name) temp = self.dict_file.read() for key, value in temp.items(): self[key] = value self.buying = False self.passed = 0 self.killed = 0 self.lpassed = 0 self.newa = False self.lost = False self.passed = 0 self.failed = 0 self.collected = 0 self.charges = 0 self.hasscroll = 0 self.tw = 0 self.sp = 0 self.paused = 1 self["magicka"] = 0
def __init__(self, action, ec): if isinstance(action, dict): lazy_keys = [] UserDict.__init__(self, action) if 'name' in self.data: self.data.setdefault( 'id', self.data['name'].lower() ) self.data.setdefault( 'title', self.data['name'] ) del self.data['name'] self.data.setdefault( 'url', '' ) self.data.setdefault( 'category', 'object' ) self.data.setdefault( 'visible', True ) self.data['available'] = True else: # if action isn't a dict, it has to implement IAction (lazy_map, lazy_keys) = action.getInfoData() UserDict.__init__(self, lazy_map) self.data['allowed'] = True permissions = self.data.pop( 'permissions', () ) if permissions: self.data['allowed'] = self._checkPermissions lazy_keys.append('allowed') self._ec = ec self._lazy_keys = lazy_keys self._permissions = permissions
def __ParseString(self, str, patt=_CookiePattern): i = 0 # Our starting point n = len(str) # Length of string M = None # Current morsel while 0 <= i < n: # Start looking for a cookie match = patt.search(str, i) if not match: break # No more cookies K,V = match.group("key"), match.group("val") i = match.end(0) # Parse the key, value in case it's metainfo if K[0] == "$": # We ignore attributes which pertain to the cookie # mechanism as a whole. See RFC 2109. # (Does anyone care?) if M: M[ K[1:] ] = V else: M = Morsel() M.set(K, apply(self.net_setfunc, (V,)), V) UserDict.__setitem__(self, K, M) return
def __init__(self, model, query_parameters, *args, **kwargs): self._model = model # Core options, not modifiable by client updates if "columns" not in kwargs: model_fields = model._meta.local_fields kwargs["columns"] = map(lambda f: f.verbose_name.capitalize(), model_fields) if "hidden_columns" not in kwargs or kwargs["hidden_columns"] is None: kwargs["hidden_columns"] = [] if "search_fields" not in kwargs or kwargs["search_fields"] is None: kwargs["search_fields"] = [] # Absorb query GET params kwargs = self._normalize_options(query_parameters, kwargs) UserDict.__init__(self, DEFAULT_OPTIONS, *args, **kwargs) self._flat_column_names = [] for field_name in self.columns: if isinstance(field_name, (tuple, list)): pretty_name, field_name = field_name[:2] if not field_name or isinstance(field_name, (tuple, list)): field_name = pretty_name self._flat_column_names.append(field_name)
def __setitem__(self, key, value): if not self.__dict__.has_key(key): self.__keys__.append(key) self.__sorted__ = False UserDict.__setitem__(self, key, value)
def __init__(self, datasrc, defaultcontext=None): """ Arguments: datasrc -- The data source for this instance. May be given in any of three forms: (1) the name of a CSS file, (2) a string containing style data in CSS syntax, or (3) a dictionary in the same form as self.data defaultcontext -- (OPTIONAL) The default context from which others inherit properties. If your stylesheet is for an ordinary web page, for example, you might use "BODY" as a default context. Must be present in the data source. """ UserDict.__init__(self) if type(datasrc) is type({}): self.data = datasrc else: if os.path.isfile(datasrc): cssdata = self._readin(datasrc) elif type(datasrc) is type(""): cssdata = datasrc else: raise RuntimeError, "Invalid data type: %s" % type(datasrc) self._parse(cssdata) self.defaultcontext = defaultcontext
def __init__(self, init_dict=None, **kwargs): UserDict.__init__(self) self.child_classes = {} self.conf_vars = {} for cls in iterbases(self, ConfBase): if hasattr(cls, "_child_classes"): for key, val in cls._child_classes.iteritems(): self.child_classes[key] = val if hasattr(cls, "_conf_vars"): for conf_var in cls._conf_vars: if isinstance(conf_var, basestring): conf_var = {"name": conf_var} conf_var = ConfVar(conf_var) self.conf_vars[conf_var.name] = conf_var json_str = kwargs.get("json_str") if json_str is not None: del kwargs["json_str"] init_dict = json.loads(json_str) if init_dict is None: init_dict = {} else: print init_dict print repr(init_dict) for key, val in init_dict.iteritems(): self[key] = val for key, val in kwargs.iteritems(): self[key] = val for key, val in self.child_classes.iteritems(): if key not in self: self[key] = val() self.do_init(**kwargs)
def __init__(self, action, ec): if isinstance(action, dict): lazy_keys = [] UserDict.__init__(self, action) if "name" in self.data: self.data.setdefault("id", self.data["name"].lower()) self.data.setdefault("title", self.data["name"]) del self.data["name"] self.data.setdefault("url", "") self.data.setdefault("category", "object") self.data.setdefault("visible", True) self.data["available"] = True else: # if action isn't a dict, it has to implement IAction (lazy_map, lazy_keys) = action.getInfoData() UserDict.__init__(self, lazy_map) self.data["allowed"] = True permissions = self.data.pop("permissions", ()) if permissions: self.data["allowed"] = self._checkPermissions lazy_keys.append("allowed") self._ec = ec self._lazy_keys = lazy_keys self._permissions = permissions
def __setitem__(self, key, item): """ inserts a key, value pair, converting all textual components to unicode and optionally removing junk from strings """ if self.cleanValues: cleanItem = self.__toUnicode(item) else: cleanItem = item UserDict.__setitem__(self, self.__keytransform(key), cleanItem)
def __init__(self, filename=""): """initialize with content of patternfile""" UserDict.__init__(self) self.data = {} self.cnt = 1 if len(filename) > 0: self.__read_pattern_file(filename)
def test_indexing_on_delete(): # erase previously created tiddler by blanking its tags tiddler = UserDict() tiddler.title = 'HelloWorld' tiddler.bag = 'alpha' tiddler.tags = [] hooks.tiddler_put_hook(STORE, tiddler) tiddler.bag = 'bravo' tiddler.tags = ['aaa', 'bbb', 'ccc'] hooks.tiddler_put_hook(STORE, tiddler) tiddler = UserDict() tiddler.title = 'LoremIpsum' tiddler.bag = 'bravo' tiddler.tags = ['...', 'bbb'] hooks.tiddler_put_hook(STORE, tiddler) tids, tags, rels = _retrieve_all() assert len(tids) == 2 assert len(tags) == 4 assert len(rels) == 5 hooks.tiddler_delete_hook(STORE, tiddler) tids, tags, rels = _retrieve_all() assert len(tids) == 1 assert tids[0][1] == 'HelloWorld' assert len(tags) == 3 assert [tag[1] for tag in tags] == ['aaa', 'bbb', 'ccc'] assert len(rels) == 3
def __init__(self, object, message, valueDict={}, **valueArgs): """ Initializes an error with the object the error occurred for, and the user-readable error message. The message should be self sufficient such that if printed by itself, the user would understand it. """ UserDict.__init__(self) self._object = object self._message = message self.update(valueDict) self.update(valueArgs)
def __init__(self,tempdir=None,stdin=None,stderr=None,stdout=None, executor=Popen,use_defIOE=0,name=None,cleanup=0,args=None,logfile=None): '''main functionality is to determine default temp dir and I/O/E settings ''' UserDict.__init__(self) self["executor"] = executor self['cleanup'] = cleanup self['files'] = [] self['logfile'] = logfile self['out'] = None if args: self.controller_type = os.path.basename(args[0]) self['args'] = args if name: self["name"] = name else: self["name"] = random_filename(prefix=self.controller_type) if tempdir: #no longer calls setitem, must do this manually, or in compose_arg self.data["tempdir"] = tempdir else: #not explicitly set by call; wait on dir creation prog = sys.argv[0] and sys.argv[0] or self.__module__ self.data["tempdir"] = os.path.join(paths["temp"],os.path.basename(prog)) #if use_defIOE=1 set stdin, stderr and stdout based on self.default_IOE(), #otherwise use individual arguments #since assignment is to self.data instead of self, __setitem__ behaviors do not fire (self.data["stdin"],self.data["stdout"],self.data["stderr"]) = \ use_defIOE and self.default_IOE() or (stdin,stdout,stderr)
def __init__(self, file_name=None): """Creates a VehicleDict composed by vehicles objects, from a file with a list of vehicles. Requires: If given, file_name is str with the name of a .txt file containing a list of vehicles organized as in the examples provided in the general specification (omitted here for the sake of readability). Ensures: if file_name is given: a VehiclesDict, composed by objects of class Vehicle that correspond to the vehicles listed in file with name file_name. if file_name is none: a empty VehiclesList. """ UserDict.__init__(self) inFile = FileUtil(file_name) for line in inFile.getContent(): vehicleData = line.rstrip().split(", ") vehiclePlate = vehicleData.pop(VehiclesDict.INDEXVehiclePlate) vehicleModel, vehicleAutonomy, vehicleKms = vehicleData newVehicle = Vehicle(vehiclePlate, vehicleModel, vehicleAutonomy, vehicleKms) self[vehiclePlate] = newVehicle
def __setitem__(self, key, item): if key == None: raise Exception('I don\'t know how to handle None as a key.') UserDict.__setitem__(self, key, item) if self._preferred_order and key in self._preferred_order: self._keys[self._preferred_order.index(key)] = key elif key not in self._keys: self._keys.append(key)
def __init__(self, filename, _ser=None, _load=True, _open_cm=None): UserDict.__init__(self) ## Just to honour it if _ser is None: _ser = {'dump': json.dump, 'load': json.load} ## Allow specifying dumps/loads instead of dump/load if 'dump' not in _ser: _ser = dict(_ser, dump=_dumps_to_dump(_ser['dumps'])) if 'load' not in _ser: _ser = dict(_ser, dump=_loads_to_load(_ser['loads'])) ## ... self._ser = _ser ## Prefer AtomicFile for writing if available. if _open_cm is None: try: from atomicfile import AtomicFile except Exception: ## Alas, nope _open_cm = open else: _open_cm = AtomicFile self._open_cm = _open_cm ## ... self._filename = filename data = {} if _load: data = self.try_load() or data self.data = data
def __init__(self,parent=None): UserDict.__init__(self) assert parent is None or isinstance(parent,CommandDict) self.__parent = parent self.__lookuptable = {}
def update(self, dict=None, **kwargs): if dict: UserDict.update(self, dict) for key in dict: self._add_key(key) if kwargs: self.update(kwargs)
def __init__(self,filename=None): UserDict.__init__(self) if filename: self.load(filename) self._filter=None self._ref_re=re.compile(r' +\| +')
def __init__(self): UserDict.__init__(self) self['meta']= {} self['faces'] = [] self['nc_codes']= self._nc_codes() # stop this business of user dict subclassing, it's useless here self['reg'] = self._reg()
def __init__(self, changes={}): UserDict.__init__(self) self.network_config = NetworkConfig() self.outer_network_config = OuterNetworkConfig() self.output_config = OutputConfig() self.choice_set_config = ChoiceSetConfig() self.assign_config = AssignConfig() # location of travel data in matsim format self["travel_dir"] = r"X:\Projects\BikeModel\data\bike_model\input\travel\2010_04_18" # directory with trip start times in hours on 24 hr clock self["time_file"] = r"X:\Projects\BikeModel\data\bike_model\input\context\2010_04_18\time.csv" # to holdback a sample of observations from estimation to use for validation self["use_holdback_sample"] = True self["holdback_rate"] = 0.10 self["holdback_from_file"] = True self["holdback_file"] = r"X:\Projects\BikeModel\data\bike_model\input\holdback\Holdback.csv" self["n_processes"] = 4 """deprecated""" # rules to lookup time dependent variables in network data { variable in choice_set_config : [ ( (time lower bound, time upper bound) , variable to lookup), ... ,('else', variable to lookup if time outside preceeding bounds) ]} # else condition must be last for each rule self["time_dependent_relation"] = { "V": [((3, 6), "V_EA"), ((6, 9), "V_AM"), ((9, 15.5), "V_MD"), ((15.5, 18.5), "V_PM"), ("else", "V_EV")] } # this gives the location of travel data with chosen routes that are hard to reproduce, used in route_model.evaluate_parameters self["imperfect_file"] = r"X:\Projects\BikeModel\data\bike_model\input\optim\imperfect.csv" for key in changes: self[key] = changes[key]
def __init__(self, deviceData=None, address=None): UserDict.__init__(self) self["data"] = deviceData self["address"] = address #self["geocoding"] = None # Fecha y hora (del sistema) self["datetime"] = datetime.datetime.now()
def __init__(self, name, config, workload, dbs): UserDict.__init__(self) self.name = name self.num_nodes = config['num_nodes'] self.category = config['category'] self._dbs = dbs self.update_time = workload['timestamp'] self["name"] = self.name self['num_nodes'] = self.num_nodes self['category'] = self.category self["update_time"] = self.update_time if self.category == "hpc": # we have a list of Queue instances, to inspect queue information, # indexed by queue name self.queues = dict() for queue_name in config['queue_info']: self.queues[queue_name] = Queue(self.name, queue_name, config['queue_info'][queue_name], workload[queue_name]) self['queues'] = self.queues elif self.category == "grid": self.num_queueing_jobs = workload['num_queueing_jobs'] self.busy_jobslots = workload['busy_jobslots'] self.idle_jobslots = workload['idle_jobslots'] self["num_queueing_jobs"] = self.num_queueing_jobs self["busy_jobslots"] = self.busy_jobslots self["idle_jobslots"] = self.idle_jobslots self.sites = dict() for site_name in config['site_info']: self.sites[site_name] = Site(self.name, site_name, config['site_info'][site_name], workload[site_name]) self['sites'] = self.sites
def test_UserDict_as_prototype(self): d = UserDict() e = derive(d) e = derive(d, bind=dict(keys=d)) d['a'] = 1 self.assertRaises(KeyError, lambda :e['a']) self.assertEqual(e.keys(), d.keys())
def __init__( self, binaryDataString ): UserDict.__init__( self ) self.binaryData = binaryDataString self.length = len( self.binaryData ) - 2 self.calculateChecksum() if self.checksum: self.interpretBinaryData()
def __init__(self, rawItems): """Canonicalize a dictionary of configuration items. Values in a configuration item dictionary are, canonically, an object subclassed from black.configure.Item. However, shortcuts are allowed for specification. For example, a Blackfile could simple set a string value to create a configuration datum that is always applicable, has no related configuration option, and whose value is that string. """ UserDict.__init__(self) for name, item in rawItems.items(): if item is None: continue elif isinstance(item, (int, long, float, str, tuple, list, dict)): # this is a simple Datum() self.data[name] = Datum(name, value=item) elif type(item) == types.InstanceType: # this had better be an instance subclassed from class Item if isinstance(item, Item): self.data[name] = item else: raise ConfigureError("The configuration item '%s' does "\ "not derive from class %s.\n" % (name, Item)) else: raise ConfigureError("Don't know how to massage a "\ "configuration item of type %s: %s" % (type(item), item))
def __init__(self, name, check_list, minions=(), **kwargs): self.minions = [] self.name = name self.check_list = check_list for minion in minions: self.minions.append(minion) UserDict.__init__(self, **kwargs)
def __init__(self, obj): # wrap the object UserDict.__init__(self) self.data = obj
def __init__(self, param): UserDict.__init__(self) self._param = param if param.is_enum(): for key in param.get_opt_keys(): self[key] = str(param.get_opt(key))
def __setitem__(self, key, item): UserDict.__setitem__(self, key, item) if key not in self._keys: self._keys.append(key)
def __init__(self, dict=None): self._keys = [] UserDict.__init__(self, dict)
def copy(self): if self.__class__ is UserDict: return UserDict(self.data) import copy return copy.copy(self)
def __init__(self, changes={}): UserDict.__init__(self) """how to project outer trips to the county line""" self['max_inner'] = 981 #maximum zone id for SF county self['outer_importance_conditions'] = [ (982, 1348), (2403, 2455) ] #zones with non-negligible trips to SF self[ 'boundary_condition'] = 'MTYPE' #network variable that indicates links which are inside SF self[ 'outer_impedance'] = "DISTANCE" #netowrk variable to minimize when projecting trips to county line """trip matrices to assign""" self['matrix_filenames'] = [ r"X:\Projects\BikeModel\data\bike_model\input\matrix\am.csv", r"X:\Projects\BikeModel\data\bike_model\input\matrix\md.csv", #r"X:\Projects\BikeModel\data\bike_model\input\matrix\pm.csv", #r"X:\Projects\BikeModel\data\bike_model\input\matrix\ev.csv", #r"X:\Projects\BikeModel\data\bike_model\input\matrix\ea.csv" ] self['load_names'] = ['BIKE_AM', 'BIKE_PM'] #'BIKE_MD','BIKE_EV','BIKE_EA' """override bound_file from choice_set_config""" self[ 'bound_file'] = r'X:\Projects\BikeModel\data\bike_model\input\bound\BoundPredict.csv' """use x times as many random seeds as needed for each source""" self['inverted_multiple'] = 2 """path storage""" self['pickle_path'] = 'C:/pickle_path' #directory to store path files self[ 'delete_paths'] = False #delete the paths after assignment is complete? self[ 'load_paths_from_files'] = False #use already generated paths rather than starting anew? """how to trace variables for utility function""" self['variables'] = [ 'DISTANCE', 'B1', 'B2', 'B3', 'TPER_RISE', 'WRONG_WAY', 'TURN' ] self['aliases'] = [ 'DISTANCE', 'BIKE_PCT_1', 'BIKE_PCT_2', 'BIKE_PCT_3', 'AVG_RISE', 'WRONG_WAY', 'TURNS_P_MI' ] self['weights'] = [ None, 'DISTANCE', 'DISTANCE', 'DISTANCE', 'DISTANCE', 'DISTANCE', None ] self['trace_funs'] = ['sum', 'avg', 'avg', 'avg', 'avg', 'avg', 'sum'] self['final_funs'] = [None, None, None, None, None, None, None] self['path_size'] = True self['path_size_log'] = True self['path_size_alias'] = 'lnpathsize' self['divisors'] = { 'TURNS_P_MI': 'DISTANCE' } # calculate this alias by dividing by this variable """fixed coefficients""" self['fixed_coefficients'] = [ 'DISTANCE', 'TURNS_P_MI', 'WRONG_WAY', 'BIKE_PCT_1', 'BIKE_PCT_2', 'BIKE_PCT_3', 'AVG_RISE', 'lnpathsize' ] self['alpha'] = [-1.05, -0.21, -13.30, 1.89, 2.15, 0.35, -154.0, 1.0] """random coefficients""" self['use_random_coefficients'] = False self['random_coefficients'] = [ ] #['BIKE_PCT_1','BIKE_PCT_2','BIKE_PCT_3','AVG_RISE'] self['random_transformations'] = [] #[idenfun,idenfun,idenfun,idenfun] self['latent_mu'] = [] #[1.82,2.49,0.76,-2.22] self['latent_sigma'] = array([]) """array( [ [24.95, 0., 6.58, 0. ], [0., 5.45, 2.91, 0. ], [0., 0., 4.19, 0. ], [0., 0., 0., 3.85 ] ] )""" self[ 'mixing_granularity'] = 0.2 # number of trips to simulate as an individual """for debugging code""" self['test_small_matrix'] = True for key in changes: self[key] = changes[key]
def test_dict_likes(self): for thing in [dict(), UserDict(), MyMapping()]: assert_equals(is_dict_like(thing), True, thing)
def __init__(self, changes={}, method='doubly_stochastic'): UserDict.__init__(self) if method == 'link_elimination': self['method'] = 'link_elimination' self['master_size'] = 96 self['consider_size'] = 96 self['overlap_var'] = 'DISTANCE' self['only_bound'] = False self['inverted'] = False self['allow_duplicates_of_chosen_route'] = True else: self['method'] = 'doubly_stochastic' """filtering parameters""" self[ 'overlap_threshold'] = 0.9 # filter out routes that have an overlap above this self[ 'overlap_var'] = 'DISTANCE' # network variable for calculating overlap """prior coefficient distribution parameters""" self[ 'ext_bound'] = True # use same distribution for each observation (False is deprecated) self[ 'only_bound'] = False # in prepare_estimation.py, only extract prior distribution rather than continuing to generate choice sets? self[ 'bound_from_file'] = True # use distribution from file rather than extracting? self[ 'bound_file'] = r'X:\Projects\BikeModel\data\bike_model\input\bound\BoundPredict.csv' #file to use self[ 'bound_file_override'] = True # override variable configuration in this choice_set_config if using file? self[ 'bounding_box_sample_size'] = 500 # max number of observations to sample self[ 'tolerance'] = 0.01 # percentage threshold to stop binary search when extracting prior distribution self[ 'log_prior'] = True # use log-uniform prior? (False means uniform prior) """variable configuration""" self['variables'] = [ 'DISTANCE', 'BNE1', 'BNE2', 'BNE3', 'WRONG_WAY', 'TPER_RISE', 'TURN' ] #network variables to use in choice set generation self['ref'] = 'DISTANCE' #reference variable (coef fixed to 1) self['ranges'] = { 'BNE1': [0.0000001, 1000.0], 'BNE2': [0.0000001, 1000.0], 'BNE3': [0.0000001, 1000.0], 'TPER_RISE': [0.00001, 100000.0], 'WRONG_WAY': [0.0000001, 1000.0], 'TURN': [0.0000001, 1000.0] } #large initial boundary intervals self['weights'] = { 'BNE1': 'DISTANCE', 'BNE2': 'DISTANCE', 'BNE3': 'DISTANCE', 'TPER_RISE': 'DISTANCE', 'WRONG_WAY': 'DISTANCE' } #to multiply each link attribute value by self['median_compare'] = [ 'TURN' ] #extract these coefficients with others at their medians (must appear last in self['variables']) self['randomize_compare'] = [ ] #extract these coefficients with link randomization (must appear last in self['variables']) """generate noisy output?""" self['verbose'] = True """speed up by randomizing whole network in outer loop and performing searches in inner loop using only comparisons/additions""" self['inverted'] = True # should we? self[ 'inverted_N_attr'] = 4 # when link attributes were randomized individually, this controlled the number of link randomizations, now just set it to the number of processors self[ 'inverted_N_param'] = 5 # when link attributes were randomized individually, this controlled the number of parameters to draw per link randomization, now just set it to the number of parameters desired divided by the number of processors (e.g. w/; N_attr=4 processors x N_param=5 == 20 random parameters) self[ 'inverted_nested'] = False # when link attributes were randomized individually, True would nest the attribute and parameter randomization loops, now just leave set to False """link randomization parameters""" self[ 'randomize_after'] = True # apply link randomization after generalized cost is calcluated rather than to attributes individually? Leave set to True. self[ 'randomize_after_dev'] = 0.4 # link randomization scale parameter self[ 'randomize_after_iters'] = 3 # number of link randomizations per coefficient (e.g. 20 random parameters x 3 randomize_after_iters == 60 max choice set size) """refrain from filtering out routes that overlap too much with chosen route (used to analyze choice set quality)""" self['allow_duplicates_of_chosen_route'] = False """deprecated""" #parameters used to randomize link attributes individually self['randomizer_fun'] = BetaUnifRandomizer beta_scl = 0.2 unif_dev = 0.4 self['randomizer_args'] = (2, unif_dev, beta_scl) self['no_randomize'] = ['WRONG_WAY', 'TURN'] #number of generalized cost coefficients to draw if not using inverted loops self['ds_num_draws'] = 32 #link randomizer optimization parameters self['optim_sample_size'] = 200 self['optim_kappa_vals'] = [0.2, 0.25] self['optim_sigma_vals'] = [0.4, 0.5] for key in changes: self[key] = changes[key]
def __init__(self, initdict=None): UserDict.__init__(self, initdict)
def __init__(self, changes={}): UserDict.__init__(self) self[ 'data_dir'] = r"X:\Projects\BikeModel\data\bike_model\input\network\2010_06_08" self['link_file'] = os.path.join(self['data_dir'], 'links.csv') self['node_file'] = os.path.join(self['data_dir'], 'nodes.csv') self['dist_var'] = 'DISTANCE' self[ 'dist_scl'] = 1 / 5280 #rescales with node distance x dist_scl= link distance self['max_centroid'] = 2454 self['exclude_group'] = { 'FT': ('in', [1, 2, 101, 102]), 'MTYPE_NUM': ('==', 0) } self['use_dual'] = True self['perform_transformation'] = True self['create_ww_links'] = True self['ww_exist_alias'] = ('ONEWAY', 'WRONG_WAY') self['ww_change'] = { 'FT': ('+', 100), 'BIKE_CLASS': ('*', 0), 'PER_RISE': ('*', -1) } self['variable_transforms'] = { 'MTYPE_NUM': ('MTYPE', { 'SF': 1, 'MTC': 0 }, ""), 'B0': ('BIKE_CLASS', { 0: 1, 1: 0, 2: 0, 3: 0 }, "int"), 'B1': ('BIKE_CLASS', { 0: 0, 1: 1, 2: 0, 3: 0 }, "int"), 'B2': ('BIKE_CLASS', { 0: 0, 1: 0, 2: 1, 3: 0 }, "int"), 'B3': ('BIKE_CLASS', { 0: 0, 1: 0, 2: 0, 3: 1 }, "int"), 'BNE1': ('BIKE_CLASS', { 0: 1, 1: 0, 2: 1, 3: 1 }, "int"), 'BNE2': ('BIKE_CLASS', { 0: 1, 1: 1, 2: 0, 3: 1 }, "int"), 'BNE3': ('BIKE_CLASS', { 0: 1, 1: 1, 2: 1, 3: 0 }, "int"), 'TPER_RISE': ('PER_RISE', ('max', 0), "float") } self['relevant_variables'] = [ 'DISTANCE', 'FT', 'MTYPE_NUM', 'TPER_RISE', 'WRONG_WAY', 'B0', 'B1', 'B2', 'B3', 'BNE1', 'BNE2', 'BNE3' ] for key in changes: self[key] = changes[key]
def __setitem__(self, key, item): if key not in self.allkeys: self.allkeys.append(key) UserDict.__setitem__(self, key, item)
def __getitem__(self, key): try: return UserDict.__getitem__(self, key) except KeyError, e: return key
def __init__(self, *args, **kwargs): super(AcquisitionAwareDict, self).__init__() UserDict.__init__(self, *args, **kwargs)
def __init__(self, config_fp): from gip_common import _Constants UserDict.__init__(self, dict=None) self.constants = _Constants() self.digest(config_fp)
def test_set_from_member(self): a = UserDict() a['first'] = 1 a['second'] = 2 inline_tools.inline('a["first"] = a["second"];', ['a']) assert_equal(a['first'], a['second'])
def __delitem__(self, key): self.allkeys.remove(key) UserDict.__delitem__(self, key)
def __init__(self, filename=None): UserDict.__init__(self) self['name'] = filename
def __new__(cls): return UserDict()
import urllib u = urllib.urlopen ('http://*****:*****@eracks733:8080/eRacks/compile') print u.read() #if find (u.read(), 'compiled OK'): # print 'OK' u.close() from UserDict import UserDict class Req (UserDict): form = {} slf = UserDict() # {} req = Req() req.data = {'name':'joe', 'email':'safasdf' } #req.__dict__ = {'name':'joe', 'email':'safasdf', 'form' : {} } # req.data #print `orglist` for f in orglist: # .values(): #req [f.name] = '' req [f[1]] = '' for f in paylist: req [f[1]] = '' req ['password'] = '******' req ['password2'] = 'wefvwefvwevwef'
def test_set_char(self): a = UserDict() inline_tools.inline('a["hello"] = 123.0;', ['a']) assert_equal(sys.getrefcount(a["hello"]), 2) assert_equal(a["hello"], 123.0)
def __setitem__(self, key, value): if not self.has_key(key): self._order.append(key) UserDict.__setitem__(self, key, value)
def __init__(self, name, data = {}): UserDict.__init__(self, data) self.name = name
from UserDict import UserDict from libcloud.storage.types import Provider Provider_Dict = UserDict() Provider_Dict["Dummy Storage Provider"] = Provider.DUMMY Provider_Dict["CloudFiles (US)"] = Provider.CLOUDFILES_US Provider_Dict["CloudFiles (UK)"] = Provider.CLOUDFILES_UK Provider_Dict["Amazon S3 (standard)"] = Provider.S3 Provider_Dict["Amazon S3 (us-west-1)"] = Provider.S3_US_WEST Provider_Dict["Amazon S3 (us-west-2)"] = Provider.S3_US_WEST_OREGON Provider_Dict["Amazon S3 (eu-west-1)"] = Provider.S3_EU_WEST Provider_Dict["Amazon S3 (ap-southeast-1)"] = Provider.S3_AP_SOUTHEAST Provider_Dict["Amazon S3 (ap-northeast-1)"] = Provider.S3_AP_NORTHEAST Provider_Dict["Ninefold"] = Provider.NINEFOLD Provider_Dict["Google Storage"] = Provider.GOOGLE_STORAGE Provider_Dict["Windows Azure Storage"] = Provider.WINDOWS_AZURE_STORAGE Provider_Dict["Aliyun Storage"] = Provider.ALIYUN_STORAGE def get_cloud_provider(provider_name): return Provider_Dict[provider_name]
def __delitem__(self, key): UserDict.__delitem__(self, key) self._order.remove(key)
def __setitem__(self, key, value): data = base64.b64encode(pickle.dumps(value)).decode('ascii') return UserDict.__setitem__(self, key, data)
def __init__(self, *args, **kwargs): UserDict.__init__(self, *args, **kwargs)
def __init__(self, client): self._client = client UserDict.__init__(self)
def __getitem__(self, key): data = UserDict.__getitem__(self, key) return pickle.loads(base64.b64decode(data.encode('ascii')))
def pop(self, path, default=None): value = UserDict.pop(self, path, default) if value.parent is not None: if value.parent in self: self.get(value.parent).del_child(value.metadata['id']) return value
def __init__(self, session): UserDict.__init__(self) self.data = session