def repr(self, format=''): s = self.srcObj.repr(format) o = self.orderObj.repr(format) msg = [] msg.append('%s, (%s), %s, %s, (%s)' % (self.type, s, typeset.anyDataToStr(self.pulseCount), typeset.anyDataToStr(self.maxAnalysisOrder), o)) #if format == 'argsOnly': # as string return ''.join(msg)
def repr(self, format=''): msg = [] msg.append('%s, %s, %s, %s, %s, %s, %s' % (self.type, self.rObj.repr('triple'), typeset.anyDataToStr(self.crossoverRate), typeset.anyDataToStr(self.mutationRate), typeset.anyDataToStr(self.percentElite), self.control, typeset.anyDataToStr(self.popSize))) if format == 'argsOnly': # if not off, doesnt add list of rhythms return ''.join(msg) msg.append('\n') for rObj in self.rObjBundle: # use rObj bundle to get lists of variations msg.append(self.LMARGIN + '%s' % rObj.repr('triple')) msg.append('\n') msg = msg[:-1] # chop off last return carriage return ''.join(msg)
def _reprWeightList(self, wList): """format a weight list for presentation""" # wList can be none: if wList == None: return None wStr = [] wList = self._sortSymbolLabel(wList) for s, w in wList: if w == 0: continue # skip zero weights wStr.append('%s%s%s' % (s, self.ASSIGN, typeset.anyDataToStr(w))) return self.ASSIGNDELIMIT.join(wStr)
def _scrubList(self, data, min=None, max=None): """for presenting list data used to apply scalar to uncalculated values""" msg = [] for element in data: if min != None and max != None: element = unit.denorm(element, min, max) msg.append(typeset.anyDataToStr(element)) dataStr = ','.join(msg) return '(%s)' % dataStr
def repr(self, format=''): msg = [] msg.append('%s, %s, %s, %s, (%s)' % (self.type, str(self.sieveObj), typeset.anyDataToStr(self.length), self.control, self.rthmObj.repr(format),)) if format == 'argsOnly': return ''.join(msg) # show sieve if not argsOnly msg.append('\n') msg.append(self.LMARGIN + '%s' % self._scrubList(self.sieveSeg)) return ''.join(msg)
def _reprDemo(self): # manually extractin acronym like this may produce # acronyms that are different than those defined in parameter.py? msg = ['%s' % drawer.acronymExtract(self.type)] # goes through each arg in the list of args for arg in self.argDefaults: raw = typeset.anyDataToStr(arg) # strip any extra quotes provided raw = raw.replace('\'', '') # will be a single quote msg.append(raw) return ', '.join(msg)
def repr(self, format=''): # why not use baesParameter representation methods here? msg = [] for name in self.argNames: if drawer.isList(self.switch(name)): msg.append('%s' % self._scrubList(self.switch(name))) else: msg.append('%s' % typeset.anyDataToStr(self.switch(name))) if format in ['argsOnly', '']: msg = [self.type,] + msg return ', '.join(msg) elif format in ['noType']: return ', '.join(msg)
def repr(self, format=''): g = self.gridRefObj.repr(format) s = self.stepGenObj.repr(format) p = self.pullObj.repr(format) return '%s, (%s), (%s), %s, (%s)' % ( self.type, g, s, typeset.anyDataToStr(self.stepCount), p)
def strongType(usrArgs, argTypes, defaultArgs=[], argCountOffset=0): """Argument checking tool. checks raw arg type and number, one level deep (does not recurse into list) will supply defaults if missing args after last given and self.defaultArgs defined two arguments required, both lists: args = a list of arguments, of proper python data types argTypes = list of one-level deap types, specified w/ strings 'list', 'num', 'float', 'int', 'str'; see drawer.py one optional args defaultArgs = list of default args to substitute returns: newArgs, ok, msg >>> strongType([[1,2,3]], ['list']) ([[1, 2, 3]], 1, '') >>> strongType([.5, 3, 'three'], ['float', 'int', 'str']) ([0.5, 3, 'three'], 1, '') >>> strongType([3.2], ['num', 'num']) ([3.2000...], 0, 'incorrect number of arguments; enter 2 arguments.') >>> strongType([3.2, 5, 6], ['num', 'num']) ([3.2000..., 5, 6], 0, 'too many arguments; enter 2 arguments.') """ argCount = len(argTypes) if len(usrArgs) < argCount: # try to get from defaults if len(defaultArgs) == argCount: # defaults exits (default is 0) for retrieve in defaultArgs[len(usrArgs):]: usrArgs.append(retrieve) # add missing to end #print 'argTools.py: adding default', retrieve, defaultArgs else: # nothing we can do: failure msg = ('incorrect number of arguments; enter %i arguments.' % (argCount + argCountOffset)) # add incase if name offset return usrArgs, 0, msg elif len(usrArgs) > argCount: #print _MOD, len(usrArgs), argCount msg = 'too many arguments; enter %i arguments.' % (argCount + argCountOffset) return usrArgs, 0, msg for pos in range(0, argCount): argTest = usrArgs[pos] # can be [list, num, float, int, str] typeCandidates = argTypes[pos] if not drawer.isList(typeCandidates): typeCandidates = [typeCandidates,] # add to list for type in typeCandidates: if type == 'list' and drawer.isList(argTest): match = 1 break elif type == 'num' and drawer.isNum(argTest): match = 1 break elif type == 'float' and drawer.isFloat(argTest): match = 1 break elif type == 'int' and drawer.isInt(argTest): match = 1 break elif type == 'str' and drawer.isStr(argTest): match = 1 break else: # dont break; need to through other possbilities match = 0 # should covnert types to better strings if match == 0: msg = ('wrong type of data used as an argument. replace %s with a %s argument type.' % (repr(typeset.anyDataToStr(argTest)), # provide 'or' to show that any type in candidate is good drawer.typeListAsStr(typeCandidates, 'or'))) return usrArgs, 0, msg # all good return usrArgs, 1, ''
def repr(self, format=''): g = self.gridRefObj.repr(format) s = self.stepGenObj.repr(format) p = self.pullObj.repr(format) return '%s, (%s), (%s), %s, (%s)' % (self.type, g, s, typeset.anyDataToStr(self.stepCount), p)
def strongType(usrArgs, argTypes, defaultArgs=[], argCountOffset=0): """Argument checking tool. checks raw arg type and number, one level deep (does not recurse into list) will supply defaults if missing args after last given and self.defaultArgs defined two arguments required, both lists: args = a list of arguments, of proper python data types argTypes = list of one-level deap types, specified w/ strings 'list', 'num', 'float', 'int', 'str'; see drawer.py one optional args defaultArgs = list of default args to substitute returns: newArgs, ok, msg >>> strongType([[1,2,3]], ['list']) ([[1, 2, 3]], 1, '') >>> strongType([.5, 3, 'three'], ['float', 'int', 'str']) ([0.5, 3, 'three'], 1, '') >>> strongType([3.2], ['num', 'num']) ([3.2000...], 0, 'incorrect number of arguments; enter 2 arguments.') >>> strongType([3.2, 5, 6], ['num', 'num']) ([3.2000..., 5, 6], 0, 'too many arguments; enter 2 arguments.') """ argCount = len(argTypes) if len(usrArgs) < argCount: # try to get from defaults if len(defaultArgs) == argCount: # defaults exits (default is 0) for retrieve in defaultArgs[len(usrArgs):]: usrArgs.append(retrieve) # add missing to end #print 'argTools.py: adding default', retrieve, defaultArgs else: # nothing we can do: failure msg = ('incorrect number of arguments; enter %i arguments.' % (argCount + argCountOffset)) # add incase if name offset return usrArgs, 0, msg elif len(usrArgs) > argCount: #print _MOD, len(usrArgs), argCount msg = 'too many arguments; enter %i arguments.' % (argCount + argCountOffset) return usrArgs, 0, msg for pos in range(0, argCount): argTest = usrArgs[pos] # can be [list, num, float, int, str] typeCandidates = argTypes[pos] if not drawer.isList(typeCandidates): typeCandidates = [ typeCandidates, ] # add to list for type in typeCandidates: if type == 'list' and drawer.isList(argTest): match = 1 break elif type == 'num' and drawer.isNum(argTest): match = 1 break elif type == 'float' and drawer.isFloat(argTest): match = 1 break elif type == 'int' and drawer.isInt(argTest): match = 1 break elif type == 'str' and drawer.isStr(argTest): match = 1 break else: # dont break; need to through other possbilities match = 0 # should covnert types to better strings if match == 0: msg = ( 'wrong type of data used as an argument. replace %s with a %s argument type.' % ( repr(typeset.anyDataToStr(argTest)), # provide 'or' to show that any type in candidate is good drawer.typeListAsStr(typeCandidates, 'or'))) return usrArgs, 0, msg # all good return usrArgs, 1, ''