示例#1
0
def setupVssRequest(sql, limit=10000):
    """		
        Execute a vss request
        @type  sql: string
        @param sql: vss request
        @rtype:   util_models.Result
        @return:  Result object		
    """
    # convert the incoming sql to a correct django query syntax object
    # based on the RESTRICTABLES dictionary in dictionaries.py
    q = sql2Q(sql)
    transs = django_models.Collisionaltransition.objects.filter(q)
    # count the number of matches, make a simple trunkation if there are
    # too many (record the coverage in the returned header)
    ncoll = transs.count()
    if limit < ncoll:
        transs, percentage = truncateTransitions(transs, q, limit)
    else:
        percentage = None

    species, nstates, sourceids = getSpeciesWithStates(transs)
    # electron collider
    particles = getParticles()

    # cross sections
    states = []
    for specie in species:
        states.extend(specie.States)
    nspecies = species.count()

    nspecies = species.count()
    sources = getSources(sourceids)
    nsources = sources.count()

    # Create the result object
    result = util_models.Result()
    result.addHeaderField('TRUNCATED', percentage)
    result.addHeaderField('COUNT-STATES', nstates)
    result.addHeaderField('COUNT-COLLISIONS', ncoll)
    result.addHeaderField('COUNT-SPECIES', nspecies)
    result.addHeaderField('COUNT-SOURCES', nsources)

    if LAST_MODIFIED is not None:
        result.addHeaderField('LAST-MODIFIED', LAST_MODIFIED)

    if (nstates == 0 and nspecies == 0):
        result.addHeaderField('APPROX-SIZE', 0)

    if ncoll > 0:
        result.addDataField('CollTrans', transs)
        result.addDataField('Particles', particles)
    result.addDataField('Atoms', species)
    result.addDataField('Sources', sources)

    return result
示例#2
0
def setupVssRequest(sql, limit=3000):
    """
    This function is always called by the software.
    """
    # log the incoming query
    log.debug(sql)

    # convert the incoming sql to a correct django query syntax object
    q = sql2Q(sql)

    start = time.clock()
    transs = django_models.Radiativetransition.objects.filter(q)
    ntranss = transs.count()

    if limit < ntranss:
        transs, percentage = truncateTransitions(transs, q, limit)
    else:
        percentage = None

    species, nstates, sourceids = getSpeciesWithStates(transs)

    # cross sections
    states = []

    nspecies = len(species)
    for specie in species:
        for state in specie.States:
            if state.xdata is not None:  # do not add state without xdata/ydata
                states.append(state)

    #transs = toLowerUpperStates(transs)
    sources = getSources(sourceids)
    nsources = sources.count()

    # Create the result object
    result = util_models.Result()

    result.addHeaderField('TRUNCATED', percentage)
    result.addHeaderField('COUNT-STATES', nstates)
    result.addHeaderField('COUNT-RADIATIVE', ntranss)
    result.addHeaderField('COUNT-SPECIES', nspecies)
    result.addHeaderField('COUNT-SOURCES', nsources)

    if (nstates == 0 and nspecies == 0):
        result.addHeaderField('APPROX-SIZE', 0)

    result.addDataField('RadTrans', transs)
    result.addDataField('Atoms', species)
    result.addDataField('RadCross', states)
    result.addDataField('Sources', sources)

    end = time.clock() - start
    log.debug("1 " + str(end) + "s")
    return result
