Example #1
0
 def put(self, key, value, raw_key=False, raw_value=False):
     """Store any Python object into a hash database object."""
     (c_key, c_key_len) = util.serialize(key, raw_key)
     (c_value, c_value_len) = util.serialize(value, raw_value)
     result = tc.hdb_put(self.db, c_key, c_key_len, c_value, c_value_len)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
Example #2
0
 def put(self, key, value, raw_key=False, raw_value=False):
     """Store any Python object into an abstract database object."""
     (c_key, c_key_len) = util.serialize(key, raw_key)
     (c_value, c_value_len) = util.serialize(value, raw_value)
     result = tc.adb_put(self.db, c_key, c_key_len, c_value, c_value_len)
     if not result:
         self._raise('Error putting a Python object in an abstract ' \
                         'database object')
     return result
Example #3
0
 def putcat(self, key, value, raw_key=False, raw_value=False):
     """Concatenate an object value at the end of the existing
     record in a hash database object."""
     (c_key, c_key_len) = util.serialize(key, raw_key)
     (c_value, c_value_len) = util.serialize(value, raw_value)
     result = tc.hdb_putcat(self.db, c_key, c_key_len, c_value, c_value_len)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
Example #4
0
 def putcat(self, key, value, raw_key=False, raw_value=False):
     """Concatenate an object value at the end of the existing
     record in an abstract database object."""
     (c_key, c_key_len) = util.serialize(key, raw_key)
     (c_value, c_value_len) = util.serialize(value, raw_value)
     result = tc.adb_putcat(self.db, c_key, c_key_len, c_value, c_value_len)
     if not result:
         self._raise('Error concatenating a Python object in an abstract ' \
                         'database object')
     return result
Example #5
0
 def get_col(self, key, col, default=None, raw_key=False, value_type=None):
     """Retrieve the value of a column of a record in a table
     database object."""
     (c_key, c_key_len) = util.serialize(key, raw_key)
     (c_col, c_col_len) = util.serialize(col, as_raw=True)
     (c_value, c_value_len) = tc.tdb_get4(self.db, c_key, c_key_len, c_col,
                                          c_col_len)
     if c_value:
         value = util.deserialize(c_value, c_value_len, value_type)
     else:
         value = default
     return value
Example #6
0
 def data(self):
     return {
         "players": self.players,
         "match": serialize(self.match),
         "results": self.results.json(),
         "hands": self.read_hands()
     }
Example #7
0
 def _getitem(self, key, raw_key=False, value_type=None):
     """Retrieve a Python object in a hash database object."""
     (c_key, c_key_len) = util.serialize(key, raw_key)
     (c_value, c_value_len) = tc.hdb_get(self.db, c_key, c_key_len)
     if not c_value:
         raise KeyError(key)
     return util.deserialize(c_value, c_value_len, value_type)
Example #8
0
 def _getitem(self, key, raw_key=False, schema=None):
     """"Retrieve a record in a table database object."""
     (c_key, c_key_len) = util.serialize(key, raw_key)
     cols_tcmap = tc.tdb_get(self.db, c_key, c_key_len)
     if not cols_tcmap:
         raise KeyError(key)
     return util.deserialize_tcmap(cols_tcmap, schema)
Example #9
0
def get_aic_bic(img):
    subplot_data = img

    ctype = ['spherical', 'tied', 'diag', 'full']

    aic_res = np.zeros(5)
    bic_res = np.zeros(5)

    res_idx = 0

    for ncomponents in range(1, 6):
        X_train = np.ceil(serialize(subplot_data))
        # clf = mixture.DPGMM(n_components=3, covariance_type='full')
        clf = mixture.GMM(n_components=ncomponents, covariance_type=ctype[2],
                          n_iter=100)
        clf.fit(X_train)

        aic_res[res_idx] = clf.aic(X_train)
        bic_res[res_idx] = clf.bic(X_train)
        # print clf.weights_
        # print clf.means_
        # print clf.get_params()
        # x = np.linspace(0.0, subplot_data.shape[0])
        # y = np.linspace(0.0, subplot_data.shape[1])
        # 	X, Y = np.meshgrid(x, y)
        # 	XX = np.c_[X.ravel(), Y.ravel()]
        # 	#Z = np.log(-clf.score_samples(XX)[0])
        # 	Z = np.log(-clf.score_samples(XX)[0])
        # 	Z = Z.reshape(X.shape)

        res_idx += 1

    return aic_res, bic_res
