def create_transaction(client, num_customers, max_txn_amount): # # This method is going to create a random transaction that moves a random amount # from a source customer to a destination customer. Prior to committing the transaction # a check will be performed to insure that the source customer has a sufficient balance # to cover the amount and not go into an overdrawn state. # uuid = uuid4().urn[9:] source_id = randint(1, num_customers) dest_id = randint(1, num_customers) while dest_id == source_id: dest_id = randint(1, num_customers) amount = randint(1, max_txn_amount) transaction = {"uuid": uuid, "sourceCust": source_id, "destCust": dest_id , "amount": amount} res = client.query( q.let( {"source_customer": q.get(q.match(q.index("customer_by_id"), source_id)), "dest_customer": q.get(q.match(q.index("customer_by_id"), dest_id))}, q.let( {"source_balance": q.select(["data", "balance"], q.var("source_customer")), "dest_balance": q.select(["data", "balance"], q.var("dest_customer"))}, q.let( {"new_source_balance": q.subtract(q.var("source_balance"), amount), "new_dest_balance": q.add(q.var("dest_balance"), amount)}, q.if_( q.gte(q.var("new_source_balance"), 0), q.do( q.create(q.class_("transactions"), {"data": transaction}), q.update(q.select("ref", q.var("source_customer")), {"data": {"txnID": uuid, "balance": q.var("new_source_balance")}}), q.update(q.select("ref", q.var("dest_customer")), {"data": {"txnID": uuid, "balance": q.var("new_dest_balance")}}) ), "Error. Insufficient funds." ) ) ) ) )
def wordPartsGenerator(word): return q.let( { "indexes": q.map_( # Reduce this array if you want less ngrams per word. # Setting it to [ 0 ] would only create the word itself, Setting it to [0, 1] would result in the word itself # and all ngrams that are one character shorter, etc.. lambda index: q.subtract(q.length(word), index), maxNgrams), "indexesFiltered": q.filter_( # left min parts length 3 lambda l: q.gte(l, 3), q.var('indexes')), "ngramsArray": q.distinct( q.union( q.map_(lambda l: q.ngram(q.lowercase(word), l, l), q.var('indexesFiltered')))) }, q.var('ngramsArray'))
def test_gte(self): self.assertJson(query.gte(1), '{"gte":1}') self.assertJson(query.gte(1, 2, 3), '{"gte":[1,2,3]}') self.assertJson(query.gte([1, 2, 3]), '{"gte":[1,2,3]}')
def test_gte(self): self.assertTrue(self._q(query.gte(1, 1)))