Beispiel #1
0
 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
Beispiel #2
0
 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]
     dpay = self.own_dpay[index]
     bbd = self.own_bbd[index]
     sum_in = sum([din[key].amount for key in din])
     sum_out = sum([dout[key].amount for key in dout])
     bp_in = self.dpay.vests_to_sp(sum_in, timestamp=ts)
     bp_out = self.dpay.vests_to_sp(sum_out, timestamp=ts)
     bp_own = self.dpay.vests_to_sp(own, timestamp=ts)
     bp_eff = bp_own + bp_in - bp_out
     return {
         "timestamp": ts,
         "vests": own,
         "delegated_vests_in": din,
         "delegated_vests_out": dout,
         "bp_own": bp_own,
         "bp_eff": bp_eff,
         "dpay": dpay,
         "bbd": bbd,
         "index": index
     }
Beispiel #3
0
 def reset(self):
     """ Resets the arrays not the stored account history
     """
     self.own_vests = [Amount("0 VESTS", dpay_instance=self.dpay)]
     self.own_dpay = [Amount("0 BEX", dpay_instance=self.dpay)]
     self.own_bbd = [Amount("0 BBD", dpay_instance=self.dpay)]
     self.delegated_vests_in = [{}]
     self.delegated_vests_out = [{}]
     self.timestamps = [addTzInfo(datetime(1970, 1, 1, 0, 0, 0, 0))]
     import dpaygobase.operationids
     self.ops_statistics = dpaygobase.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_SP_timestamp = []
     self.curation_per_1000_SP = []
     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 = []
Beispiel #4
0
 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
Beispiel #5
0
 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)