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
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
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
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
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
def data(self): return { "players": self.players, "match": serialize(self.match), "results": self.results.json(), "hands": self.read_hands() }
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)
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)
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
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
def serialize(self): first = Operation(ROBOT_NOTIFY_CAPABILITIES_HASH, '0', {'capabilitiesHash': self._capability_hash}) operations = [first] + self.__pending res = util.serialize(operations) return res
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
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
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)
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
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
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
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
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
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
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)
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
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
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
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
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
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')
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)
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)
def serialize(format="pretty-xml", filename=None): """Dummy function, see util.py""" util.serialize(format, filename)