示例#3
0
def setupVssRequest(sql, limit=500):
    """		
        Execute a vss request
        @type  sql: string
        @param sql: vss request
        @rtype:   util_models.Result
        @return:  Result object		
    """

    result = util_models.Result()
    q = sql2Q(sql)

    #select transitions : combination of density/temperature
    transs = django_models.Transition.objects.filter(q)
    ntranss = transs.count()

    if limit < ntranss:
        transs, percentage = truncateTransitions(transs, q, limit)
    else:
        percentage = None

    # Through the transition-matches, use our helper functions to extract
    # all the relevant database data for our query.
    if ntranss > 0:
        species, nspecies, nstates = getSpeciesWithStates(transs)
        transitions, environments = getTransitionsData(transs)
        particles = getParticles(ntranss)
        functions = getFunctions()
        sources = getSources(transs)
        nsources = len(sources)

        # Create the header with some useful info. The key names here are
        # standardized and shouldn't be changed.
        result.addHeaderField('TRUNCATED', percentage)
        result.addHeaderField('COUNT-SPECIES', nspecies)
        result.addHeaderField('COUNT-STATES', nstates)
        result.addHeaderField('COUNT-RADIATIVE', len(transitions))

        if LAST_MODIFIED is not None:
            result.addHeaderField('LAST-MODIFIED', LAST_MODIFIED)

        result.addDataField('RadTrans', transitions)
        result.addDataField('Atoms', species)
        result.addDataField('Environments', environments)
        result.addDataField('Particles', particles)
        #~ result.addDataField('Functions',functions)
        result.addDataField('Sources', sources)

    else:  # only fill header
        result.addHeaderField('APPROX-SIZE', 0)
        result.addHeaderField('TRUNCATED', percentage)
        result.addHeaderField('COUNT-STATES', 0)
        result.addHeaderField('COUNT-RADIATIVE', 0)
    return result
示例#4
0
def setupSpecies():
    """		
		Return all target species
		@rtype:   util_models.Result
		@return:  Result object		
	"""
    result = util_models.Result()
    species = getSpecies()
    result.addHeaderField('COUNT-SPECIES', len(species))
    result.addDataField('Atoms', species)
    return result
示例#5
0
def setupSpecies():
    """		
		Return all target species
		@rtype:   util_models.Result
		@return:  Result object		
	"""
    result = util_models.Result()
    ids = django_models.Radiativetransition.objects.all().values_list(
        'version', flat=True)
    versions = django_models.Version.objects.filter(pk__in=ids)
    result.addHeaderField('COUNT-SPECIES', len(versions))
    result.addDataField('Atoms', versions)
    return result
示例#6
0
def setupVssRequest(sql, limit=2000):
    """		
        Execute a vss request
        @type  sql: string
        @param sql: vss request
        @rtype:   util_models.Result
        @return:  Result object		
    """

    result = util_models.Result()
    q = sql2Q(sql)
    log.debug(q)
    #select transitions : combination of density/temperature
    transs = models.Radiativetransition.objects.filter(q)
    ntranss = transs.count()
    methods = util_models.Methods()

    if limit < ntranss:
        transs, percentage = truncateTransitions(transs, q, limit)
    else:
        percentage = None

    log.debug("number of transitions : " + str(ntranss))
    # Through the transition-matches, use our helper functions to extract
    # all the relevant database data for our query.
    if ntranss > 0:
        species, nspecies, nstates = getSpeciesWithStates(transs)
        transitions = transs
        sources = getSources(transs)
        nsources = len(sources)

        # Create the header with some useful info. The key names here are
        # standardized and shouldn't be changed.
        result.addHeaderField('TRUNCATED', percentage)
        result.addHeaderField('COUNT-SPECIES', nspecies)
        result.addHeaderField('COUNT-STATES', nstates)
        result.addHeaderField('COUNT-SOURCES', nsources)
        result.addHeaderField('COUNT-RADIATIVE', len(transitions))

        result.addDataField('RadTrans', transitions)
        result.addDataField('Molecules', species)
        result.addDataField('Methods', methods.getMethodsAsList())
        result.addDataField('Sources', sources)

    else:  # only fill header
        result.addHeaderField('APPROX-SIZE', 0)
        result.addHeaderField('TRUNCATED', percentage)
        result.addHeaderField('COUNT-STATES', 0)
        result.addHeaderField('COUNT-RADIATIVE', 0)
    return result
示例#7
0
def setupSpecies():
    """		
    Return all target species
    @rtype:   util_models.Result
    @return:  Result object		
  """

    # get recommended dataset
    dataset = django_models.Dataset.objects.filter(isrecommended="1").get()
    # get all species in this set
    ids = django_models.DatasetVersion.objects.filter(
        datasetid=dataset).values_list('versionid', flat=True)
    versions = django_models.Version.objects.filter(pk__in=ids)

    result = util_models.Result()
    result.addHeaderField('COUNT-SPECIES', versions.count())
    result.addDataField('Atoms', versions)
    return result