def rank(self, sub): """ Returns the rank of sub as a subset of s of size k. EXAMPLES:: sage: Subsets(3,2).rank([1,2]) 0 sage: Subsets([2,3,4],2).rank([3,4]) 2 sage: Subsets([2,3,4],2).rank([2]) sage: Subsets([2,3,4],4).rank([2,3,4,5]) """ subset = Set(sub) lset = __builtin__.list(self.s) lsubset = __builtin__.list(subset) try: index_list = sorted(map(lambda x: lset.index(x), lsubset)) except ValueError: return None n = len(self.s) r = 0 if self.k not in range(len(self.s)+1): return None elif self.k != len(subset): return None else: return choose_nk.rank(index_list,n)
def rank(self, sub): """ Returns the rank of sub as a subset of s. EXAMPLES:: sage: Subsets(3).rank([]) 0 sage: Subsets(3).rank([1,2]) 4 sage: Subsets(3).rank([1,2,3]) 7 sage: Subsets(3).rank([2,3,4]) == None True """ subset = Set(sub) lset = __builtin__.list(self.s) lsubset = __builtin__.list(subset) try: index_list = sorted(map(lambda x: lset.index(x), lsubset)) except ValueError: return None n = len(self.s) r = 0 for i in range(len(index_list)): r += binomial(n,i) return r + choose_nk.rank(index_list,n)
def _determine_arguments(self, arguments): # # '''Determine right set of arguments for different method types.''' '''Avoid to add object or class references twice.''' if not self.arguments_determined: if self.method_type is builtins.classmethod: arguments = [self.class_object] + builtins.list(arguments) elif not (self.object is None or self.method_type is builtins.staticmethod): arguments = [self.object] + builtins.list(arguments) if self.wrapped_decorator is not None: self.wrapped_decorator.arguments_determined = True return builtins.tuple(arguments)
def __init__(self, db_connection, parent=None): self.pointList = list() self.selectionRectangle = QgsRectangle() self.connection = db_connection #====================================================================== # QT main window constructor # Super Constuctor for our Main Windows; the Parent window #====================================================================== super(OurMainWindow, self).__init__(parent) #====================================================================== # SetupUi from ui_main_window # Build the Main windows apparence and layout #====================================================================== self.setupUi(self) #====================================================================== # Create and add Child Widgets: # 1 - Tabulation #====================================================================== self.our_tab_view = OurTabWiew(self, self.connection) self.formLayout.addChildWidget(self.our_tab_view) #====================================================================== # Give Action to the main windows #====================================================================== self.setupAction_main()
def mergeIntervals(int1,int2): newinterval=interval('(0,0)') ls1=int1.Range() ls2=int2.Range() newls= list (set(ls1)&set(ls2)) if not newls : raise Exception('not valid') else: if int1.lo<=int2.lo: newinterval.lo=int1.lo newinterval.low_inclusive=int1.low_inclusive if int1.up<=int2.up: newinterval.up=int2.up newinterval.up_inclusive=int2.up_inclusive else: newinterval.up=int1.up newinterval.up_inclusive=int1.up_inclusive elif int1.lo>=int2.lo: newinterval.lo=int2.lo newinterval.lo_inclusive=int2.low_inclusive if int1.up<=int2.up: newinterval.up=int2.up newinterval.up_inclusive=int2.up_inclusive else: newinterval.up=int1.up newinterval.up_inclusive=int1.up_inclusive return newinterval
def cardinality(self): """ Returns the number of Lyndon words with the evaluation e. EXAMPLES:: sage: LyndonWords([]).cardinality() 0 sage: LyndonWords([2,2]).cardinality() 1 sage: LyndonWords([2,3,2]).cardinality() 30 Check to make sure that the count matches up with the number of Lyndon words generated. :: sage: comps = [[],[2,2],[3,2,7],[4,2]]+Compositions(4).list() sage: lws = [ LyndonWords(comp) for comp in comps] sage: all( [ lw.cardinality() == len(lw.list()) for lw in lws] ) True """ evaluation = self.e le = __builtin__.list(evaluation) if len(evaluation) == 0: return 0 n = sum(evaluation) return sum([moebius(j)*factorial(n/j) / prod([factorial(ni/j) for ni in evaluation]) for j in divisors(gcd(le))])/n
def onPerformDragOperation(self, sender): self.guiCursor.setDrawsBackground_(False) import __builtin__ try: filenames = __builtin__.list(sender.draggingPasteboard().propertyListForType_(AppKit.NSFilenamesPboardType)) filenames = map(convertToUnicode, filenames) index = self.index internalDragCallback = getattr(sender.draggingSource(), "onInternalDrag", None) def doDragHandler(): control.attr.dragHandler( control.parent.subjectObject, control.subjectObject, index, filenames) if internalDragCallback: do_in_mainthread(lambda: internalDragCallback( control, index, filenames), wait=False) utils.daemonThreadCall(doDragHandler, name="DragHandler") return True except: sys.excepthook(*sys.exc_info()) return False
def less(s, t): """ Returns True if s < t otherwise it returns False. EXAMPLES:: sage: z = SetPartitions(3).list() sage: sage.combinat.set_partition.less(z[0], z[1]) False sage: sage.combinat.set_partition.less(z[4], z[1]) True sage: sage.combinat.set_partition.less(z[4], z[0]) True sage: sage.combinat.set_partition.less(z[3], z[0]) True sage: sage.combinat.set_partition.less(z[2], z[0]) True sage: sage.combinat.set_partition.less(z[1], z[0]) True sage: sage.combinat.set_partition.less(z[0], z[0]) False """ if _union(s) != _union(t): raise ValueError, "cannot compare partitions of different sets" if s == t: return False for p in s: f = lambda z: z.intersection(p) != Set([]) if len(filter(f, __builtin__.list(t)) ) != 1: return False return True
def _listbloc(n, nbrepets, listint=None): """ listbloc decomposes a set of n\*nbrepets integers (the list listint) in nbrepets parts. It is used in the algorithm to generate all set partitions. Not to be called by the user. EXAMPLES:: sage: list(sage.combinat.set_partition._listbloc(2,1)) [{{1, 2}}] sage: l = [Set([Set([3, 4]), Set([1, 2])]), Set([Set([2, 4]), Set([1, 3])]), Set([Set([2, 3]), Set([1, 4])])] sage: list(sage.combinat.set_partition._listbloc(2,2,[1,2,3,4])) == l True """ if isinstance(listint, (int, sage.rings.integer.Integer)) or listint is None: listint = Set(range(1,n+1)) if nbrepets == 1: yield Set([listint]) return l = __builtin__.list(listint) l.sort() smallest = Set(l[:1]) new_listint = Set(l[1:]) f = lambda u, v: u.union(_set_union([smallest,v])) for ssens in subset.Subsets(new_listint, n-1): for z in _listbloc(n, nbrepets-1, new_listint-ssens): yield f(z,ssens)
def calculate_fitness_population(self): threads = list() for i in range(len(self.__population)): t = threading.Thread(target=self.calculate_fitness , args=(i,)) threads.append(t) t.start() t.join()
def hidepass(url): from urlparse import urlsplit, urlunsplit from __builtin__ import list l = list(urlsplit(url)) s = l[1].rsplit('@', 1) if len(s) == 2: l[1] = "%s:-password-@%s" % (s[0].split(':', 1)[0], s[1]) return urlunsplit(l)
def standard_form(sp): """ Returns the set partition as a list of lists. EXAMPLES:: sage: map(sage.combinat.set_partition.standard_form, SetPartitions(4, [2,2])) [[[3, 4], [1, 2]], [[2, 4], [1, 3]], [[2, 3], [1, 4]]] """ return [__builtin__.list(x) for x in sp]
def clone(ui, source, dest=None, *subtreeargs, **opts): '''copy one or more existing repositories to create a tree''' global hg_clone if not hg_clone: hg_clone = compatible_clone() if subtreeargs: s = __builtin__.list(subtreeargs) s.extend(opts.get('subtrees')) # Note: extend does not return a value opts['subtrees'] = s if dest is None: dest = hg.defaultdest(source) _clone(ui, source, dest, opts, opts.get('skiproot')) return 0
def cruce_2punto_paralelo(self): posiciones = [] for i in range(len(self.__population)): posiciones.append(i) shuffle(posiciones) threads = list() i = 0 while i < len(posiciones): t = threading.Thread(target=self.crossover2points, args=(posiciones[i], posiciones[i+1],)) threads.append(t) t.start() t.join() i+=2
def list(module_name, deep=False): u"""List module names and method signatures (within a given module). Arguments: * module_name (string) -- full (absolute) name of a particular module, e.g. '', 'system', 'module.some.other'; * deep (bool) -- if set to True, list all submodules/methods recursively (from all the subtree, not only direct children). Result: a list of names/signatures (strings). """ return __builtin__.list(_iter_signatures(module_name, deep))
def random_element(self): """ Returns a random element of the class of subsets of s (in other words, a random subset of s). EXAMPLES:: sage: Subsets(3).random_element() {2} sage: Subsets([4,5,6]).random_element() {5} """ lset = __builtin__.list(self.s) n = len(self.s) return Set(filter(lambda x: rnd.randint(0,1), lset))
def help(name, deep=False): u"""List module/method help-texts, i.e signatures + docstrings. Arguments: * name (string) -- full (absolute) name of a module or method, e.g. '', 'system', 'module.some.other' (if it is name of a method only the method's help-text is returned); * deep (bool) -- if set to True, walk through all submodules/methods recursively (from all the subtree, not only direct children). Result: a list of help-texts (strings). """ return __builtin__.list(_iter_help_texts(name, deep))
def command(ui, repo, cmd, *args, **opts): """Run a command in each repo in the tree. Change directory to the root of each repo and run the command. The command is executed directly (i.e., not using a shell), so if i/o redirection or other shell features are desired, include the shell invocation in the command, e.g.: hg tcommand -- sh -c 'ls -l > ls.out' Mercurial parses all arguments that start with a dash, including those that follow the command name, which usually results in an error. Prevent this by using '--' before the command or arguments, e.g.: hg tcommand -- ls -l""" _checklocal(repo) l = __builtin__.list((cmd,) + args) return _command(ui, repo, l, opts.get('stop'), opts)
def extsetup(ui = None): # The cmdtable is initialized here to pick up options added by other # extensions (e.g., rebase, bookmarks). # # Commands tagged with '^' are listed by 'hg help'. global defpath_mod defpath_mod = None defpath_opts = [] try: defpath_mod = extensions.find('defpath') defpath_opts = __builtin__.list(defpath_mod.opts) + subtreesopts defpath_doc = getattr(defpath_mod, 'common_docstring', '') if defpath_doc: defpath.__doc__ += defpath_doc except: pass global cmdtable cmdtable = { '^tclone': _newcte('clone', clone, cloneopts, _('[OPTION]... SOURCE [DEST [SUBTREE]...]')), 'tcommand|tcmd': (command, commandopts, _('command [arg] ...')), 'tcommit|tci': _newcte('commit', commit, subtreesopts), 'tconfig': (config, configopts, _('[OPTION]... [SUBTREE]...')), 'tdiff': _newcte('diff', diff, subtreesopts), 'theads': _newcte('heads', heads, subtreesopts), 'tincoming': _newcte('incoming', incoming, subtreesopts), 'toutgoing': _newcte('outgoing', outgoing, subtreesopts), 'tlist': (list, listopts, _('[OPTION]...')), '^tlog|thistory': _newcte('log', log, subtreesopts), 'tmerge': _newcte('merge', merge, subtreesopts), 'tparents': _newcte('parents', parents, subtreesopts), 'tpaths': _newcte('paths', paths, subtreesopts), '^tpull': _newcte('pull', pull, subtreesopts), '^tpush': _newcte('push', push, subtreesopts), '^tstatus': _newcte('status', status, subtreesopts), '^tupdate': _newcte('update', update, subtreesopts), 'ttag': _newcte('tag', tag, subtreesopts), 'ttip': _newcte('tip', tip, subtreesopts), 'tversion': (version, [], ''), 'tdebugkeys': (debugkeys, namespaceopt, '') } if defpath_mod: cmdtable['tdefpath'] = (defpath, defpath_opts, _('')) if getattr(commands, 'summary', None): cmdtable['tsummary'] = _newcte('summary', summary, subtreesopts)
def doInitialFill(): with list.lock: import __builtin__ listCopy = __builtin__.list(list) control.guiObjectList = [] Step = 5 def doInitialAddSome(iStart): for i in range(iStart, min(len(listCopy), iStart + Step)): control.guiObjectList += [buildControlForIndex(i, listCopy[i])] updater.update() for i in xrange(0, len(listCopy), Step): do_in_mainthread(lambda: doInitialAddSome(i), wait=True) def list_onInsert(index, value): control.guiObjectList.insert(index, buildControlForIndex(index, value)) updater.update() def list_onRemove(index): control.guiObjectList[index].obsolete = True control.guiObjectList[index].nativeGuiObject.removeFromSuperview() del control.guiObjectList[index] updater.update() def list_onClear(): for subCtr in control.guiObjectList: subCtr.nativeGuiObject.removeFromSuperview() subCtr.obsolete = True del control.guiObjectList[:] updater.update() for ev in ["onInsert", "onRemove", "onClear"]: f = locals()["list_" + ev] def wrap(f=f, ev=ev): def handler(*args): if control.select: getattr(control.select, ev)(*args) f(*args) return lambda *args: do_in_mainthread(lambda: handler(*args), wait=False) setattr(list, ev, wrap())
def ch_reducer(jids): c = cloud._getcloud() res = getattr( c, '_Cloud__iresult' ) all_map_results_it = res(jids, by_jid=True) if hasattr(itertools.chain, 'from_iterable'): #Python2.6+ flattened_map_results = itertools.chain.from_iterable(all_map_results_it) else: flattened_map_results = (map_result for map_result in all_map_results_it) red = reducer( flattened_map_results ) if not hasattr(red, '__iter__'): raise Exception('reducer is not an iterable') final_result = __builtin__.list( red ) #must return list for it to be serializable return final_result
def list(ap='.',r=False,type='',t='',d=False,dir=False,f=False,file=False): '''Parms:boll r recursion str (type,t) '(d,f,a,r)' default return all''' # print ap if dir:d=True if file:f=True if t and not type:type=t if 'd' in type:d=True if 'f' in type:f=True if 'a' in type:d=True;f=True if 'r' in type:r=True if d or dir or f or file:pass else:d=f=True #default return all if py.type(ap)!=py.type('') or py.len(ap)<1:ap='.' # if len(ap)==2 and ap.endswith(':'):ap+='/' if not U.inMuti(ap,'/','\\',f=str.endswith):ap+='/' # print ap # U.repl() ########## below r is result rls=[] try:r3=py.list(_os.walk(ap).next()) except Exception as ew: # print ap;raise ew return [] if ap=='./':ap='' # U.repl() r3[1]=[ap+i for i in r3[1]] r3[2]=[ap+i for i in r3[2]] if d:rls.extend(r3[1]) # if r: for i in r3[1]:rls.extend(list(i,r=r,d=d,f=f)) if f:rls.extend(r3[2]) return rls
def last(self): """ Returns the last subset of s of size k. EXAMPLES:: sage: Subsets(Set([1,2,3]), 2).last() {2, 3} sage: Subsets([1,2,3,3], 2).last() {2, 3} sage: Subsets(3,2).last() {2, 3} sage: Subsets(3,4).last() """ if self.k not in range(len(self.s)+1): return None else: return Set(__builtin__.list(self.s)[-self.k:])
def sup(s,t): """ Returns the supremum of the two set partitions s and t. EXAMPLES:: sage: sp1 = Set([Set([2,3,4]),Set([1])]) sage: sp2 = Set([Set([1,3]), Set([2,4])]) sage: s = Set([ Set([1,2,3,4]) ]) sage: sage.combinat.set_partition.sup(sp1, sp2) == s True """ res = s for p in t: inters = Set(filter(lambda x: x.intersection(p) != Set([]), __builtin__.list(res))) res = res.difference(inters).union(_set_union(inters)) return res
def historical_members(request): if request.GET.has_key('date'): form = forms.HistoricalMembersForm(request.GET) if not form.is_valid(): return HttpResponse("Please enter in a valid date") date = str(form.cleaned_data.get('date')) query = "SELECT * from membership_member where date_joined <= '" + date + "' AND (date_departed is null and (member_owner_equity_held>0 OR membership_fund_equity_held>0) OR (date_departed > '" + date + "' AND id in (SELECT DISTINCT member_id FROM accounting_transaction WHERE purchase_type='O' AND purchase_amount>0))" members = m_models.Member.objects.raw(query) member_count = len(__builtin__.list(members)) else: form = forms.HistoricalMembersForm() return render_to_response('reporting/historical_members.html', locals(), context_instance=RequestContext(request))
def random_element(self): """ Returns a random element of the class of subsets of s of size k (in other words, a random subset of s of size k). EXAMPLES:: sage: Subsets(3, 2).random_element() {1, 2} sage: Subsets(3,4).random_element() is None True """ lset = __builtin__.list(self.s) n = len(self.s) if self.k not in range(len(self.s)+1): return None else: return Set([lset[i] for i in choose_nk.ChooseNK(n, self.k).random_element()])
def sup(s, t): """ Returns the supremum of the two set partitions s and t. EXAMPLES:: sage: sp1 = Set([Set([2,3,4]),Set([1])]) sage: sp2 = Set([Set([1,3]), Set([2,4])]) sage: s = Set([ Set([1,2,3,4]) ]) sage: sage.combinat.set_partition.sup(sp1, sp2) == s True """ res = s for p in t: inters = Set( filter(lambda x: x.intersection(p) != Set([]), __builtin__.list(res))) res = res.difference(inters).union(_set_union(inters)) return res
def __iter__(self): """ Iterates through the subsets of s. EXAMPLES:: sage: [sub for sub in Subsets(Set([1,2,3]))] [{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}] sage: [sub for sub in Subsets(3)] [{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}] sage: [sub for sub in Subsets([1,2,3,3])] [{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}] """ lset = __builtin__.list(self.s) #We use the iterator for the subwords of range(len(self.s)) ind_set = lambda index_list: Set([lset[i] for i in index_list]) it = itertools.imap(ind_set, subword.Subwords(range(len(lset)))) for sub in it: yield sub
def setRectangle(self, point, button): if (len(self.pointList) < 2): # print "ajouter un point" self.pointList.append(QgsPoint(point)) print len(self.pointList) if (len(self.pointList) == 2): selection_rectangle = QgsRectangle( self.pointList[0], self.pointList[1]) # print selection_rectangle.asWktCoordinates(), # selection_rectangle.asPolygon() print selection_rectangle.width() self.pointList = list() # True = a polygon r = QgsRubberBand(self.our_tab_view.getTabMapCanvas(), True) r.setWidth(3) r.setToGeometry(QgsGeometry.fromRect(selection_rectangle), None) return selection_rectangle
def __iter__(self): """ Iterates through the subsets of s of size k. EXAMPLES:: sage: [sub for sub in Subsets(Set([1,2,3]), 2)] [{1, 2}, {1, 3}, {2, 3}] sage: [sub for sub in Subsets([1,2,3,3], 2)] [{1, 2}, {1, 3}, {2, 3}] sage: [sub for sub in Subsets(3,2)] [{1, 2}, {1, 3}, {2, 3}] """ if self.k not in range(len(self.s)+1): return lset = __builtin__.list(self.s) #We use the iterator for the subwords of range(len(self.s)) ind_set = lambda index_list: Set([lset[i] for i in index_list]) for sub in choose_nk.ChooseNK(len(lset),self.k): yield ind_set(sub)
def by(self, **type): '''Return the member with the specified ``name``.''' searchstring = ', '.join("{:s}={!r}".format(k, v) for k, v in type.iteritems()) res = __builtin__.list(self.iterate(**type)) if len(res) > 1: map(logging.info, (("[{:d}] {:x}:+{:x} '{:s}' {!r}".format( m.index, m.offset, m.size, m.name, m.type)) for m in res)) logging.warn( "{:s}.instance({:s}).members.by({:s}) : Found {:d} matching results, returning the first one. : [{:d}] {:x}:+{:x} '{:s}' {!r}" .format(__name__, self.owner.name, searchstring, len(res), res[0].index, res[0].offset, res[0].size, res[0].fullname, res[0].type)) res = next(iter(res), None) if res is None: raise LookupError( "{:s}.instance({:s}).members.by({:s}) : Found 0 matching results." .format(__name__, self.owner.name, searchstring)) return res
def __init__(self,list,dtype=None): ''' Parameters ---------- list : iterable List of FITS file paths load() method refer this list to load FITS file. Whether path like object is supported depends on the version of Python and Astropy. dtype : str or dtype, default None dtype of cupy.ndarray If None, this value will be usually "float32", but this can be changed with eclair.set_dtype. ''' self.list = builtins.list(list) self.dtype = judge_dtype(dtype) self.slices = dict(x_start=0,x_stop=None,y_start=0,y_stop=None) self.header = [None] * len(list) self.data = self.header[:]
def unrank(self, r): """ Returns the subset of s that has rank k. EXAMPLES:: sage: Subsets(3,2).unrank(0) {1, 2} sage: Subsets([2,4,5],2).unrank(0) {2, 4} """ lset = __builtin__.list(self.s) n = len(lset) if self.k not in range(len(self.s)+1): return None elif r >= self.cardinality() or r < 0: return None else: return Set([lset[i] for i in choose_nk.from_rank(r, n, self.k)])
def unrank(self, r): """ Returns the subset of s that has rank k. EXAMPLES:: sage: Subsets(3,2).unrank(0) {1, 2} sage: Subsets([2,4,5],2).unrank(0) {2, 4} """ lset = __builtin__.list(self.s) n = len(lset) if self.k not in range(len(self.s) + 1): return None elif r >= self.cardinality() or r < 0: return None else: return Set([lset[i] for i in choose_nk.from_rank(r, n, self.k)])
def __iter__(self): """ Iterates through the subsets of s of size k. EXAMPLES:: sage: [sub for sub in Subsets(Set([1,2,3]), 2)] [{1, 2}, {1, 3}, {2, 3}] sage: [sub for sub in Subsets([1,2,3,3], 2)] [{1, 2}, {1, 3}, {2, 3}] sage: [sub for sub in Subsets(3,2)] [{1, 2}, {1, 3}, {2, 3}] """ if self.k not in range(len(self.s) + 1): return lset = __builtin__.list(self.s) #We use the iterator for the subwords of range(len(self.s)) ind_set = lambda index_list: Set([lset[i] for i in index_list]) for sub in choose_nk.ChooseNK(len(lset), self.k): yield ind_set(sub)
def random_element(self): """ Returns a random element of the class of subsets of s of size k (in other words, a random subset of s of size k). EXAMPLES:: sage: Subsets(3, 2).random_element() {1, 2} sage: Subsets(3,4).random_element() is None True """ lset = __builtin__.list(self.s) n = len(self.s) if self.k not in range(len(self.s) + 1): return None else: return Set([ lset[i] for i in choose_nk.ChooseNK(n, self.k).random_element() ])
def __iter__(self): """ An iterator for the elements in the cartesian product of the iterables \*iters. From Recipe 19.9 in the Python Cookbook by Alex Martelli and David Ascher. EXAMPLES:: sage: [e for e in CartesianProduct(range(3), range(3))] [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]] sage: [e for e in CartesianProduct('dog', 'cat')] [['d', 'c'], ['d', 'a'], ['d', 't'], ['o', 'c'], ['o', 'a'], ['o', 't'], ['g', 'c'], ['g', 'a'], ['g', 't']] """ # visualize an odometer, with "wheels" displaying "digits"...: wheels = map(iter, self.iters) digits = [it.next() for it in wheels] while True: yield __builtin__.list(digits) for i in range(len(digits)-1, -1, -1): try: digits[i] = wheels[i].next() break except StopIteration: wheels[i] = iter(self.iters[i]) digits[i] = wheels[i].next() else: break
def getRow2CallSet(array_idx, variants, nVariants, metadb): """ Returns a dictionary that maps the row ids to the tuple (call set Id, call set GUID, call set name) """ tile_rows = list() for i in range(0, nVariants): callcount = variants[i].contents.callcount CallArray = variants[i].contents.CallArray for j in range(0, callcount): tile_rows.append(long(CallArray[j].contents.id)) if len(tile_rows) == 0: return dict() # Fetch info from meta DBQuery results = metadb.tileRow2CallSet(array_idx, tile_rows) resultDict = dict() for r in results: resultDict[r[0]] = r[1:] del tile_rows del results return resultDict
def explain_missing_dlls(error_string): """ Returns a dict containing the missing DLLs as keys and lists containing the suggested packages containing the DLL as the values.""" missing_dlls = [] for line in error_string.split('\n'): match = re.match(r'(?i)^err:module:import_dll .*? (\w+\.\w{3})', line) if match: missing_dlls.append(match.groups()[0].lower()) missing_dlls = __builtin__.list(set(missing_dlls)) return_dict = {} # Figure out which packages we know contains the missing DLLs dll_packages = libraries.PACKAGES for dll in missing_dlls: packages_containing_dll = [ k for (k, v) in dll_packages.iteritems() if dll.lower() in v ] return_dict[dll.lower()] = packages_containing_dll return return_dict
def unrank(self, r): """ Returns the subset of s that has rank k. EXAMPLES:: sage: Subsets(3).unrank(0) {} sage: Subsets([2,4,5]).unrank(1) {2} """ lset = __builtin__.list(self.s) n = len(lset) if r >= self.cardinality() or r < 0: return None else: for k in range(n + 1): bin = binomial(n, k) if r >= bin: r = r - bin else: return Set([lset[i] for i in choose_nk.from_rank(r, n, k)])
def solve(): myXY = f_in.readline().split() C = float(myXY[0]) F = float(myXY[1]) X = float(myXY[2]) currentCookieSpeed = 2 collapsedTime = 0.0 isDone = False timeList = list() prevMin = 100000000000000000.0 prevmincounter = 0 while (not isDone): tmpVar = collapsedTime + X / currentCookieSpeed timeList.append(tmpVar) collapsedTime = collapsedTime + (C / currentCookieSpeed) currentCookieSpeed = currentCookieSpeed + F if (min(timeList) >= prevMin): if (prevmincounter == 4): return prevMin prevmincounter = prevmincounter + 1 else: prevMin = min(timeList) '''sorted(timeList, key=float, reverse=True)
def by(**type): """Search through all the segments within the database for a particular result. Search type can be identified by providing a named argument. like = glob match regex = regular expression selector = segment selector index = particular index name = specific segment name predicate = function predicate """ searchstring = ', '.join("{:s}={!r}".format(k,v) for k,v in type.iteritems()) res = __builtin__.list(iterate(**type)) if len(res) > 1: maxaddr = max(__builtin__.map(operator.attrgetter('endEA'), res) or [1]) caddr = math.ceil(math.log(maxaddr)/math.log(16)) __builtin__.map(logging.info, (("[{:d}] {:0{:d}x}:{:0{:d}x} {:s} {:+#x} sel:{:04x} flags:{:02x}".format(seg.index, seg.startEA, int(caddr), seg.endEA, int(caddr), idaapi.get_true_segm_name(seg), seg.size(), seg.sel, seg.flags)) for seg in res)) logging.warn("{:s}.by({:s}) : Found {:d} matching results, returning the first one. : [{:d}] {:0{:d}x}:{:0{:d}x} {:s} {:+#x}".format(__name__, searchstring, len(res), res[0].index, res[0].startEA, int(caddr), res[0].endEA, int(caddr), idaapi.get_true_segm_name(res[0]), res[0].size())) res = next(iter(res), None) if res is None: raise LookupError("{:s}.by({:s}) : Found 0 matching results.".format(__name__, searchstring)) return res
print(i) # If you wanna test something.. if 0 < maxdoc <= i: break sentence = [line.split()] dictionary.add_documents(sentence) i += 1 dictionary.filter_extremes() print("Extracting terms...") with open(path + 'terms.csv', 'wb') as out: csvw = csv.writer(out) for item in dictionary.items(): row = list() row.append(str(item[0])) row.append(item[1].encode('utf-8')) csvw.writerow(row) print("Writing word-sentence Matrix ... ") with open(path + 'bow.imat.txt', 'wb') as out: with open(corpus_path, "r") as corpus_file: csvw = csv.writer(out) i = 0 for line in corpus_file: sentence = line.split() bow = dictionary.doc2bow(sentence) for word in bow: csvw.writerow((word[0], i))
categories = {'food': food, 'price': price, 'place': place, 'service': service} def to_mongo_db(df, collection_name): records = json.loads(df.T.to_json()).values() db[collection_name].insert_many(records) print("Try loading model", 'time from start', (time.time() - start_time)) model = gensim.models.Word2Vec.load('new-all-rest.word2vec.model') word_vectors = model.wv del model print("Loaded model", 'time from start', (time.time() - start_time)) raw = list(db.yelp_reviews_terms_adj_noun_not_noun.find()) print("[Info] Total elements " + str(len(raw)), 'time from start', (time.time() - start_time)) review = pd.DataFrame(raw) print("[Info] Total elements " + str(len(review)), 'time from start', (time.time() - start_time)) def function_to_run(review): ret_list = [] for _, row in review.iterrows(): _scores_ = {} del row['_id'] tags = row['final'] if len(set(tags.keys())) > 0: for key in tags.keys():
def get_tfidf(seq): return Counter(seq) def sum_new(lis): sum_i = 0 for elem in lis: try: sum_i += float(elem) except: pass return sum_i word_sets = list(get_sets()) # In[43]: word_dictionary = {} word_count = 0 stop_words = stopwords.words('english') keep_list = ['not', 'no'] city = 'las_vegas' bus_type = 'restaurants' table = 'yelp_review_patterns_las_vagas_restaurant' tags = set(['JJ', 'JJR', 'JJS', 'NN', 'NNS', 'NNP', 'NNPS']) # In[44]: business = [
def projectrun(data_file, genes_list_file): print 'Starting [ ', print '\b' * 12, sys.stdout.flush() os.system("grep '^#' " + data_file + " > ./data_comments.vcf") os.system("grep -v '^#' " + data_file + " > ./data_body.vcf") os.system("grep '^#' " + genes_list_file + " > ./genes_comments.vcf") os.system("grep -v '^#' " + genes_list_file + " > ./genes_body.vcf") data = open('./data_body.vcf') genes_list = open('./genes_body.vcf') s_data = data.read() s_genes = genes_list.read() data.close() genes_list.close() s_genes_splitted = s_genes.split('\n') s_data_splitted = s_data.split('\n') genes_array_dominant = [] genes_values_dominant = [] genes_array_recessive = [] genes_values_recessive = [] for i in range(len(s_genes_splitted) - 1): line = s_genes_splitted[i].split('\t') if line[5] == 'AR': genes_array_recessive.append(line[0]) genes_values_recessive.append([]) elif line[5] == 'AD': genes_array_dominant.append(line[0]) genes_values_dominant.append([]) dominant_hash = { x: y for x, y in zip(genes_array_dominant, genes_values_dominant) } recessive_hash = { k: v for k, v in zip(genes_array_recessive, genes_values_recessive) } r = 0 for i in range(len(s_data_splitted) - 1): r += 1 if r % 1000 == 0: print '\b.', sys.stdout.flush() tab_splitted = s_data_splitted[i].split() # data splitted tabular if tab_splitted[9].split(':')[0] == '1/1': # Genotype ann_field = tab_splitted[7].split('ANN=')[1].split(';')[0].split( ',') #split the ANN field in the annotated file for ii in range( len(ann_field) ): # Outputs the IDs in the ANN field according to the criteria if (ann_field[ii].split('|')[2] == "HIGH") or (ann_field[ii].split('|')[2] == "MODERATE"): gene_string = ann_field[ii].split('|')[3] try: p = recessive_hash.keys().index(gene_string) recessive_hash.values()[p].append(i) except ValueError: continue elif tab_splitted[9].split(':')[0] == '0/1': ann_field = tab_splitted[7].split('ANN=')[1].split(';')[0].split( ',') #split the ANN field in the annotated file for ii in range( len(ann_field) ): # Outputs the IDs in the ANN field according to the criteria if (ann_field[ii].split('|')[2] == "HIGH") or (ann_field[ii].split('|')[2] == "MODERATE"): gene_string = ann_field[ii].split('|')[3] try: p = dominant_hash.keys().index(gene_string) dominant_hash.values()[p].append(i) except ValueError: continue i_d = 0 flag = 0 while flag == 0: if dominant_hash.values()[i_d] == []: string = dominant_hash.keys()[i_d] dominant_hash.pop(string, 0) else: string2 = dominant_hash.keys()[i_d] v = dominant_hash.values()[i_d] v = set(v) v = list(v) dominant_hash[string2] = v i_d += 1 try: u = dominant_hash.values()[i_d + 1] except IndexError: flag = 1 i_r = 0 flag = 0 while flag == 0: unique = [] if recessive_hash.values()[i_r] == []: string = recessive_hash.keys()[i_r] recessive_hash.pop(string, 0) else: string2 = recessive_hash.keys()[i_r] v = recessive_hash.values()[i_r] v = set(v) v = list(v) recessive_hash[string2] = v i_r += 1 try: u = recessive_hash.values()[i_r + 1] except IndexError: flag = 1 recessive_index = [] for i in range(len(recessive_hash)): for ii in range(len(recessive_hash.values()[i])): recessive_index.append(recessive_hash.values()[i][ii]) dominant_index = [] for i in range(len(dominant_hash)): for ii in range(len(dominant_hash.values()[i])): dominant_index.append(dominant_hash.values()[i][ii]) out_recessive = [] unique_rec = set(recessive_index) unique_rec = list(unique_rec) unique_rec = sorted(unique_rec) for i in range(len(unique_rec)): out_recessive.append(s_data_splitted[unique_rec[i]]) np.savetxt('./output_recessive1.vcf', out_recessive, delimiter=" ", fmt="%s") os.system( "cat ./data_comments.vcf ./output_recessive1.vcf > ./output_recessive.vcf" ) out_dominant = [] unique_dom = set(dominant_index) unique_dom = list(unique_dom) unique_dom = sorted(unique_dom) for i in range(len(unique_dom)): out_dominant.append(s_data_splitted[unique_dom[i]]) np.savetxt('./output_dominant1.vcf', out_dominant, delimiter=" ", fmt="%s") os.system( "cat ./data_comments.vcf ./output_dominant1.vcf > ./output_dominant.vcf" ) compound_het = [] compound_het_genes = [] for i in range(len(recessive_hash)): if len(recessive_hash.values()[i]) >= 2: compound_het_genes.append(recessive_hash.keys()[i]) for ii in range(len(recessive_hash.values()[i])): compound_het.append( s_data_splitted[recessive_hash.values()[i][ii]]) np.savetxt('./compound.het.data1.vcf', compound_het, delimiter=" ", fmt="%s") os.system( "cat ./data_comments.vcf ./compound.het.data1.vcf > ./compound.het.data.vcf" ) for i in range(len(compound_het_genes)): if i == 0: os.system("grep -w '^" + compound_het_genes[i] + "' " + genes_list_file + " > ./compound.het.genes1.vcf") else: os.system("grep -w '^" + compound_het_genes[i] + "' " + genes_list_file + " >> ./compound.het.genes1.vcf") os.system( "cat ./genes_comments.vcf ./compound.het.genes1.vcf > ./compound.het.genes.vcf" ) os.system( "rm ./data_comments.vcf ./genes_comments.vcf ./data_body.vcf ./genes_body.vcf ./output_dominant1.vcf ./output_recessive1.vcf ./compound.het.data1.vcf ./compound.het.genes1.vcf" ) print '\b] Done!',
def from_set_(report): lis = [] for keys in report.keys(): lis.append([list(set(keys)), report[keys]]) return lis
def nlp_analysis(business_id, mongo_connection): data_path = '/Users/hammadhaleem/Desktop/yelp-data-api/server/data/' print("Load data") model = cPickle.load(open(data_path + 'modeltempe.pkl')) ngram_counter = cPickle.load(open(data_path + 'ngram_countertempe.pkl')) model_classifier = model.coef_.toarray() feature_names = ngram_counter.get_feature_names() print("Loaded models", len(feature_names)) db = mongo_connection.db.yelp_reviews query = {'business_id': business_id} raw = list( db.find(query, { 'business_id': 1, 'text': 1, 'stars': 1, 'review_id': 1 })) for elem in raw: del elem['_id'] reviews_df = pd.DataFrame(raw) reviews_df = reviews_df.drop('_id', axis=1) reviews_df['tokens'] = reviews_df.text.apply(lambda x: token_ze(x)) reviews_df['text_tokens'] = reviews_df.tokens.apply(lambda x: ' '.join(x)) reviews_df['features'] = reviews_df.text_tokens.apply( lambda x: ngram_counter.transform([x])) reviews_df['predicted'] = reviews_df.features.apply( lambda x: model.predict(x)) reviews_df['indexes'] = reviews_df.features.apply( lambda x: list(x[0].indices)) print('[Info] feature shapes ', model_classifier[0].shape, list(model.classes_)) reviews_df['predicted'] = reviews_df.features.apply( lambda x: model.predict(x)) reviews_df['count'] = 1 reviews_df['feature_vars'] = reviews_df.indexes.apply( lambda x: _index_to_element(model_classifier[0], x)) reviews_df['coef_pos'] = reviews_df.feature_vars.apply( lambda x: assign_labels(x, 'pos')) reviews_df['coef_neg'] = reviews_df.feature_vars.apply( lambda x: assign_labels(x, 'neg')) df = reviews_df.groupby('business_id').agg({ 'coef_neg': sum_of_list, 'coef_pos': sum_of_list, 'count': sum, 'stars': np.mean, 'tfidf': sum_of_dict }).reset_index() df['coef_neg'] = df.coef_neg.apply( lambda x: sorted(x, key=operator.itemgetter(1), reverse=False)) df['coef_pos'] = df.coef_pos.apply( lambda x: sorted(x, key=operator.itemgetter(1), reverse=True)) df['coef_pos_1'] = df.coef_pos.apply(lambda x: sorted( split_n(x, 1), key=operator.itemgetter(1), reverse=True)) df['coef_neg_1'] = df.coef_neg.apply(lambda x: sorted( split_n(x, 1), key=operator.itemgetter(1), reverse=False)) df['coef_pos_2'] = df.coef_pos.apply(lambda x: sorted( split_n(x, 2), key=operator.itemgetter(1), reverse=True)) df['coef_neg_2'] = df.coef_neg.apply(lambda x: sorted( split_n(x, 2), key=operator.itemgetter(1), reverse=False)) return raw
def __init__(self, n, length=None, min_length=0, max_length=float('+inf'), floor=None, ceiling=None, min_part=0, max_part=float('+inf'), min_slope=float('-inf'), max_slope=float('+inf'), name=None, element_constructor=None, element_class=None, global_options=None): """ Initialize ``self``. TESTS:: sage: import sage.combinat.integer_list_old as integer_list sage: C = integer_list.IntegerListsLex(2, length=3) sage: C == loads(dumps(C)) True sage: C == loads(dumps(C)) # this did fail at some point, really! True sage: C is loads(dumps(C)) # todo: not implemented True sage: C.cardinality().parent() is ZZ True sage: TestSuite(C).run() """ stopgap( "The old implementation of IntegerListsLex does not allow for arbitrary input;" " non-allowed input can return wrong results," " please see the documentation for IntegerListsLex for details.", 17548) # Convert to float infinity from sage.rings.infinity import infinity if max_slope == infinity: max_slope = float('+inf') if min_slope == -infinity: min_slope = float('-inf') if max_length == infinity: max_length = float('inf') if max_part == infinity: max_part = float('+inf') if floor is None: self.floor_list = [] else: try: # Is ``floor`` an iterable? # Not ``floor[:]`` because we want ``self.floor_list`` # mutable, and applying [:] to a tuple gives a tuple. self.floor_list = __builtin__.list(floor) # Make sure the floor list will make the list satisfy the constraints if min_slope != float('-inf'): for i in range(1, len(self.floor_list)): self.floor_list[i] = max( self.floor_list[i], self.floor_list[i - 1] + min_slope) # Some input checking for i in range(1, len(self.floor_list)): if self.floor_list[i] - self.floor_list[i - 1] > max_slope: raise ValueError( "floor does not satisfy the max slope condition") if self.floor_list and min_part - self.floor_list[ -1] > max_slope: raise ValueError( "floor does not satisfy the max slope condition") except TypeError: self.floor = floor if ceiling is None: self.ceiling_list = [] else: try: # Is ``ceiling`` an iterable? self.ceiling_list = __builtin__.list(ceiling) # Make sure the ceiling list will make the list satisfy the constraints if max_slope != float('+inf'): for i in range(1, len(self.ceiling_list)): self.ceiling_list[i] = min( self.ceiling_list[i], self.ceiling_list[i - 1] + max_slope) # Some input checking for i in range(1, len(self.ceiling_list)): if self.ceiling_list[i] - self.ceiling_list[i - 1] < min_slope: raise ValueError( "ceiling does not satisfy the min slope condition") if self.ceiling_list and max_part - self.ceiling_list[ -1] < min_slope: raise ValueError( "ceiling does not satisfy the min slope condition") except TypeError: # ``ceiling`` is not an iterable. self.ceiling = ceiling if name is not None: self.rename(name) if n in ZZ: self.n = n self.n_range = [n] else: self.n_range = n if length is not None: min_length = length max_length = length self.min_length = min_length self.max_length = max_length self.min_part = min_part self.max_part = max_part # FIXME: the internal functions currently assume that floor and ceiling start at 1 # this is a workaround self.max_slope = max_slope self.min_slope = min_slope if element_constructor is not None: self._element_constructor_ = element_constructor if element_class is not None: self.Element = element_class if global_options is not None: self.global_options = global_options Parent.__init__(self, category=FiniteEnumeratedSets())
def main(): global gloClauses global globalvar clauses = [] propSymbols = set() model = {} filename = argv[1] jobs = "" if len(sys.argv) >= 5: jobs = argv[2] if (argv[3] == "T"): isPure = True else: isPure = False if (argv[4] == "T"): isUnit = True else: isUnit = False elif (len(sys.argv) == 4): if (argv[2] == "T"): isPure = True else: isPure = False if (argv[3] == "T"): isUnit = True else: isUnit = False file = open(filename, 'r') global totalIterations #out_file = open("output_resolution.txt",'w') length = 0 print "Initial Clauses:" for line in file: if line.strip() and not line[0] == "#": #sys.stdout.write("%s: %s" %(lineNum, line)) words = line.split() temp = Clause() length = 0 for word in words: tempWord = word.strip("-") if (tempWord == word): temp.clause_list[word] = "+" propSymbols.add(word) else: temp.clause_list[tempWord] = "-" propSymbols.add(tempWord) length += 1 temp.length = length print "%s: ( %s )" % (globalvar, temp.getList()) temp.index = globalvar globalvar += 1 clauses.append(temp) print "The Input Facts" if (jobs != Null): for job in jobs.split(): temp = Clause() temp.clause_list[job] = "+" temp.length = 1 temp.index = globalvar print "%s: ( %s )" % (globalvar, temp.getList()) globalvar += 1 clauses.append(temp) gloClauses = copy.deepcopy(clauses) print "Props: " + str(list(propSymbols)) print "------------------------" t, model = DPLL(clauses, propSymbols, model, isPure, isUnit) print model print "------------------------" print "Nodes Searched: %s" % totalIterations print "Full Solution" aTeam = [] for p, b in model.iteritems(): print "%s = %s" % (p, b) if (len(p) == 1 and b == True): aTeam.append(p) for prop in propSymbols: if (prop not in model): print " %s = True/False" % prop print "------------------------" sys.stdout.write("Agent Team: ") for a in aTeam: sys.stdout.write(a + " ")
def __init__(self, n, length=None, min_length=0, max_length=float('+inf'), floor=None, ceiling=None, min_part=0, max_part=float('+inf'), min_slope=float('-inf'), max_slope=float('+inf'), name=None, element_constructor=None, element_class=None, global_options=None): """ Initialize ``self``. TESTS:: sage: C = IntegerListsLex(2, length=3) sage: C == loads(dumps(C)) True sage: C == loads(dumps(C)) # this did fail at some point, really! True sage: C is loads(dumps(C)) # todo: not implemented True sage: C.cardinality().parent() is ZZ True sage: TestSuite(C).run() """ # Convert to float infinity from sage.rings.infinity import infinity if max_slope == infinity: max_slope = float('+inf') if min_slope == -infinity: min_slope = float('-inf') if max_length == infinity: max_length = float('inf') if max_part == infinity: max_part = float('+inf') if floor is None: self.floor_list = [] else: try: # Is ``floor`` an iterable? self.floor_list = __builtin__.list( floor) # not ``floor[:]`` because we want # ``self.floor_list`` mutable, and # applying [:] to a tuple gives a # tuple. # Make sure the floor list will make the list satisfy the constraints if max_slope != float('+inf'): for i in reversed(range(len(self.floor_list) - 1)): self.floor_list[i] = max( self.floor_list[i], self.floor_list[i + 1] - max_slope) if min_slope != float('-inf'): for i in range(1, len(self.floor_list)): self.floor_list[i] = max( self.floor_list[i], self.floor_list[i - 1] + min_slope) except TypeError: self.floor = floor if ceiling is None: self.ceiling_list = [] else: try: # Is ``ceiling`` an iterable? self.ceiling_list = __builtin__.list(ceiling) # Make sure the ceiling list will make the list satisfy the constraints if max_slope != float('+inf'): for i in range(1, len(self.ceiling_list)): self.ceiling_list[i] = min( self.ceiling_list[i], self.ceiling_list[i - 1] + max_slope) if min_slope != float('-inf'): for i in reversed(range(len(self.ceiling_list) - 1)): self.ceiling_list[i] = min( self.ceiling_list[i], self.ceiling_list[i + 1] - min_slope) except TypeError: # ``ceiling`` is not an iterable. self.ceiling = ceiling if length is not None: min_length = length max_length = length if name is not None: self.rename(name) if n in ZZ: self.n = n self.n_range = [n] else: self.n_range = n self.min_length = min_length self.max_length = max_length self.min_part = min_part self.max_part = max_part # FIXME: the internal functions currently assume that floor and ceiling start at 1 # this is a workaround self.max_slope = max_slope self.min_slope = min_slope if element_constructor is not None: self._element_constructor_ = element_constructor if element_class is not None: self.Element = element_class if global_options is not None: self.global_options = global_options Parent.__init__(self, category=FiniteEnumeratedSets())
def get_ngrams(token, number=2): return [' '.join(x) for x in list(set(ngrams(token, number)))]
def get_selected_words(dict_i): lis = list(dict_i.keys()) return lis
def list(n, min_length, max_length, floor, ceiling, min_slope, max_slope): """ .. WARNING:: THIS FUNCTION IS DEPRECATED! Use ``IntegersListsLex(...)`` instead. EXAMPLES:: sage: import sage.combinat.integer_list as integer_list sage: g = lambda x: lambda i: x sage: integer_list.list(0,0,infinity,g(1),g(infinity),0,infinity) [[]] sage: integer_list.list(0,0,infinity,g(1),g(infinity),0,0) [[]] sage: integer_list.list(0, 0, 0, g(1), g(infinity), 0, 0) [[]] sage: integer_list.list(0, 0, 0, g(0), g(infinity), 0, 0) [[]] sage: integer_list.list(0, 0, infinity, g(1), g(infinity), 0, infinity) [[]] sage: integer_list.list(1, 0, infinity, g(1), g(infinity), 0, infinity) [[1]] sage: integer_list.list(0, 1, infinity, g(1), g(infinity), 0, infinity) [] sage: integer_list.list(0, 1, infinity, g(0), g(infinity), 0, infinity) [[0]] sage: integer_list.list(3, 0, 2, g(0), g(infinity), -infinity, infinity) [[3], [2, 1], [1, 2], [0, 3]] sage: partitions = (0, infinity, g(0), g(infinity), -infinity, 0) sage: partitions_min_2 = (0, infinity, g(2), g(infinity), -infinity, 0) sage: compositions = (0, infinity, g(1), g(infinity), -infinity, infinity) sage: integer_vectors = lambda l: (l, l, g(0), g(infinity), -infinity, infinity) sage: lower_monomials = lambda c: (len(c), len(c), g(0), lambda i: c[i], -infinity, infinity) sage: upper_monomials = lambda c: (len(c), len(c), g(0), lambda i: c[i], -infinity, infinity) sage: constraints = (0, infinity, g(1), g(infinity), -1, 0) sage: integer_list.list(6, *partitions) [[6], [5, 1], [4, 2], [4, 1, 1], [3, 3], [3, 2, 1], [3, 1, 1, 1], [2, 2, 2], [2, 2, 1, 1], [2, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]] sage: integer_list.list(6, *constraints) [[6], [3, 3], [3, 2, 1], [2, 2, 2], [2, 2, 1, 1], [2, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]] sage: integer_list.list(1, *partitions_min_2) [] sage: integer_list.list(2, *partitions_min_2) [[2]] sage: integer_list.list(3, *partitions_min_2) [[3]] sage: integer_list.list(4, *partitions_min_2) [[4], [2, 2]] sage: integer_list.list(5, *partitions_min_2) [[5], [3, 2]] sage: integer_list.list(6, *partitions_min_2) [[6], [4, 2], [3, 3], [2, 2, 2]] sage: integer_list.list(7, *partitions_min_2) [[7], [5, 2], [4, 3], [3, 2, 2]] sage: integer_list.list(9, *partitions_min_2) [[9], [7, 2], [6, 3], [5, 4], [5, 2, 2], [4, 3, 2], [3, 3, 3], [3, 2, 2, 2]] sage: integer_list.list(10, *partitions_min_2) [[10], [8, 2], [7, 3], [6, 4], [6, 2, 2], [5, 5], [5, 3, 2], [4, 4, 2], [4, 3, 3], [4, 2, 2, 2], [3, 3, 2, 2], [2, 2, 2, 2, 2]] sage: integer_list.list(4, *compositions) [[4], [3, 1], [2, 2], [2, 1, 1], [1, 3], [1, 2, 1], [1, 1, 2], [1, 1, 1, 1]] """ #from sage.misc.superseded import deprecation #deprecation(13605, 'list(...) is deprecated. Use list(IntegerListLex(...) instead.') return __builtin__.list( iterator(n, min_length, max_length, floor, ceiling, min_slope, max_slope))
def list(): """ Return a list of glanceclient.v1.images.Image objects""" return __builtin__.list(glance().images.list())
def get(self): month_start, month_end = self._get_month() entries = self.session.query('user_id', 'date', 'time', 'late_count').from_statement(""" SELECT t.user_id as "user_id", t.date as "date", ( SELECT COALESCE(SUM(h.time), 0.0) FROM time_entry h WHERE h.user_id = t.user_id AND h.date = t.date AND h.deleted = FALSE ) as "time", ( SELECT COUNT(*) FROM time_entry s WHERE s.user_id = t.user_id AND s.date = t.date AND DATE(s.modified_ts) > s.date ) as "late_count" FROM time_entry t WHERE t.date >= :month_start AND t.date <= :month_end GROUP BY t.user_id, t.date; """).params(month_start=month_start, month_end=month_end) if not self.request.has_perm('view'): users = [self.request.user] # TODO do we need to constrain entries also? locations= { self.request.user.location: ('', 1) } else: users_w = User.query.filter(User.is_not_client()) \ .filter(User.is_active==True) \ .filter(User.location=='wroclaw') \ .order_by(User.freelancer, User.name) \ .all() users_p = User.query.filter(User.is_not_client()) \ .filter(User.is_active==True) \ .filter(User.location=='poznan') \ .order_by(User.freelancer, User.name) \ .all() locations = { 'wroclaw': [u'Wrocław', len(users_w)], 'poznan': [u'Poznań', len(users_p)], } locations[self.request.user.location][1] -= 1 if self.request.user.location == 'wroclaw': users = users_w users.extend(users_p) else: users = users_p users.extend(users_w) today = datetime.date.today() grouped = defaultdict(lambda: defaultdict(lambda: 0.0)) late = defaultdict(lambda: defaultdict(lambda: False)) sums = defaultdict(lambda: 0.0) daily_sums = defaultdict(lambda: 0.0) for user_id, date, time, late_count in entries: grouped[user_id][date] = time if date <= today: sums[user_id] += time daily_sums[date] += time late[user_id][date] = late_count > 0 holidays = Holiday.all() count_of_required_month_hours = {} count_of_required_hours_to_today = {} for user in users: sftw = user.start_full_time_work or datetime.date(1970, 1, 1) if sftw > month_end: start_work = datetime.date(today.year+10, 1, 1) elif sftw < month_start: start_work = month_start else: start_work = sftw count_of_required_month_hours[user.id] = h.get_working_days(start_work, month_end) * 8 count_of_required_hours_to_today[user.id] = h.get_working_days(start_work, today if today < month_end else month_end) * 8 # move current user to the front of the list current_user_index = None for i, user in enumerate(users): if user.id == self.request.user.id: current_user_index = i users.insert(0, users.pop(current_user_index)) return dict( entries=grouped, users=users, sums=sums, late=late, excuses=excuses.wrongtime(), daily_sums=daily_sums, monthly_sum=sum(daily_sums.values()), dates=__builtin__.list(dates_between(month_start, month_end)), is_holiday=lambda date: Holiday.is_holiday(date, holidays=holidays), month_start=month_start, prev_date=previous_month(month_start), next_date=next_month(month_start), today=today, count_of_required_month_hours=count_of_required_month_hours, count_of_required_hours_to_today=count_of_required_hours_to_today, locations=locations, )
def list(*args, **kwargs): return builtins.list(*args, **kwargs)
def get_ngrams(token, number=2): return list(set(ngrams(token, number)))
from __builtin__ import str from collections import Counter from nltk.corpus import stopwords from nltk.stem import PorterStemmer, WordNetLemmatizer from pymining import assocrules from pymining import itemmining from pymining import seqmining from pymongo import MongoClient port_stemmmer = PorterStemmer() word_net_lemmer = WordNetLemmatizer() client = MongoClient() db = client.yelp_comparative_analytics raw = list(db.yelp_reviews.find({})) print("[Info] Total elements " + str(len(raw))) reviews_df = pd.DataFrame(raw) word_dictionary = {} word_count = 0 stop_words = set(stopwords.words('english')) def combine_text(rows): lis = [] for row in set(rows): lis.append(row) return lis