def get_ops(self, start=None, stop=None, use_block_num=True, only_ops=[], exclude_ops=[]): """ Returns ops in the given range""" if start is not None: start = addTzInfo(start) if stop is not None: stop = addTzInfo(stop) for op in self: if use_block_num and start is not None and isinstance(start, int): if op["block"] < start: continue elif not use_block_num and start is not None and isinstance(start, int): if op["index"] < start: continue elif start is not None and isinstance(start, (datetime, date, time)): if start > formatTimeString(op["timestamp"]): continue if use_block_num and stop is not None and isinstance(stop, int): if op["block"] > stop: continue elif not use_block_num and stop is not None and isinstance(stop, int): if op["index"] > stop: continue elif stop is not None and isinstance(stop, (datetime, date, time)): if stop < formatTimeString(op["timestamp"]): continue if exclude_ops and op["type"] in exclude_ops: continue if not only_ops or op["type"] in only_ops: yield op
def search(self, search_str, start=None, stop=None, use_block_num=True): """ Returns ops in the given range""" ops = [] if start is not None: start = addTzInfo(start) if stop is not None: stop = addTzInfo(stop) for op in self: if use_block_num and start is not None and isinstance(start, int): if op["block"] < start: continue elif not use_block_num and start is not None and isinstance(start, int): if op["index"] < start: continue elif start is not None and isinstance(start, (datetime, date, time)): if start > formatTimeString(op["timestamp"]): continue if use_block_num and stop is not None and isinstance(stop, int): if op["block"] > stop: continue elif not use_block_num and stop is not None and isinstance(stop, int): if op["index"] > stop: continue elif stop is not None and isinstance(stop, (datetime, date, time)): if stop < formatTimeString(op["timestamp"]): continue op_string = json.dumps(list(op.values())) if re.search(search_str, op_string): ops.append(op) return ops
def get_data(self, timestamp=None, index=0): """ Returns snapshot for given timestamp""" if timestamp is None: timestamp = datetime.utcnow() timestamp = addTzInfo(timestamp) # Find rightmost value less than x i = bisect_left(self.timestamps, timestamp) if i: index = i - 1 else: return {} ts = self.timestamps[index] own = self.own_vests[index] din = self.delegated_vests_in[index] dout = self.delegated_vests_out[index] hive = self.own_steem[index] hbd = self.own_sbd[index] sum_in = sum([din[key].amount for key in din]) sum_out = sum([dout[key].amount for key in dout]) hp_in = self.hive.vests_to_hp(sum_in, timestamp=ts) hp_out = self.hive.vests_to_hp(sum_out, timestamp=ts) hp_own = self.hive.vests_to_hp(own, timestamp=ts) hp_eff = hp_own + hp_in - hp_out return {"timestamp": ts, "vests": own, "delegated_vests_in": din, "delegated_vests_out": dout, "hp_own": hp_own, "hp_eff": hp_eff, "hive": hive, "hbd": hbd, "index": index}
def reset(self): """ Resets the arrays not the stored account history """ self.own_vests = [Amount(0, self.hive.vests_symbol, hive_instance=self.hive)] self.own_steem = [Amount(0, self.hive.steem_symbol, hive_instance=self.hive)] self.own_sbd = [Amount(0, self.hive.sbd_symbol, hive_instance=self.hive)] self.delegated_vests_in = [{}] self.delegated_vests_out = [{}] self.timestamps = [addTzInfo(datetime(1970, 1, 1, 0, 0, 0, 0))] import bhivebase.operationids self.ops_statistics = bhivebase.operationids.operations.copy() for key in self.ops_statistics: self.ops_statistics[key] = 0 self.reward_timestamps = [] self.author_rewards = [] self.curation_rewards = [] self.curation_per_1000_HP_timestamp = [] self.curation_per_1000_HP = [] self.out_vote_timestamp = [] self.out_vote_weight = [] self.in_vote_timestamp = [] self.in_vote_weight = [] self.in_vote_rep = [] self.in_vote_rshares = [] self.vp = [] self.vp_timestamp = [] self.rep = [] self.rep_timestamp = []
def test_formatTimeString(self): t = "2018-07-10T10:08:39" t = formatTimeString(t) t2 = addTzInfo(datetime(2018, 7, 10, 10, 8, 39)) self.assertEqual(t, t2)