Esempio n. 1
0
class Comment(MongoModel):
    ref_post = fields.ReferenceField(Post)

    def full_clean(self, exclude=None):
        super().full_clean(exclude=['ref_post'])

    # All queries must be executed via this_manger
    manager = Manager.from_queryset(CommentQuerySet)()

    class Meta:
        cascade = True
class Facet(MongoModel):
    id = fields.CharField(max_length=200, blank=False, required=True)
    values = fields.DictField('Values')

    manager = Manager.from_queryset(FacetQuerySet)()

    @staticmethod
    def get_facet_by_id(id):
        facets = list(Facet.manager.get_property_facet(id))
        if (len(facets) > 0):
            return facets[0]
        return None
Esempio n. 3
0
class Post(MongoModel):
    ref_user = fields.ReferenceField(User)

    # Override full_clean by pass exclude to super,
    # so that the reference field will not be checked in clean()
    def full_clean(self, exclude=None):
        super().full_clean(exclude=['ref_user'])

    # All queries must be executed via this_manger
    manager = Manager.from_queryset(PostQuerySet)()

    def get_comments(self):
        return list(Comment.manager.comments_by_post(self._id))

    class Meta:
        # Important for cascade saving
        cascade = True
class SimilarTool(MongoModel):
    id = fields.CharField(max_length=200, blank=False, required=True)
    similars = fields.EmbeddedDocumentListField('Similar')

    manager = Manager.from_queryset(SimilarQuerySet)()

    @staticmethod
    def get_similars_by_id(id):
        tools = list(SimilarTool.manager.get_tool_by_id(id))
        if (len(tools) > 0):
            return tools[0]
        return None

    def add_similar(self, id, score):
        not_found = True
        for a in self.similars:
            if a.id == id:
                not_found = False
                a.score = score
        if not_found:
            similar = Similar()
            similar.id = id
            similar.score = score
            self.similars.append(similar)
Esempio n. 5
0
from pymodm.queryset import QuerySet

from test import ODMTestCase


class CustomQuerySet(QuerySet):
    def authors(self):
        """Return a QuerySet over documents representing authors."""
        return self.raw({'role': 'A'})

    def editors(self):
        """Return a QuerySet over documents representing editors."""
        return self.raw({'role': 'E'})


CustomManager = Manager.from_queryset(CustomQuerySet)


class BookCredit(MongoModel):
    first_name = fields.CharField()
    last_name = fields.CharField()
    role = fields.CharField(choices=[('A', 'author'), ('E', 'editor')])
    contributors = CustomManager()
    more_contributors = CustomManager()


class ManagerTestCase(ODMTestCase):

    def test_default_manager(self):
        # No auto-created Manager, since we defined our own.
        self.assertFalse(hasattr(BookCredit, 'objects'))
Esempio n. 6
0
        return self.raw({"status": TaskStatusConst.COMPLETED})

    def aborted(self):
        return self.raw({"status": TaskStatusConst.ABORTED})

    def failed(self):
        return self.raw({"status": TaskStatusConst.FAILED})

    def canceled(self):
        return self.raw({"status": TaskStatusConst.CANCELED})

    def preempted(self):
        return self.raw({"status": TaskStatusConst.PREEMPTED})


TaskManager = Manager.from_queryset(TaskQuerySet)
TaskStatusManager = Manager.from_queryset(TaskStatusQuerySet)


class TaskConstraints(EmbeddedMongoModel):
    hard = fields.BooleanField(default=True)

    @classmethod
    def from_payload(cls, payload):
        document = Document.from_payload(payload)
        task_constraints = cls.from_document(document)
        return task_constraints

    def to_dict(self):
        dict_repr = self.to_son().to_dict()
        dict_repr.pop('_cls')
Esempio n. 7
0
from pymodm.queryset import QuerySet


class ExperimentQuerySet(QuerySet):

    def by_dataset(self, dataset):
        return self.raw({"dataset": dataset})

    def by_bidding_rule(self, bidding_rule):
        return self.raw({'bidding_rule': bidding_rule})

    def by_dataset_and_bidding_rule(self, dataset, bidding_rule):
        return self.raw({"dataset": dataset}) and self.raw({"bidding_rule": bidding_rule})


ExperimentManager = Manager.from_queryset(ExperimentQuerySet)


