Esempio n. 1
0
 def filter(cls, instance_name, **kwargs):
     if 'dbcache' not in this_thread.misc:
         this_thread.misc['dbcache'] = {}
     listobj = DAList(instance_name, object_type=cls, auto_gather=False)
     filters = []
     for key, val in kwargs.items():
         if not hasattr(cls._model, key):
             raise Exception("filter: class " + cls.__name__ +
                             " does not have column " + key)
         filters.append(getattr(cls._model, key) == val)
     for db_entry in list(
             cls._session.query(cls._model).filter(*filters).order_by(
                 cls._model.id).all()):
         if cls._model.__name__ in this_thread.misc[
                 'dbcache'] and db_entry.id in this_thread.misc['dbcache'][
                     cls._model.__name__]:
             listobj.append(this_thread.misc['dbcache'][cls._model.__name__]
                            [db_entry.id])
         else:
             obj = listobj.appendObject()
             obj.id = db_entry.id
             db_values = {}
             for column in cls._model.__dict__.keys():
                 if column == 'id' or column.startswith('_'):
                     continue
                 db_values[column] = getattr(db_entry, column)
                 if db_values[column] is not None:
                     obj.db_set(column, db_values[column])
             obj._orig = db_values
             obj.db_cache()
     listobj.gathered = True
     return listobj
Esempio n. 2
0
 def classified_entries(self, key=None):
     self._initialize()
     results = DAList()
     results.gathered = True
     results.set_random_instance_name()
     if key is None:
         query = MachineLearning.query.filter_by(
             group_id=self.group_id,
             active=True).order_by(MachineLearning.id).all()
     else:
         query = MachineLearning.query.filter_by(
             group_id=self.group_id, active=True,
             key=key).order_by(MachineLearning.id).all()
     for entry in query:
         results.appendObject(
             MachineLearningEntry,
             ml=self,
             id=entry.id,
             independent=fix_pickle_obj(
                 codecs.decode(
                     bytearray(entry.independent, encoding='utf-8'),
                     'base64')),
             dependent=fix_pickle_obj(
                 codecs.decode(bytearray(entry.dependent, encoding='utf-8'),
                               'base64')),
             info=fix_pickle_obj(
                 codecs.decode(bytearray(entry.info, encoding='utf-8'),
                               'base64'))
             if entry.info is not None else None,
             create_time=entry.create_time,
             key=entry.key)
     return results
Esempio n. 3
0
 def all(cls, instance_name=None):
     if 'dbcache' not in this_thread.misc:
         this_thread.misc['dbcache'] = {}
     if instance_name:
         listobj = DAList(instance_name, object_type=cls)
     else:
         listobj = DAList(object_type=cls)
         listobj.set_random_instance_name()
     for db_entry in list(
             cls._session.query(cls._model).order_by(cls._model.id).all()):
         if cls._model.__name__ in this_thread.misc[
                 'dbcache'] and db_entry.id in this_thread.misc['dbcache'][
                     cls._model.__name__]:
             listobj.append(this_thread.misc['dbcache'][cls._model.__name__]
                            [db_entry.id])
         else:
             obj = listobj.appendObject()
             obj.id = db_entry.id
             db_values = {}
             for column in cls._model.__dict__.keys():
                 if column == 'id' or column.startswith('_'):
                     continue
                 db_values[column] = getattr(db_entry, column)
                 if db_values[column] is not None:
                     obj.db_set(column, db_values[column])
             obj._orig = db_values
             obj.db_cache()
     listobj.gathered = True
     return listobj
Esempio n. 4
0
 def unclassified_entries(self, key=None):
     self._initialize()
     results = DAList()._set_instance_name_for_method()
     results.gathered = True
     if key is None:
         query = db.session.execute(
             select(MachineLearning).filter_by(
                 group_id=self.group_id,
                 active=False).order_by(MachineLearning.id)).scalars()
     else:
         query = db.session.execute(
             select(MachineLearning).filter_by(
                 group_id=self.group_id, key=key,
                 active=False).order_by(MachineLearning.id)).scalars()
     for entry in query:
         results.appendObject(
             MachineLearningEntry,
             ml=self,
             id=entry.id,
             independent=fix_pickle_obj(
                 codecs.decode(
                     bytearray(entry.independent, encoding='utf-8'),
                     'base64')),
             create_time=entry.create_time,
             key=entry.key,
             info=fix_pickle_obj(
                 codecs.decode(bytearray(entry.info, encoding='utf-8'),
                               'base64'))
             if entry.info is not None else None)
     return results
Esempio n. 5
0
 def unclassified_entries(self, key=None):
     self._initialize()
     results = DAList()._set_instance_name_for_method()
     results.gathered = True
     if key is None:
         query = MachineLearning.query.filter_by(group_id=self.group_id, active=False).order_by(MachineLearning.id).all()
     else:
         query = MachineLearning.query.filter_by(group_id=self.group_id, key=key, active=False).order_by(MachineLearning.id).all()
     for entry in query:
         results.appendObject(MachineLearningEntry, ml=self, id=entry.id, independent=pickle.loads(codecs.decode(entry.independent, 'base64')), create_time=entry.create_time, key=entry.key)
     return results
Esempio n. 6
0
 def unclassified_entries(self, key=None):
     self._initialize()
     results = DAList()._set_instance_name_for_method()
     results.gathered = True
     if key is None:
         query = MachineLearning.query.filter_by(group_id=self.group_id, active=False).order_by(MachineLearning.id).all()
     else:
         query = MachineLearning.query.filter_by(group_id=self.group_id, key=key, active=False).order_by(MachineLearning.id).all()
     for entry in query:
         results.appendObject(MachineLearningEntry, ml=self, id=entry.id, independent=fix_pickle_obj(codecs.decode(bytearray(entry.independent, encoding='utf-8'), 'base64')), create_time=entry.create_time, key=entry.key, info=fix_pickle_obj(codecs.decode(bytearray(entry.info, encoding='utf-8'), 'base64')) if entry.info is not None else None)
     return results
Esempio n. 7
0
 def classified_entries(self, key=None):
     self._initialize()
     results = DAList()
     results.gathered = True
     results.set_random_instance_name()
     if key is None:
         query = MachineLearning.query.filter_by(group_id=self.group_id, active=True).order_by(MachineLearning.id).all()
     else:
         query = MachineLearning.query.filter_by(group_id=self.group_id, active=True, key=key).order_by(MachineLearning.id).all()
     for entry in query:
         results.appendObject(MachineLearningEntry, ml=self, id=entry.id, independent=pickle.loads(codecs.decode(entry.independent, 'base64')), dependent=pickle.loads(codecs.decode(entry.dependent, 'base64')), info=pickle.loads(codecs.decode(entry.info, 'base64')) if entry.info is not None else None, create_time=entry.create_time, key=entry.key)
     return results