Ejemplo n.º 1
0
 def register_plugin(self, plugin_cls):
     plugin_proxy = PluginProxy(name=plugin_cls.name, hashkey=plugin_cls.hashkey)
     plugin = get_cls(self.session, Plugin, plugin_proxy, attrs=["name", "hashkey"], create=True)
     if plugin_cls.models is not None:
         for m in plugin_cls.models:
             get_cls(self.session, Metric, m.metric_proxy, create=True)
             get_cls(self.session, Source, m.source_proxy, create=True)
             self.register_model(plugin_cls, m)
     return plugin
Ejemplo n.º 2
0
    def query_models(self, plugin_proxy=None, metric_proxy=None, query_cls=PluginData):
        models = self.session.query(PluginModel).order_by("date")
        if plugin_proxy is not None:
            plugin = get_cls(self.session, Plugin, plugin_proxy, attrs=["hashkey"])
            models = models.filter(getattr(query_cls, "plugin") == plugin)

        if metric_proxy is not None:
            metric = get_cls(self.session, Metric, metric_proxy)
            models = models.filter(getattr(query_cls, "metric") == metric)
        return models.distinct()
Ejemplo n.º 3
0
    def register_view_model(self, plugin_cls, model):
        from app import db

        proxy = PluginViewProxy(plugin_id=plugin_cls.hashkey, name=model.name)
        val = get_cls(db.session, PluginView, proxy, attrs=["name", "plugin_id"], create=True)
        proxy.hashkey = val.hashkey
        model.plugin_view_proxy = proxy
        model.hashkey = val.hashkey
Ejemplo n.º 4
0
    def register_model(self, plugin_cls, model):
        proxy = PluginModelProxy(
            plugin_id=plugin_cls.hashkey,
            metric_id=model.metric_proxy.name,
            name=model.__name__
        )
        val = get_cls(self.session, PluginModel, proxy, attrs=["name", "plugin_id", "metric_id"], create=True)

        proxy.hashkey = val.hashkey
        model.plugin_model_proxy = proxy
Ejemplo n.º 5
0
    def _query_base(self, plugin_proxy=None, metric_proxy=None, query_cls=PluginData, plugin_model_proxy=None):
        query = self.session.query(query_cls).order_by("date")
        if self.user is not None:
            query = query.filter(getattr(query_cls, "user") == self.user)

        query = query.order_by(query_cls.date.asc())
        if plugin_proxy is not None:
            plugin = get_cls(self.session, Plugin, plugin_proxy, attrs=["hashkey"])
            query = query.filter(getattr(query_cls, "plugin") == plugin)

        if metric_proxy is not None:
            metric = get_cls(self.session, Metric, metric_proxy)
            query = query.filter(getattr(query_cls, "metric") == metric)

        if plugin_model_proxy is not None:
            plugin_model = get_cls(self.session, PluginModel, plugin_model_proxy, attrs=["hashkey"])
            query = query.filter(getattr(query_cls, "plugin_model") == plugin_model)

        return query
Ejemplo n.º 6
0
 def register_view_model(self, plugin_cls, model):
     from app import db
     proxy = PluginViewProxy(
         plugin_id=plugin_cls.hashkey,
         name=model.name
     )
     val = get_cls(db.session, PluginView, proxy, attrs=["name", "plugin_id"], create=True)
     proxy.hashkey = val.hashkey
     model.plugin_view_proxy = proxy
     model.hashkey = val.hashkey
Ejemplo n.º 7
0
    def setup_model(self, obj):
        data = obj.get_data()

        metric = get_cls(self.session, Metric, obj.metric_proxy)
        source = get_cls(self.session, Source, obj.source_proxy, create=True)

        attribs = {
            'source': source,
            'metric': metric,
            'data': data,
            'plugin': self.plugin,
            'plugin_model_id': obj.plugin_model_proxy.hashkey,
            }

        if self.user is not None:
            attribs['user'] = self.user
        elif self.group is not None:
            attribs['group'] = self.group

        for v in self.modify_vals:
            attribs[v] = getattr(obj, v)

        return attribs
Ejemplo n.º 8
0
    def add(self, plugin_hashkey):
        from app import db
        from core.plugins.loader import plugins
        from core.database.models import Metric, Source

        plugin_cls = plugins[plugin_hashkey]
        plugin = self.lookup_plugin(plugin_hashkey)
        model = self.get_scope_model()
        if plugin not in model.plugins:
            model.plugins.append(plugin)

        if plugin_cls.models is not None:
            for m in plugin_cls.models:
                # Register metrics and sources.
                get_cls(db.session, Metric, m.metric_proxy, create=True)
                get_cls(db.session, Source, m.source_proxy, create=True)

        # If we are operating on a user, run the setup actions.
        setup_id = None
        if plugin_cls.setup_task is not None and self.user is not None:
            setup_id = self.run_task(plugin_hashkey, plugin_cls.setup_task.task_proxy)
        db.session.commit()
        return dict(task_id=setup_id)
Ejemplo n.º 9
0
    def add(self, plugin_hashkey):
        from app import db
        from core.plugins.loader import plugins
        from core.database.models import Metric, Source

        plugin_cls = plugins[plugin_hashkey]
        plugin = self.lookup_plugin(plugin_hashkey)
        model = self.get_scope_model()
        if plugin not in model.plugins:
            model.plugins.append(plugin)

        if plugin_cls.models is not None:
            for m in plugin_cls.models:
                # Register metrics and sources.
                get_cls(db.session, Metric, m.metric_proxy, create=True)
                get_cls(db.session, Source, m.source_proxy, create=True)

        # If we are operating on a user, run the setup actions.
        setup_id = None
        if plugin_cls.setup_task is not None and self.user is not None:
            setup_id = self.run_task(plugin_hashkey,
                                     plugin_cls.setup_task.task_proxy)
        db.session.commit()
        return dict(task_id=setup_id)