def setupResults(sql, LIMIT=10): q = sqlparse.where2q(sql.where,RESTRICTABLES) try: q=eval(q) except Exception,e: LOG('Exception in setupResults():') LOG(e) return {}
def setupResults(sql, LIMIT=None, XSAMSvariant='working'): q = sqlparse.where2q(sql.where,RESTRICTABLES) try: q=eval(q) except Exception,e: LOG('Exception in setupResults():') LOG(e) return {}
def setupResults(sql, LIMIT=None, XSAMSvariant='working'): q = sqlparse.where2q(sql.where, RESTRICTABLES) try: q = eval(q) except Exception, e: LOG('Exception in setupResults():') LOG(e) return {}
def setupResults(sql): """ This function is always called by the software. """ # log the incoming query log.debug('sql input: %s'%sql) # convert the incoming sql to a correct django query syntax object # based on the RESTRICTABLES dictionary in dictionaries.py # (where2q is a helper function to do this for us). q = where2q(sql.where, dictionaries.RESTRICTABLES) try: q = eval(q) # test queryset syntax validity except: return {} #react_ds = RxnData.objects.filter(pk__in=(2,4,3862,3863,7975,7976)) react_ds = RxnData.objects.filter(q) # count the number of matches, make a simple trunkation if there are # too many (record the coverage in the returned header) nreacts=react_ds.count() log.debug('number of reaction data: %s'%nreacts) sources = Source.objects.filter(pk__in=set(react_ds.values_list('ref_id', flat=True))) nsources = sources.count() reacts = Reaction.objects.filter(pk__in=set(react_ds.values_list('reaction_id', flat=True))) species = Species.objects.filter(pk__in=reacts.values_list('species')) atoms = species.filter(type=1) molecules = species.filter(type=2) particles = species.filter(type=3) for rea in react_ds: rea.Reactants = rea.reaction.reactants.all() rea.Products = rea.reaction.products.all() log.debug('done setting up the QuerySets') # Create the header with some useful info. The key names here are # standardized and shouldn't be changed. headerinfo={\ 'COUNT-ATOMS':atoms.count(), 'COUNT-MOLECULES':molecules.count(), 'COUNT-COLLISIONS':nreacts, } # Return the data. The keynames are standardized. return {\ 'CollTrans':react_ds, 'Atoms':atoms, 'Molecules':molecules, #'Particles':particles, 'Sources':sources, 'HeaderInfo':headerinfo, #'Methods':methods #'Functions':functions }
def setupResults(sql, limit=1000): """ This function is always called by the software. """ # log the incoming query LOG(sql) # convert the incoming sql to a correct django query syntax object # based on the RESTRICTABLES dictionary in dictionaries.py # (where2q is a helper function to do this for us). q = where2q(sql.where, dictionaries.RESTRICTABLES) try: q = eval(q) # test queryset syntax validity except: return {} # We build a queryset of database matches on the Transision model # since through this model (in our example) we are be able to # reach all other models. Note that a queryset is actually not yet # hitting the database, making it very efficient. transs = models.Transition.objects.select_related(depth=2).filter(q) # count the number of matches, make a simple trunkation if there are # too many (record the coverage in the returned header) ntranss = transs.count() if limit < ntranss: transs = transs[:limit] percentage = '%.1f' % (float(limit) / ntranss * 100) else: percentage = None # Through the transition-matches, use our helper functions to extract # all the relevant database data for our query. sources = getRefs(transs) nsources = sources.count() species, nspecies, nstates = getSpeciesWithStates(transs) methods = getLifetimeMethods() # Create the header with some useful info. The key names here are # standardized and shouldn't be changed. headerinfo=CaselessDict({\ 'Truncated':percentage, 'COUNT-SOURCES':nsources, 'COUNT-species':nspecies, 'count-states':nstates, 'count-radiative':ntranss }) # Return the data. The keynames are standardized. return { 'RadTrans': transs, 'Atoms': species, 'Sources': sources, 'HeaderInfo': headerinfo, 'Methods': methods }
def setupResults(sql, limit=1000): """ This function is always called by the software. """ # log the incoming query LOG(sql) # convert the incoming sql to a correct django query syntax object # based on the RESTRICTABLES dictionary in dictionaries.py # (where2q is a helper function to do this for us). q = where2q(sql.where, dictionaries.RESTRICTABLES) try: q = eval(q) # test queryset syntax validity except: return {} # We build a queryset of database matches on the Transision model # since through this model (in our example) we are be able to # reach all other models. Note that a queryset is actually not yet # hitting the database, making it very efficient. transs = models.Transition.objects.select_related(depth=2).filter(q) # count the number of matches, make a simple trunkation if there are # too many (record the coverage in the returned header) ntranss=transs.count() if limit < ntranss : transs = transs[:limit] percentage='%.1f' % (float(limit) / ntranss * 100) else: percentage=None # Through the transition-matches, use our helper functions to extract # all the relevant database data for our query. sources = getRefs(transs) nsources = sources.count() species, nspecies, nstates = getSpeciesWithStates(transs) methods = getLifetimeMethods() # Create the header with some useful info. The key names here are # standardized and shouldn't be changed. headerinfo=CaselessDict({\ 'Truncated':percentage, 'COUNT-SOURCES':nsources, 'COUNT-species':nspecies, 'count-states':nstates, 'count-radiative':ntranss }) # Return the data. The keynames are standardized. return {'RadTrans':transs, 'Atoms':species, 'Sources':sources, 'HeaderInfo':headerinfo, 'Methods':methods #'Functions':functions }
def setupResults(sql, limit=1000): """ This function is always called by the software. """ # log the incoming query LOG(sql) result_sources = [] # Sources related to results methods = [] # Methods related to results nmMethod = None # convert the incoming sql to a correct django query syntax object # based on the RESTRICTABLES dictionary in dictionaries.py # (where2q is a helper function to do this for us). q = where2q(sql.where, dictionaries.RESTRICTABLES) try: q = eval(q) # test queryset syntax validity except Exception, e: return {}
def setupResults(sql, limit=1000): """ This function is always called by the software. """ # log the incoming query LOG(sql) result_sources = [] #Sources related to results methods = [] #Methods related to results nmMethod = None # convert the incoming sql to a correct django query syntax object # based on the RESTRICTABLES dictionary in dictionaries.py # (where2q is a helper function to do this for us). q = where2q(sql.where, dictionaries.RESTRICTABLES) try: q = eval(q) # test queryset syntax validity except Exception, e: return {}
def returnResults(tap): """ Return this node's response to the TAP query, tap, where the requested return format is something other than XSAMS. The TAP object has been validated upstream of this method, so we're good to go. """ if tap.format != 'par': emsg = 'Currently, only FORMATs PAR and XSAMS are supported.\n' return tapServerError(status=400, errmsg=emsg) # XXX more duplication of code from setupResults(): # which uses sql = tap.parsedSQL q = sqlparse.where2q(tap.parsedSQL.where, RESTRICTABLES) try: q=eval(q) except Exception,e: LOG('Exception in setupResults():') LOG(e) return {}
def returnResults(tap): """ Return this node's response to the TAP query, tap, where the requested return format is something other than XSAMS. The TAP object has been validated upstream of this method, so we're good to go. """ if tap.format != 'par': emsg = 'Currently, only FORMATs PAR and XSAMS are supported.\n' return tapServerError(status=400, errmsg=emsg) # XXX more duplication of code from setupResults(): # which uses sql = tap.parsedSQL q = sqlparse.where2q(tap.parsedSQL.where, RESTRICTABLES) try: q = eval(q) except Exception, e: LOG('Exception in setupResults():') LOG(e) return {}
def setupResults(sql): """ This function is always called by the software. """ # log the incoming query log.debug('sql input: %s'%sql) # convert the incoming sql to a correct django query syntax object # based on the RESTRICTABLES dictionary in dictionaries.py # (where2q is a helper function to do this for us). q = where2q(sql.where, dictionaries.RESTRICTABLES) try: q = eval(q) # test queryset syntax validity except: return {} #react_ds = RxnData.objects.filter(pk__in=(2,4,3862,3863,7975,7976)) react_ds = RxnData.objects.filter(q, network_id=3) # count the number of matches, make a simple trunkation if there are # too many (record the coverage in the returned header) nreacts=react_ds.count() log.debug('number of reaction data: %s'%nreacts) sources = Source.objects.filter(pk__in=set(react_ds.values_list('ref_id', flat=True))) nsources = sources.count() reacts = Reaction.objects.filter(pk__in=set(react_ds.values_list('reaction_id', flat=True))) species = Species.objects.filter(pk__in=reacts.values_list('species')) atoms = species.filter(type=1) molecules = species.filter(type=2) particles = species.filter(type=3) for rea in react_ds: rea.Reactants = rea.reaction.reactants.all() rea.Products = rea.reaction.products.all() # Add the rate coefficient at 10K as a data table if rea.r10kr: data = [] rea.DataSets = [] dataset = EmptyClass() dataRow = EmptyClass() dataRow.xdata = '10' dataRow.ydata = str(rea.r10kr) dataRow.xdataunit = 'K' dataRow.ydataunit = 'cm3/sec' dataRow.datadescription = 'Rate Coefficient at 10K' data.append(dataRow) dataset.TabData = data dataset.Description = dataRow.datadescription dataset.Ref = rea.ref.abbr rea.DataSets.append(dataset) log.debug('done setting up the QuerySets') # Create the header with some useful info. The key names here are # standardized and shouldn't be changed. headerinfo={\ 'COUNT-ATOMS':atoms.count(), 'COUNT-MOLECULES':molecules.count(), 'COUNT-COLLISIONS':nreacts, } # Return the data. The keynames are standardized. # 2012-02-14 KWS As per Guy's message - return an empty dict if there is no data. if nreacts > 0: return {\ 'CollTrans':react_ds, 'Atoms':atoms, 'Molecules':molecules, #'Particles':particles, 'Sources':sources, 'HeaderInfo':headerinfo, #'Methods':methods #'Functions':functions } else: return {}