class Experiment(MongoModel):
    run_id = fields.IntegerField(primary_key=True)
    name = fields.CharField()
    approach = fields.CharField()
    bidding_rule = fields.CharField()
    dataset = fields.CharField()
    requests = fields.EmbeddedDocumentListField(TransportationRequest)
    tasks = fields.EmbeddedDocumentListField(Task)
    actions = fields.EmbeddedDocumentListField(Action)
    tasks_status = fields.EmbeddedDocumentListField(TaskStatus)
    tasks_performance = fields.EmbeddedDocumentListField(TaskPerformance)
    robots_performance = fields.EmbeddedDocumentListField(RobotPerformance)
Esempio n. 8
0
from pymodm.manager import Manager
from db.queryset import CurrenciesQuerySet

manager = Manager.from_queryset(CurrenciesQuerySet)
Esempio n. 9
0
from pymodm import fields, MongoModel
from pymodm.queryset import QuerySet
from pymodm.manager import Manager


class RoundQuerySet(QuerySet):
    def get_task(self, number):
        return self.get({'_id': number})


RoundManager = Manager.from_queryset(RoundQuerySet)


class Round(MongoModel):
    number = fields.IntegerField(primary_key=True)
    round_id = fields.CharField()
    tasks_to_allocate = fields.ListField(blank=True)
    time_to_allocate = fields.FloatField()
    allocated_task = fields.UUIDField()
    n_received_bids = fields.IntegerField()
    n_received_no_bids = fields.IntegerField()

    objects = RoundManager()

    class Meta:
        ignore_unknown_fields = True

    @classmethod
    def create_new(cls, **kwargs):
        kwargs.update(number=cls.get_number())
        round_ = cls(**kwargs)
Esempio n. 10
0
                    for doc in docs:
                        if field.attname in doc:
                            inner_doc = doc[field.attname]
                            cls_name = inner_doc.get(
                                '_cls',
                                field.related_model._mongometa.object_name)
                            docs_by_cls[cls_name].append(inner_doc)
                elif isinstance(field,
                                pymodm.fields.EmbeddedDocumentListField):
                    for doc in docs:
                        if field.attname in doc:
                            for inner_doc in doc[field.attname]:
                                cls_name = inner_doc.get(
                                    '_cls',
                                    field.related_model._mongometa.object_name)
                                docs_by_cls[cls_name].append(inner_doc)

        # Delete all the images at those paths
        if len(image_paths) > 0:
            with arvet.database.image_manager.get() as image_manager:
                for path in image_paths:
                    image_manager.remove_image(path)

        # Proceed with the rest of the delete
        super(ImageQuerySet, self).delete()


# Custom manager using the ImageQueryset by default.
# Assign this as the manager for models with image fields
ImageManager = Manager.from_queryset(ImageQuerySet)
Esempio n. 11
0
from pymodm.queryset import QuerySet

from test import ODMTestCase


class CustomQuerySet(QuerySet):
    def authors(self):
        """Return a QuerySet over documents representing authors."""
        return self.raw({'role': 'A'})

    def editors(self):
        """Return a QuerySet over documents representing editors."""
        return self.raw({'role': 'E'})


CustomManager = Manager.from_queryset(CustomQuerySet)


class BookCredit(MongoModel):
    first_name = fields.CharField()
    last_name = fields.CharField()
    role = fields.CharField(choices=[('A', 'author'), ('E', 'editor')])
    contributors = CustomManager()
    more_contributors = CustomManager()


class ManagerTestCase(ODMTestCase):
    def test_default_manager(self):
        # No auto-created Manager, since we defined our own.
        self.assertFalse(hasattr(BookCredit, 'objects'))
        # Check that our custom Manager was installed.
