Пример #1
0
 def search_prod_req_tags(self, req, ins, tags, pipeline):
     if req.dest in self.extra_data:
         val = self.extra_data[req.dest]
         content = load(req.type, val)
         return StoredProduct(id=0, tags={}, content=content)
     else:
         return self.search_prod_type_tags(req.type, ins, tags, pipeline)
Пример #2
0
    def search_prod_type_tags(self, tipo, ins, tags, pipeline):
        """Returns the first coincidence..."""

        _logger.debug('query search_prod_type_tags type=%s instrument=%s tags=%s pipeline=%s',
                      tipo, ins, tags, pipeline)
        # drp = self.drps.query_by_name(ins)
        label = tipo.name()
        # print('search prod', tipo, ins, tags, pipeline)
        session = self.session
        # FIXME: and instrument == ins
        res = session.query(DataProduct).filter(DataProduct.datatype == label).order_by(DataProduct.priority.desc())
        _logger.debug('requested tags are %s', tags)
        for prod in res:
            pt = {}
            # TODO: facts should be a dictionary
            for key, val in prod.facts.items():
                pt[val.key] = val.value
            # print('product ', prod.id, 'tags', pt)
            _logger.debug('found value with id %d', prod.id)
            _logger.debug('product tags are %s', pt)

            if tags_are_valid(pt, tags):
                _logger.debug('tags are valid, return product, id=%s', prod.id)
                _logger.debug('content is %s', prod.contents)
                # this is a valid product
                return StoredProduct(id=prod.id,
                                     content=load(tipo, os.path.join(self.basedir, prod.contents)),
                                     tags=pt
                                     )
            _logger.debug('tags are in valid')
        else:
            _logger.debug('query search_prod_type_tags, no result found')
            msg = 'type %s compatible with tags %r not found' % (label, tags)
            raise NoResultFound(msg)
Пример #3
0
    def search_param_req(self, req, instrument, mode, pipeline):
        key = req.dest
        _logger.debug('search for instrument %s, req %s',
                      instrument, req)
        try:
            param = self._reqs['requirements'][key]
            content = storage.load(req.type, param)

        except KeyError:
            raise NoResultFound("key %s not found" % key)
        return StoredParameter(content)
Пример #4
0
    def search_prod_req_tags(self, req, ins, tags, pipeline):
        """Returns the first coincidence..."""
        _logger.debug('search for instrument %s, req %s with tags %s',
                      ins, req, tags)
        key = req.dest
        try:
            product = self._reqs['requirements'][key]
            content = storage.load(req.type, product)
        except KeyError:
            raise NoResultFound("key %s not found" % key)

        return StoredProduct(id=-1, content=content, tags={})
Пример #5
0
    def search_product(self, name, tipo, obsres, options=None):
        # returns StoredProduct
        ins = obsres.instrument
        tags = obsres.tags
        pipeline = obsres.pipeline

        if name in self.extra_data:
            val = self.extra_data[name]
            content = load(tipo, val)
            return StoredProduct(id=0, tags={}, content=content)
        else:
            return self.search_prod_type_tags(tipo, ins, tags, pipeline)
Пример #6
0
 def search_param_req_tags(self, req, instrument, mode, tags, pipeline):
     req_table_ins = self.req_table.get(instrument, {})
     req_table_insi_pipe = req_table_ins.get(pipeline, {})
     mode_list = req_table_insi_pipe.get(mode, [])
     if req.dest in self.extra_data:
         value = self.extra_data[req.dest]
         content = StoredParameter(value)
         return content
     else:
         for prod in mode_list:
             pn = prod['name']
             pt = prod['tags']
             if pn == req.dest and tags_are_valid(pt, tags):
                 # We have found the result, no more checks
                 value = load(req.type, prod['content'])
                 content = StoredParameter(value)
                 return content
         else:
             msg = 'name %s compatible with tags %r not found' % (req.dest, tags)
             raise NoResultFound(msg)
Пример #7
0
    def search_prod_type_tags(self, tipo, ins, tags, pipeline):
        """Returns the first coincidence..."""

        klass = tipo.__class__
        drp = self.drps.query_by_name(ins)
        label = product_label(drp, klass)

        # search results of these OBs
        for prod in self.prod_table[ins]:
            pk = prod['type'] 
            pt = prod['tags']
            if pk == label and tags_are_valid(pt, tags):
                # this is a valid product
                # We have found the result, no more checks
                # Make a copy
                rprod = dict(prod)
                rprod['content'] = load(tipo, prod['content'])
                return StoredProduct(**rprod)
        else:
            msg = 'type %s compatible with tags %r not found' % (klass, tags)
            raise NoResultFound(msg)
Пример #8
0
    def search_result_relative(self, name, tipo, obsres, mode, field, node, options=None):
        # So, if node is children, I have to obtain
        session = self.session
        if node == 'children':
            print('obtain', field, 'from all the children of', obsres.taskid)
            res = session.query(DataProcessingTask).filter_by(id=obsres.taskid).one()
            result = []
            for child in res.children:
                # this can be done better...
                nodes = session.query(ReductionResult).filter_by(task_id=child.id).first()
                # this surely can be a mapping instead of a list

                for prod in nodes.values:
                    if prod.name == field:
                        st = StoredProduct(
                            id=prod.id,
                            content=load(DataFrameType(), os.path.join(self.basedir, prod.contents)),
                            tags={}
                        )
                        result.append(st)
                        break
            return result

        elif node == 'prev':
            print('obtain', field, 'from the previous node to', obsres.taskid)
            res = session.query(DataProcessingTask).filter_by(id=obsres.taskid).one()
            # inspect children of my parent
            parent = res.parent
            if parent:
                print([child for child in parent.children])
                raise NoResultFound
            else:
                # Im top level, no previous
                raise NoResultFound
        else:
            pass # print(dest, type, obsres, mode, field, node)