Example #10
0
 def out(self, key, as_raw=False):
     """Remove a Python object of a hash database object."""
     (c_key, c_key_len) = util.serialize(key, as_raw)
     result = tc.hdb_out(self.db, c_key, c_key_len)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
Example #11
0
 def serialize(self):
   first = Operation(ROBOT_NOTIFY_CAPABILITIES_HASH,
                     '0',
                     {'capabilitiesHash': self._capability_hash})
   operations = [first] + self.__pending
   res = util.serialize(operations)
   return res
Example #12
0
 def vsiz(self, key, as_raw=False):
     """Get the size of the value of a Python object in a hash
     database object."""
     (c_key, c_key_len) = util.serialize(key, as_raw)
     result = tc.hdb_vsiz(self.db, c_key, c_key_len)
     if result == -1:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
Example #13
0
 def finished(self, user):
     matches = Match.query.filter(Match.finished.isnot(None)) \
         .order_by(Match.finished.desc()) \
         .offset(self.offset) \
         .limit(25) \
         .all()
     pagination = {'offset': self.offset, 'limit': 25}
     return pagination, [serialize(m) for m in matches]
 def serialize(self):
   first = Operation(ROBOT_NOTIFY_CAPABILITIES_HASH,
                     '0',
                     {'capabilitiesHash': self._capability_hash,
                      'protocolVersion': PROTOCOL_VERSION})
   operations = [first] + self.__pending
   res = util.serialize(operations)
   return res
Example #15
0
 def fwmkeys(self, prefix, max_=-1, as_raw=True):
     """Get forward matching string keys in a hash database object."""
     (c_prefix, c_prefix_len) = util.serialize(prefix, as_raw)
     tclist_objs = tc.hdb_fwmkeys(self.db, c_prefix, c_prefix_len, max_)
     if not tclist_objs:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     as_type = util.get_type(prefix, as_raw)
     return util.deserialize_tclist(tclist_objs, as_type)
Example #16
0
 def put(self, key, value, as_raw=False):
     """Store any Python object into a fixed-length database
     object."""
     (c_value, c_value_len) = util.serialize(value, as_raw)
     result = tc.fdb_put(self.db, key, c_value, c_value_len)
     if not result:
         raise tc.TCException(tc.fdb_errmsg(tc.fdb_ecode(self.db)))
     return result
Example #17
0
 def putcat(self, key, value, as_raw=False):
     """Concatenate a Python object value at the end of the
     existing record in a fixed-length database object."""
     (c_value, c_value_len) = util.serialize(value, as_raw)
     result = tc.fdb_putcat(self.db, key, c_value, c_value_len)
     if not result:
         raise tc.TCException(tc.fdb_errmsg(tc.fdb_ecode(self.db)))
     return result
Example #18
0
 def add_float(self, key, num, as_raw=False):
     """Add a real number to a record in a hash database object."""
     assert isinstance(num, float), 'Value is not a float'
     (c_key, c_key_len) = util.serialize(key, as_raw)
     result = tc.hdb_adddouble(self.db, c_key, c_key_len, num)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
Example #19
0
 def out(self, key, as_raw=False):
     """Remove a Python object of an abstract database object."""
     (c_key, c_key_len) = util.serialize(key, as_raw)
     result = tc.adb_out(self.db, c_key, c_key_len)
     if not result:
         self._raise('Error deleting a Python object in an abstract ' \
                         'database object.');
     return result
Example #20
0
 def has_key(self, key, raw_key=False):
     """Return True if abstract database object has the key."""
     result = False
     (c_key, c_key_len) = util.serialize(key, raw_key)
     (c_value, _) = tc.adb_get(self.db, c_key, c_key_len)
     if c_value:
         result = True
     return result
Example #21
0
 def putcat(self, key, cols, raw_key=False, raw_cols=False):
     """Concatenate columns of the existing record in a table
     database object."""
     (c_key, c_key_len) = util.serialize(key, raw_key)
     cols_tcmap = util.serialize_tcmap(cols, raw_cols)
     result = tc.tdb_putcat(self.db, c_key, c_key_len, cols_tcmap)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Example #22