Esempio n. 12
0
class MongoWorkflow(MongoModel):
    """
    Mongo model class that contains the persistence information of a Workflow.
    """
    name = fields.CharField()
    author = fields.CharField(blank=True)
    description = fields.CharField(blank=True)
    git_repo = fields.CharField()
    license = fields.CharField(blank=True)
    type = fields.CharField(blank=True)
    containers = fields.ListField(fields.CharField(blank=True), blank=True)

    manager = Manager.from_queryset(WokflowQuerySet)()

    @staticmethod
    def get_workflows(name=None,
                      description=None,
                      author=None,
                      license=None,
                      type=None,
                      container=None,
                      offset=0,
                      limit=None,
                      is_all_field_search=False,
                      sort_field=None,
                      sort_order=None):

        filters = []
        if name is not None:
            filters.append({"name": {"$regex": name}})
        if description is not None:
            filters.append({"description": {"$regex": description}})
        if author is not None:
            filters.append({"author": {"$regex": author}})
        if license is not None:
            filters.append({"license": {"$regex": license}})
        if type is not None:
            filters.append({"name": {"$regex": type}})
        if container is not None:
            filters.append({"containers": {"$regex": container}})

        if is_all_field_search:
            filters_query = {"$or": filters}
        else:
            filters_query = {"$and": filters}

        match_condition = {"$match": filters_query}

        if sort_field == "name":
            sort_field = "name"
        elif sort_field == "description":
            sort_field = "description"

        if sort_order is not None and sort_order.lower().startswith("desc"):
            sort_order = pymongo.DESCENDING
        else:
            sort_order = pymongo.ASCENDING

        sort_condition = {'$sort': {sort_field: sort_order}}

        if len(filters) > 0:
            res = MongoWorkflow.manager.exec_aggregate_query(
                match_condition, sort_condition)
        else:
            res = MongoWorkflow.manager.exec_aggregate_query(sort_condition)

        tools = list(res)
        tools_len = len(tools)
        offset = int(offset)
        if offset >= tools_len:  # empty list
            return None

        next_offset = offset + limit
        tools_paginated = tools[offset:next_offset]

        total_pages = math.ceil(tools_len / limit)
        last_page_offset = (total_pages - 1) * limit

        resp = ToolsResponse()
        resp.tools = tools_paginated
        resp.last_page_offset = last_page_offset
        if next_offset < tools_len:
            resp.next_offset = next_offset

        return resp

    @staticmethod
    def get_all_workflows():
        return MongoWorkflow.manager.all_workflows()
Esempio n. 13
0
class MongoToolVersion(MongoModel):
    """
    This class store the information of a Tool version (e.g. PeptideShacker 2.0 )
    """
    id = fields.CharField(max_length=200, blank=False, required=False)
    name = fields.CharField(max_length=1000, blank=True, required=False)
    version = fields.CharField(max_length=1000, blank=False, required=False)
    description = fields.CharField(blank=True)
    home_url = fields.CharField()
    doc_url = fields.CharField()
    license = fields.CharField(max_length=1000)
    additional_identifiers = fields.CharField()
    organization = fields.CharField()
    has_checker = fields.BooleanField()
    checker_url = fields.CharField(max_length=400)
    is_verified = fields.BooleanField()
    verified_source = fields.CharField(max_length=400)
    registry_url = fields.CharField(max_length=500)

    additional_metadata = fields.CharField()
    tool_classes = fields.EmbeddedDocumentListField('ToolClass')
    authors = fields.ListField(fields.CharField(max_length=200))
    contains = fields.ListField(fields.CharField(max_length=400))
    tool_versions = fields.ListField(fields.CharField(max_length=400))
    aliases = fields.ListField(fields.CharField())
    container_recipe = fields.CharField(max_length=500)

    # Specific of Tool Version
    ref_tool = fields.ReferenceField(MongoTool)
    hash_name = fields.CharField(max_length=2000)
    descriptors = fields.EmbeddedDocumentListField('Descriptor')
    image_containers = fields.EmbeddedDocumentListField('ContainerImage')
    last_update = fields.DateTimeField()

    # All queries must be executed via this_manger
    manager = Manager.from_queryset(ToolQuerySet)()
    manager_versions = Manager.from_queryset(ToolVersionQuerySet)()

    @staticmethod
    def get_all_tool_versions():
        return MongoToolVersion.manager_versions.mongo_all_tool_versions()

    @staticmethod
    def get_tool_version_by_id(tool_version_id):
        tools = MongoToolVersion.manager_versions.get_tool_version_by_id(
            tool_version_id)
        tools_list = list(tools)
        if tools_list is not None and len(tools_list) > 0:
            return tools_list[0]
        return None

    @staticmethod
    def get_tool_version_by_name(tool_name):
        tools = MongoToolVersion.manager_versions.get_tool_version_by_name(
            tool_name)
        tools_list = list(tools)
        if tools_list is not None and len(tools_list) > 0:
            return tools_list
        return None

    def add_image_container(self, image_container):
        """
        Add a new container image to the to the list of containers.
        :param image_container:
        :return:
        """
        new = True
        for index, image_container_old in enumerate(self.image_containers):
            if image_container.full_tag == image_container_old.full_tag and image_container.container_type == image_container_old.container_type:
                self.image_containers[index] = image_container
                new = False
        if new:
            self.image_containers.append(image_container)

    def __getitem__(self, key):
        if key == self.id:
            return self
        return

    def add_author(self, author):
        """
        This method add a new author to the list of authors of the Tool Version
        :param author: New author
        :return:
        """
        if self.authors is None:
            self.authors = []

        if author not in self.authors:
            self.authors.append(author)

    class Meta:
        write_concern = WriteConcern(j=True)
        final = True
        indexes = [
            IndexModel([("id", pymongo.DESCENDING),
                        ("name", pymongo.DESCENDING),
                        ("version", pymongo.DESCENDING)],
                       unique=True)
        ]
