trending fixes

This commit is contained in:
Jack Robison 2021-08-30 19:36:14 -04:00 committed by Victor Shyba
parent 3800fb1ab0
commit da75968078
5 changed files with 19 additions and 17 deletions

View file

@ -520,7 +520,7 @@ class BlockProcessor:
# add the spike for trending # add the spike for trending
self.db_op_stack.append_op(self.db.prefix_db.trending_spike.pack_spike( self.db_op_stack.append_op(self.db.prefix_db.trending_spike.pack_spike(
height, claim_hash, tx_num, nout, txo.amount - previous_amount, half_life=self.env.trending_half_life height, claim_hash, tx_num, nout, txo.amount, half_life=self.env.trending_half_life
)) ))
def _add_support(self, height: int, txo: 'Output', tx_num: int, nout: int): def _add_support(self, height: int, txo: 'Output', tx_num: int, nout: int):

View file

@ -178,9 +178,8 @@ class SearchIndex:
}, slices=4, conflicts='proceed' }, slices=4, conflicts='proceed'
) )
self.logger.info("updated trending scores in %ims", int((time.perf_counter() - start) * 1000)) self.logger.info("updated trending scores in %ims", int((time.perf_counter() - start) * 1000))
whale_decay_factor = 2.0 ** ((-1 / self._trending_whale_half_life) + 1)
whale_decay_factor = 2 * (2.0 ** (-1 / self._trending_whale_half_life)) decay_factor = 2.0 ** ((-1 / self._trending_half_life) + 1)
decay_factor = 2 * (2.0 ** (-1 / self._trending_half_life))
decay_script = """ decay_script = """
if (ctx._source.trending_score == null) { ctx._source.trending_score = 0.0; } if (ctx._source.trending_score == null) { ctx._source.trending_score = 0.0; }
if ((-0.1 <= ctx._source.trending_score) && (ctx._source.trending_score <= 0.1)) { if ((-0.1 <= ctx._source.trending_score) && (ctx._source.trending_score <= 0.1)) {

View file

@ -1363,12 +1363,14 @@ class TrendingSpikePrefixRow(PrefixRow):
struct.Struct(b'>L20sLH').pack struct.Struct(b'>L20sLH').pack
] ]
def pack_spike(self, height: int, claim_hash: bytes, tx_num: int, position: int, amount: int, half_life: int, @classmethod
def pack_spike(cls, height: int, claim_hash: bytes, tx_num: int, position: int, amount: int, half_life: int,
depth: int = 0, subtract: bool = False) -> RevertablePut: depth: int = 0, subtract: bool = False) -> RevertablePut:
softened_change = (((amount * 1E-8) + 1E-8) ** 0.25).real softened_change = (((amount * 1E-8) + 1E-8) ** (1 / 4))
spike_mass = (-1.0 if subtract else 1.0) * softened_change * 2 * ((2.0 ** (-1 / half_life)) ** depth) spike_mass = softened_change * ((2.0 ** (-1 / half_life)) ** depth)
# trending_spike_height = self.height + delay_trending_spike(self.amount * 1E-8) if subtract:
return RevertablePut(*self.pack_item(height, claim_hash, tx_num, position, spike_mass)) spike_mass = -spike_mass
return RevertablePut(*cls.pack_item(height, claim_hash, tx_num, position, spike_mass))
@classmethod @classmethod
def pack_key(cls, height: int, claim_hash: bytes, tx_num: int, position: int): def pack_key(cls, height: int, claim_hash: bytes, tx_num: int, position: int):

View file

@ -5,7 +5,7 @@
# See the file "LICENCE" for information about the copyright # See the file "LICENCE" for information about the copyright
# and warranty status of this software. # and warranty status of this software.
import math
import re import re
import resource import resource
from os import environ from os import environ
@ -39,12 +39,13 @@ class Env:
self.obsolete(['UTXO_MB', 'HIST_MB', 'NETWORK']) self.obsolete(['UTXO_MB', 'HIST_MB', 'NETWORK'])
self.db_dir = self.required('DB_DIRECTORY') self.db_dir = self.required('DB_DIRECTORY')
self.db_engine = self.default('DB_ENGINE', 'leveldb') self.db_engine = self.default('DB_ENGINE', 'leveldb')
self.trending_algorithms = [ # self.trending_algorithms = [
trending for trending in set(self.default('TRENDING_ALGORITHMS', 'zscore').split(' ')) if trending # trending for trending in set(self.default('TRENDING_ALGORITHMS', 'zscore').split(' ')) if trending
] # ]
self.trending_half_life = float(self.string_amount('TRENDING_HALF_LIFE', "0.9")) self.trending_half_life = math.log2(0.1 ** (1 / (3 + self.integer('TRENDING_DECAY_RATE', 48)))) + 1
self.trending_whale_half_life = float(self.string_amount('TRENDING_WHALE_HALF_LIFE', "0.99")) self.trending_whale_half_life = math.log2(0.1 ** (1 / (3 + self.integer('TRENDING_WHALE_DECAY_RATE', 24)))) + 1
self.trending_whale_threshold = float(self.integer('TRENDING_WHALE_THRESHOLD', 10000)) self.trending_whale_threshold = float(self.integer('TRENDING_WHALE_THRESHOLD', 10000)) * 1E8
self.max_query_workers = self.integer('MAX_QUERY_WORKERS', None) self.max_query_workers = self.integer('MAX_QUERY_WORKERS', None)
self.individual_tag_indexes = self.boolean('INDIVIDUAL_TAG_INDEXES', True) self.individual_tag_indexes = self.boolean('INDIVIDUAL_TAG_INDEXES', True)
self.track_metrics = self.boolean('TRACK_METRICS', False) self.track_metrics = self.boolean('TRACK_METRICS', False)

View file

@ -897,7 +897,7 @@ class LBRYElectrumX(SessionBase):
'donation_address': env.donation_address, 'donation_address': env.donation_address,
'daily_fee': env.daily_fee, 'daily_fee': env.daily_fee,
'hash_function': 'sha256', 'hash_function': 'sha256',
'trending_algorithm': env.trending_algorithms[0] 'trending_algorithm': 'variable_decay'
}) })
async def server_features_async(self): async def server_features_async(self):