commit 016da073b7ae2188c596cf2e3f2cdf7d627b3770
parent 23a1d7ccc9fd28428289424c77d32767db404e60
Author: lash <dev@holbrook.no>
Date: Thu, 7 Apr 2022 13:54:45 +0000
Add moving average, remove faulty names for previous averages
Diffstat:
2 files changed, 18 insertions(+), 29 deletions(-)
diff --git a/eth_stat_syncer/runnable/tracker.py b/eth_stat_syncer/runnable/tracker.py
@@ -44,7 +44,7 @@ argparser.add_argument('-i', '--chain-spec', dest='i', default='evm:ethereum:1',
argparser.add_argument('--moving', action='append', default=[], type=int, help='add moving average')
argparser.add_argument('--offset', type=int, default=0, help='Start sync on this block')
argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration')
-argparser.add_argument('--cache-dir', dest='cache_dir', type=str, help='Directory to store tx data')
+argparser.add_argument('--cache-dir', dest='cache_dir', type=str, help='Directory to store gas cache')
argparser.add_argument('--state-dir', dest='state_dir', default=exec_dir, type=str, help='Directory to store sync state')
argparser.add_argument('--session-id', dest='session_id', type=str, help='Use state from specified session id')
argparser.add_argument('-v', action='store_true', help='be verbose')
@@ -100,7 +100,7 @@ class EthChainInterface(ChainInterface):
def main():
- gas_store = RunStore(basedir=config.get('STORE_BASE_DIR'))
+ gas_store = RunStore(basedir=config.get('_CACHE_DIR'))
cap = 360
try:
v = max(config.get('_MOVING'))
@@ -130,23 +130,6 @@ def main():
r = drv.run(conn)
-# if config.get('_START') != None:
-# offset = start_block - config.get('_START')
-# syncer_backend = MemBackend.custom(chain_spec, start_block)
-# syncer_backend.set(offset, 0)
-# syncer = HistorySyncer(syncer_backend, chain_interface, block_callback=gas_aggregator.block_callback)
-# syncer.add_filter(gas_filter)
-# try:
-# syncer.loop(0.0, conn)
-# except NoBlockForYou:
-# logg.info('history done at {}'.format(syncer.backend.get()))
-
-# syncer_backend = MemBackend(chain_spec, None)
-# syncer_backend.set(start_block + 1, 0)
-# syncer = HeadSyncer(syncer_backend, chain_interface, block_callback=gas_aggregator.block_callback)
-# syncer.add_filter(gas_filter)
-# syncer.loop(1.0, conn)
-
if __name__ == '__main__':
main()
diff --git a/eth_stat_syncer/store.py b/eth_stat_syncer/store.py
@@ -104,25 +104,28 @@ class GasAggregator:
self.aggr += v
self.avg = int(self.aggr / self.count)
logg.info('added {} to aggregate {} new average {} from {} samples'.format(v, self.aggr, self.avg, self.count))
+
return True
def get(self, n=0):
if n == 0:
- n = self.capacity
+ n = self.buffer_capacity
+ if n > self.count:
+ n = self.count
aggrs = {
'average': 0,
'low': 0,
'high': 0,
}
+
for o in [
(self.buffer_average, 'average',),
(self.buffer_low, 'low',),
(self.buffer_high, 'high',),
]:
cursor = self.buffer_cursor
- aggr = 0
i = 0
while i < n:
v = o[0][cursor]
@@ -131,23 +134,26 @@ class GasAggregator:
if cursor < 0:
cursor = self.buffer_capacity - 1
i += 1
-
- return {
+
+ r = {
'average': int(aggrs['average']/ n),
'high': int(aggrs['high']/ n),
'low': int(aggrs['low']/ n),
}
+ logg.debug('calc for {}: avg {} high {} low {}'.format(n, r['average'], r['high'], r['low']))
+ return r
def block_callback(self, block, tx):
- logg.info('synced {}'.format(block))
+ tx_count = len(block.txs)
+ logg.info('synced {} with {} txs'.format(block, tx_count))
if self.process():
- last = self.get(1)
+ last = self.get(tx_count)
self.store.put(last, 'block')
- minute = self.get(6)
- self.store.put(minute, 'minute')
- hour = self.get(360)
- self.store.put(hour, 'hour')
self.store.put({
'average': int(self.aggr / self.count),
}, 'all')
+
+ for v in self.moving:
+ r = self.get(v)
+ self.store.put(r, str(v))