Esempio n. 14
0
class MongoTool(MongoModel):
    """
    Mongo Tool Class contains the persistence information of a Tool.
    """
    id = fields.CharField(max_length=200, blank=False, required=True)
    name = fields.CharField(max_length=1000, blank=True, required=False)
    description = fields.CharField(blank=True)
    home_url = fields.CharField()
    last_version = fields.CharField()
    organization = fields.CharField()
    has_checker = fields.BooleanField()
    checker_url = fields.CharField(max_length=400)
    is_verified = fields.BooleanField()
    verified_source = fields.CharField(max_length=400)
    registry_url = fields.CharField(max_length=500)
    license = fields.CharField(max_length=1000)
    additional_metadata = fields.CharField()
    tool_classes = fields.EmbeddedDocumentListField('ToolClass')
    authors = fields.ListField(fields.CharField(max_length=200))
    contains = fields.ListField(fields.CharField(max_length=400))
    tool_versions = fields.ListField(fields.CharField(max_length=400))
    additional_identifiers = fields.ListField(fields.CharField(max_length=400))
    registries = fields.ListField(fields.CharField(max_length=200))
    aliases = fields.ListField(fields.CharField())
    checker = fields.BooleanField()
    tool_tags = fields.ListField(fields.CharField())
    publications = fields.EmbeddedDocumentListField('Publication')
    pulls = fields.EmbeddedDocumentListField('PullProvider')
    total_pulls = fields.IntegerField()
    anchor_tool = fields.CharField(max_length=1000, blank=True, required=False)

    manager = Manager.from_queryset(ToolQuerySet)()

    class Meta:
        write_concern = WriteConcern(j=True)
        final = True
        indexes = [
            IndexModel([("id", pymongo.DESCENDING),
                        ("name", pymongo.DESCENDING)],
                       unique=True)
        ]
        cascade = True

    def get_tool_versions(self):
        return list(
            MongoToolVersion.manager.mongo_tool_versions_by_tool(self._id))

    def add_authors(self, new_authors):
        """
        This method adds a list of authors to the current list of author of the Tool
        :param new_authors: New Authors
        :return:
        """
        if self.authors is None:
            self.authors = []

        for author in new_authors:
            if author not in self.authors:
                self.authors.append(author)

    def add_additional_identifiers(self, ids):
        if self.additional_identifiers is None:
            self.additional_identifiers = []

        for id in ids:
            if id not in self.additional_identifiers:
                self.additional_identifiers.append(id)

    def add_registry(self, new_registry):
        """
        This method adds a registry to the current list of registries of the Tool
        :param new_registry:
        :param registry: New registry
        :return:
        """
        if self.registries is None:
            self.registries = []

        if new_registry not in self.registries:
            self.registries.append(new_registry)

    def add_alias(self, new_alias):
        """
        This method adds a registry to the current list of registries of the Tool
        :param registry: New registry
        :return:
        """
        if self.aliases is None:
            self.aliases = []

        if new_alias not in self.aliases:
            self.aliases.append(new_alias)

    def add_publication(self, publication):
        if self.publications is None:
            self.publications = []
        noFound = True
        for entry in self.publications:
            if entry.pubmed_id == publication.pubmed_id or entry.doi_id == publication.doi_id or entry.pmc_id == publication.pmc_id:
                noFound = False

        if noFound:
            self.publications.append(publication)

    def get_main_author(self):
        """
        This method returns first author of the list. The pipeline add the
        BioContainers as first author of the container.
        :return:
        """
        if len(self.authors) > 0:
            return self.authors[0]
        return None

    def get_main_tool_class(self):
        """
        This method return the specific tool
        :return:
        """
        if self.tool_classes is not None and len(self.tool_classes) > 0:
            return self.tool_classes[0]

        return _CONSTANT_TOOL_CLASSES['CommandLineTool']

    def build_complete_metadata(self):
        fields = [self.name]
        if self.description is not None:
            fields.append(self.description)
        for alias in self.aliases:
            fields.append(alias)
        for id in self.additional_identifiers:
            fields.append(id)
        for publication in self.publications:
            if publication.title is not None:
                fields.append(publication.title)
            if publication.abstract is not None:
                fields.append(publication.abstract)
            if publication.authors is not None:
                for author in publication.authors:
                    fields.append(author)
        self.additional_metadata = "\n".join(fields)

    def add_pull_provider(self, id, count):
        if self.pulls is None:
            self.pulls = []

        total_count = 0

        pull_not_found = True
        for pull in self.pulls:
            if pull.id == id:
                pull.count = count
                pull_not_found = False

            total_count += pull.count

        if pull_not_found:
            pull = PullProvider()
            pull.id = id
            pull.count = count
            self.pulls.append(pull)

        self.total_pulls = total_count

    def get_pulls(self):
        count = 0
        if self.total_pulls is not None:
            count = self.total_pulls
        return count

    @staticmethod
    def get_main_author_dict(authors):
        """
        This method returns first author of the list. The pipeline add the
        BioContainers as first author of the container.
        :return:
        """
        if len(authors) > 0:
            return authors[0]
        return None

    @staticmethod
    def get_main_tool_class_dict(tool_classes):
        """
        This method return the specific tool
        :return:
        """
        if tool_classes is not None:
            if isinstance(tool_classes, list) and len(tool_classes) > 0:
                return tool_classes[0]
            else:
                return tool_classes

        return _CONSTANT_TOOL_CLASSES['CommandLineTool']

    @staticmethod
    def get_all_tools():
        return MongoTool.manager.mongo_all_tools()

    @staticmethod
    def get_tools_by_name(toolname, alias, name):
        return MongoTool.manager.get_tools_by_name(toolname, alias, name)

    @staticmethod
    def get_tool_by_id(id):
        tools = MongoTool.manager.get_tool_by_id(id)
        tools_list = list(tools)
        if tools_list is not None and len(tools_list) > 0:
            return tools_list[0]
        return None

    @staticmethod
    def get_tool_with_anchor_tool_field(tool_id):
        return MongoTool.manager.get_tool_with_anchor_tool_field(tool_id)

    @staticmethod
    def get_tool_by_additional_id(id):
        tools = MongoTool.manager.get_tool_by_additional_id(id)
        return tools

    @staticmethod
    def get_all_tools_by_id(ids):
        return MongoTool.manager.get_all_tools_by_id(ids)

    @staticmethod
    def get_tools(id=None,
                  alias=None,
                  registry=None,
                  organization=None,
                  name=None,
                  toolname=None,
                  toolclass=None,
                  description=None,
                  author=None,
                  checker=None,
                  license=None,
                  tool_tags=None,
                  facets=None,
                  offset=None,
                  limit=None,
                  is_all_field_search=False,
                  sort_field=None,
                  sort_order=None):

        unwind_tool_classes = None
        filters = []
        facets_filter = []
        if id is not None:
            filters.append({"id": {"$regex": id, '$options': 'i'}})
        if alias is not None:
            filters.append({"aliases": {"$regex": alias, '$options': 'i'}})
        if registry is not None:
            filters.append(
                {"registries": {
                    "$regex": registry,
                    '$options': 'i'
                }})
        if organization is not None:
            filters.append(
                {"organization": {
                    "$regex": organization,
                    '$options': 'i'
                }})
        if toolname is not None:
            filters.append({"name": {
                "$regex": toolname,
                '$options': 'i'
            }})  # toolname : The name of the tool
        if toolclass is not None:
            unwind_tool_classes = {"$unwind": "$tool_classes"}
            filters.append(
                {"tool_classes.name": {
                    "$regex": toolclass,
                    '$options': 'i'
                }})  # toolclass : type of the tool
        if description is not None:
            filters.append(
                {"description": {
                    "$regex": description,
                    '$options': 'i'
                }})
        if author is not None:
            filters.append({"authors": {"$regex": author, '$options': 'i'}})
        if license is not None:
            filters.append({"license": {"$regex": license, '$options': 'i'}})
        if tool_tags is not None:
            filters.append(
                {"tool_tags": {
                    "$regex": tool_tags,
                    '$options': 'i'
                }})
        # if checker is not None:  # TODO

        if facets is not None:
            for facet in facets:
                for facet_value in facets[facet]:
                    facets_filter.append(
                        {facet: {
                            "$regex": facet_value,
                            '$options': 'i'
                        }})

        versions_string = "tool_versions"
        if name is not None:  # name : The name of the image i.e., tool_version
            filters.append({
                ("%s.name" % versions_string): {
                    "$regex": name,
                    '$options': 'i'
                }
            })

        # Fetch tools along with the tool_versions in one query (similar to SQL join)
        lookup_condition = \
            {"$lookup":
                {
                    "from": "mongo_tool_version",
                    "localField": "name",
                    "foreignField": "name",
                    "as": ("%s" % versions_string)
                }
            }

        if is_all_field_search:
            filters_query = {"$or": filters}
        else:
            filters_query = {"$and": filters}

        if len(facets_filter) > 0:
            filters_query["$and"] = facets_filter

        match_condition = {"$match": filters_query}

        if sort_field == "toolname":
            sort_field = "name"
        elif sort_field == "description":
            sort_field = "description"
        elif sort_field == "pulls":
            sort_field = "total_pulls"
        else:
            sort_field = "id"

        if sort_order is not None and sort_order.lower().startswith("desc"):
            sort_order = pymongo.DESCENDING
        else:
            sort_order = pymongo.ASCENDING

        sort_condition = {'$sort': {sort_field: sort_order}}

        exec_args = [lookup_condition, sort_condition]
        if len(filters) > 0:
            exec_args.append(match_condition)
        if unwind_tool_classes is not None:
            exec_args.append(unwind_tool_classes)

        res = MongoTool.manager.exec_aggregate_query(*exec_args)

        tools = list(res)
        tools_len = len(tools)
        offset = int(offset)
        if offset >= tools_len:  # empty list
            return None

        next_offset = offset + limit
        tools_paginated = tools[offset:next_offset]

        total_pages = math.ceil(tools_len / limit)
        last_page_offset = (total_pages - 1) * limit

        resp = ToolsResponse()
        resp.tools = tools_paginated
        resp.last_page_offset = last_page_offset
        if next_offset < tools_len:
            resp.next_offset = next_offset

        return resp
