def deserialize(self, data): # neo-boa bug, Something is require here for some reason... print('deserialize_bytearray') collection_length_length = substr(data, 0, 1) collection_len = substr(data, 1, collection_length_length) new_collection = list(length=collection_len) offset = 1 + collection_length_length newdata = data[offset:] for i in range(0, collection_len): datalen_len = substr(newdata, 0, 1) data_len = substr(newdata, 1, datalen_len) start = 1 + datalen_len stop = start + data_len data = substr(newdata, start, data_len) new_collection[i] = data newdata = newdata[stop:] return new_collection
def get_all_drawings(): context = GetContext() result_iter = Find(context, OPERATOR) pre = len(OPERATOR) operators = [] while result_iter.IterNext(): operator = [] key = result_iter.IterKey() created_at = result_iter.IterValue() account = substr(key, pre, 20) game_no = substr(key, pre + 20, len(key) - (pre + 20)) # --- Get total entries of the game previous_ticket = concat(LAST_DRAWING_TICKET, game_no - 1) previous_ticket = Get(context, previous_ticket) last_ticket = concat(LAST_DRAWING_TICKET, game_no) last_ticket = Get(context, last_ticket) total_entries = last_ticket - previous_ticket # -- Get winning numbers winning_numbers_key = concat(WINNING_NUMBERS, game_no) winning_numbers = Get(context, winning_numbers_key) operator.append(game_no) operator.append(winning_numbers) operator.append(account) operator.append(total_entries) operator.append(created_at) operators.append(serialize_array(operator)) data = serialize_array(operators) return data
def get_all_tickets(): context = GetContext() result_iter = Find(context, TICKET) pre = len(TICKET) tickets = [] while result_iter.IterNext(): key = result_iter.IterKey() val = result_iter.IterValue() key_length = len(key) ticket = deserialize_bytearray(val) ticket_no = substr(key, pre, key_length) ticket.append(ticket_no) rank = get_rank(ticket_no) ticket.append(rank) tickets.append(serialize_array(ticket)) return serialize_array(tickets)
def deserialize_bytearray(data): # ok this is weird. if you remove this print statement, it stops working :/ print("deserializing data...") # get length of length collection_length_length = substr(data, 0, 1) # get length of collection collection_len = substr(data, 1, collection_length_length) # create a new collection new_collection = list(length=collection_len) # calculate offset offset = 1 + collection_length_length # trim the length data newdata = data[offset:] for i in range(0, collection_len): # get the data length length itemlen_len = substr(newdata, 0, 1) # get the length of the data item_len = substr(newdata, 1, itemlen_len) start = 1 + itemlen_len end = start + item_len # get the data item = substr(newdata, start, item_len) # store it in collection new_collection[i] = item # trim the data newdata = newdata[end:] return new_collection
def get_all_verifying(): context = GetContext() result_iter = Find(context, VERIFIER) pre = len(VERIFIER) verifiers = [] while result_iter.IterNext(): verifier = [] key = result_iter.IterKey() created_at = result_iter.IterValue() account = substr(key, pre, 20) ticket_no = substr(key, pre + 20, len(key) - (pre + 20)) rank = get_rank(ticket_no) verifier.append(ticket_no) verifier.append(account) verifier.append(rank) verifier.append(created_at) verifiers.append(serialize_array(verifier)) data = serialize_array(verifiers) return data
def stringCompare(Str): allow = { "a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6, "g": 7, "h": 8, "i": 9, "j": 10, "k": 11, "l": 12, "m": 13, "n": 14, "o": 15, "p": 16, "q": 17, "r": 18, "s": 19, "t": 20, "u": 21, "v": 22, "w": 23, "x": 24, "y": 25, "z": 26, "-": 27, "1": 28, "2": 29, "3": 30, "4": 31, "5": 32, "6": 33, "7": 34, "8": 39, "9": 40, "0": 41 } for i in range(0, len(Str)): if not allow.has_key(substr(Str, i, 1)): return True return False
def get_all_operators_by_player(account): context = GetContext() iter_key = concat(OPERATOR, account) pre = len(iter_key) result_iter = Find(context, iter_key) operators = [] while result_iter.IterNext(): operator = [] key = result_iter.IterKey() created_at = result_iter.IterValue() key_length = len(key) game_no = substr(key, pre, key_length) previous_ticket = concat(LAST_DRAWING_TICKET, game_no - 1) previous_ticket = Get(context, previous_ticket) last_ticket = concat(LAST_DRAWING_TICKET, game_no) last_ticket = Get(context, last_ticket) operator.append(game_no) operator.append(last_ticket - previous_ticket) operator.append(created_at) operators.append(serialize_array(operator)) data = serialize_array(operators) return data
def get_all_verifiers_by_player(account): context = GetContext() iter_key = concat(VERIFIER, account) pre = len(iter_key) result_iter = Find(context, iter_key) verifiers = [] while result_iter.IterNext(): verifier = [] key = result_iter.IterKey() created_at = result_iter.IterValue() key_length = len(key) ticket_no = substr(key, pre, key_length) rank = get_rank(ticket_no) verifier.append(ticket_no) verifier.append(rank) verifier.append(created_at) verifiers.append(serialize_array(verifier)) data = serialize_array(verifiers) return data