0
 def create(self, db):
     data = PlayerData(self.user)
     if len(data.bots) >= self.user.max_bots:
         raise Exception("Already have too many bots")
     app.logger.error("{} just created a new bot named {}"
                      .format(self.user.username, self.bot.name))
     db.session.add(self.bot)
     db.session.commit()
     return serialize(self.bot)
Example #23
0
 def add_float(self, key, num, as_raw=False):
     """Add a real number to a record in an abstract database object."""
     assert isinstance(num, float), 'Value is not a float'
     (c_key, c_key_len) = util.serialize(key, as_raw)
     result = tc.adb_adddouble(self.db, c_key, c_key_len, num)
     if not result:
         self._raise('Error adding a real number to a record in an ' \
                         'abstract database object.')
     return result
Example #24
0
 def add_int(self, key, num, as_raw=False):
     """Add an integer to a record in an abstract database object."""
     assert isinstance(num, int), 'Value is not an integer'
     (c_key, c_key_len) = util.serialize(key, as_raw)
     result = tc.adb_addint(self.db, c_key, c_key_len, num)
     if not result:
         self._raise('Error adding an integer to a record in an abstract ' \
                         'database object.')
     return result
Example #25
0
File: ops.py Project: adajw/Laura
 def serialize(self, method_prefix=''):
   first = Operation(ROBOT_NOTIFY,
                     NOTIFY_OP_ID,
                     {'capabilitiesHash': self._capability_hash,
                      'protocolVersion': PROTOCOL_VERSION})
   operations = [first] + self.__pending
   return [op.serialize(method_prefix=method_prefix) for op in operations]
   res = util.serialize(operations)
   return res
Example #26
0
 def vsiz(self, key, as_raw=False):
     """Get the size of the value of a Python object in an abstract
     database object."""
     (c_key, c_key_len) = util.serialize(key, as_raw)
     result = tc.adb_vsiz(self.db, c_key, c_key_len)
     if result == -1:
         self._raise('Error getting the size of a Python object in an ' \
                         ' abstract database object.');
     return result
Example #27
0
 def put(self, key, cols, raw_key=False, raw_cols=False):
     """Store a record into a table database object."""
     assert isinstance(cols, dict)
     (c_key, c_key_len) = util.serialize(key, raw_key)
     cols_tcmap = util.serialize_tcmap(cols, raw_cols)
     result = tc.tdb_put(self.db, c_key, c_key_len, cols_tcmap)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Example #28
0
 def add_int(self, key, num, as_raw=False):
     """Add an integer to a column of a record in a table database
     object."""
     assert isinstance(num, int), 'Value is not an integer'
     (c_key, c_key_len) = util.serialize(key, as_raw)
     result = tc.tdb_addint(self.db, c_key, c_key_len, num)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
 def testSerializeLine(self):
   line = element.Line(element.Line.TYPE_H1, alignment=element.Line.ALIGN_LEFT)
   s = util.serialize(line)
   k = s.keys()
   k.sort()
   # we should really only have three things to serialize
   props = s['properties']
   self.assertEquals(len(props), 2)
   self.assertEquals(props['alignment'], 'l')
   self.assertEquals(props['lineType'], 'h1')
Example #30
0
 def fwmkeys(self, prefix, max_=-1, as_raw=True):
     """Get forward matching string keys in an abstract database
     object."""
     (c_prefix, c_prefix_len) = util.serialize(prefix, as_raw)
     tclist_objs = tc.adb_fwmkeys(self.db, c_prefix, c_prefix_len, max_)
     if not tclist_objs:
         self._raise('Error forward matching string keys in an abstract ' \
                         'database object.')
     as_type = util.get_type(prefix, as_raw)
     return util.deserialize_tclist(tclist_objs, as_type)
Example #31
0
 def putkeep(self, key, value, raw_key=False, raw_value=False):
     """Store a new Python object into an abstract database object."""
     (c_key, c_key_len) = util.serialize(key, raw_key)
     (c_value, c_value_len) = util.serialize(value, raw_value)
     return tc.adb_putkeep(self.db, c_key, c_key_len, c_value, c_value_len)
Example #32
0
def serialize(format="pretty-xml", filename=None):
    """Dummy function, see util.py"""
    util.serialize(format, filename)