Esempio n. 15
0
# 从Mongodb里面读取已有collection的长度

from pymodm.queryset import QuerySet
from pymodm.connection import connect
from pymongo.write_concern import WriteConcern
from pymodm import MongoModel, fields
from pymodm.manager import Manager


# 创建查询
class QuerySet_secumain(QuerySet):
    def get_SecuCode(self, SecuCode):
        return list(self.only(SecuCode))


Manager_hk_secumain = Manager.from_queryset(QuerySet_secumain)


class hk_secumain(MongoModel):
    ID = fields.CharField(primary_key=True)
    InnerCode = fields.IntegerField()
    CompanyCode = fields.IntegerField()
    SecuCode = fields.CharField()
    ChiName = fields.CharField(blank=True)
    ChiNameAbbr = fields.CharField(blank=True)
    EngName = fields.CharField()
    EngNameAbbr = fields.CharField()
    SecuAbbr = fields.CharField()
    ChiSpelling = fields.CharField()
    SecuMarket = fields.IntegerField()
    SecuCategory = fields.IntegerField()
Esempio n. 16
0
import dateutil.parser
from fmlib.utils.messages import Document
from pymodm import fields, MongoModel
from pymodm.manager import Manager
from pymodm.queryset import QuerySet
from pymongo.errors import ServerSelectionTimeoutError


class TimetableQuerySet(QuerySet):
    def get_timetable(self, robot_id):
        """ Returns a timetable mongo model that matches to the robot_id
        """
        return self.get({'_id': robot_id})


TimetableManager = Manager.from_queryset(TimetableQuerySet)


class Timetable(MongoModel):
    robot_id = fields.CharField(primary_key=True)
    solver_name = fields.CharField()
    ztp = fields.DateTimeField()
    stn = fields.DictField()
    dispatchable_graph = fields.DictField(default=dict())
    stn_tasks = fields.DictField(blank=True)

    objects = TimetableManager()

    class Meta:
        archive_collection = 'timetable_archive'
        ignore_unknown_fields = True
Esempio n. 17
0
    navigation_stack = fields.EmbeddedDocumentListField(SoftwareComponent)
    interfaces = fields.EmbeddedDocumentListField(SoftwareComponent)


class Version(EmbeddedMongoModel):

    hardware = fields.EmbeddedDocumentField(RobotHardware)
    software = fields.EmbeddedDocumentField(SoftwareStack)


class RobotQuerySet(QuerySet):
    def get_robot(self, robot_id):
        return self.get({'_id': robot_id})


RobotManager = Manager.from_queryset(RobotQuerySet)


class Robot(MongoModel):

    robot_id = fields.CharField(primary_key=True)
    uuid = fields.UUIDField()
    version = fields.EmbeddedDocumentField(Version)
    status = fields.EmbeddedDocumentField(RobotStatus)
    position = fields.EmbeddedDocumentField(Position)

    objects = RobotManager()

    class Meta:
        archive_collection = 'robot_archive'
        ignore_unknown_fields = True
Esempio n. 18
0
    def by_country(self, country_name):
        country_code = PythonReverseGeocoding.get_country_code(country_name)
        return self.raw({'reverse_geocoding.cc': country_code})

    def by_month(self, month_num, year):
        earliest_datetime = datetime(year, month_num, 1)
        latest_datetime = datetime(year, month_num + 1, 1)
        return self.raw(
            {'t': {
                '$gte': earliest_datetime,
                '$lt': latest_datetime
            }})


LocationManager = Manager.from_queryset(LocationQuerySet)


class Location(MongoModel):

    datetime = fields.DateTimeField(verbose_name='UTC Time',
                                    mongo_name='t',
                                    required=True)

    latitude = fields.FloatField(required=True, mongo_name='lat')
    longitude = fields.FloatField(required=True, mongo_name='lon')

    reverse_geocoding = fields.EmbeddedDocumentField(ReverseGeocoding,
                                                     blank=True)

    objects = LocationManager()
Esempio n. 19
0

class FrameErrorResultQuerySet(QuerySet):

    def delete(self):
        """
        When a frame error result is deleted, also delete the frame errors it refers to
        :return:
        """
        frame_error_ids = set(err_id for doc in self.values()
                              for trial_errors in doc['errors'] for err_id in trial_errors['frame_errors'])
        FrameError.objects.raw({'_id': {'$in': list(frame_error_ids)}}).delete()
        super(FrameErrorResultQuerySet, self).delete()


FrameErrorResultManger = Manager.from_queryset(FrameErrorResultQuerySet)


class FrameErrorResult(MetricResult):
    """
    Error observations per estimate of a pose
    """
    system = fields.ReferenceField(VisionSystem, required=True, on_delete=pymodm.ReferenceField.CASCADE)
    image_source = fields.ReferenceField(ImageSource, required=True, on_delete=pymodm.ReferenceField.CASCADE)
    errors = fields.EmbeddedDocumentListField(TrialErrors, required=True, blank=True)
    image_source_properties = fields.DictField(blank=True)
    metric_properties = fields.DictField(blank=True)
    frame_columns = fields.ListField(fields.CharField(), blank=True)

    objects = FrameErrorResultManger()
Esempio n. 20
0
import uuid

from pymodm import EmbeddedMongoModel, fields, MongoModel
from pymodm.manager import Manager
from pymodm.queryset import QuerySet
from ropod.structs.status import ActionStatus


class ActionQuerySet(QuerySet):
    def get_action(self, action_id):
        if isinstance(action_id, str):
            action_id = uuid.UUID(action_id)
        return self.get({'_id': action_id})


ActionManager = Manager.from_queryset(ActionQuerySet)


class Duration(EmbeddedMongoModel):
    mean = fields.FloatField()
    variance = fields.FloatField()

    def update(self, mean, variance):
        self.mean = mean
        self.variance = variance


class Action(MongoModel, EmbeddedMongoModel):

    action_id = fields.UUIDField(primary_key=True)
    type = fields.CharField()
Esempio n. 21
0
from pymodm import fields, MongoModel
from pymodm.queryset import QuerySet
from pymodm.manager import Manager


class ConfigQuerySet(QuerySet):
    def get_config(self, component_name):
        return self.get({'_id': component_name})


TimetableManager = Manager.from_queryset(ConfigQuerySet)


class Config(MongoModel):
    component_name = fields.CharField(primary_key=True)
    config_params = fields.DictField()

    @classmethod
    def create_new(cls, component_name, config_params):
        config = cls(component_name, config_params)
        config.save()