renormalization

This commit is contained in:
Jack Robison 2021-09-07 19:27:45 -04:00
parent 57028eab39
commit 32f8c9e59f
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
3 changed files with 41 additions and 34 deletions

View file

@ -30,7 +30,7 @@ INDEX_DEFAULT_SETTINGS = {
"height": {"type": "integer"}, "height": {"type": "integer"},
"claim_type": {"type": "byte"}, "claim_type": {"type": "byte"},
"censor_type": {"type": "byte"}, "censor_type": {"type": "byte"},
"trending_score": {"type": "float"}, "trending_score": {"type": "double"},
"release_time": {"type": "long"} "release_time": {"type": "long"}
} }
} }

View file

@ -162,7 +162,7 @@ class SearchIndex:
update_trending_score_script = """ update_trending_score_script = """
double softenLBC(double lbc) { Math.pow(lbc, 1.0f / 3.0f) } double softenLBC(double lbc) { Math.pow(lbc, 1.0f / 3.0f) }
double inflateUnits(int height) { double inflateUnits(int height) {
int renormalizationPeriod = 300000; int renormalizationPeriod = 100000;
double doublingRate = 400.0f; double doublingRate = 400.0f;
Math.pow(2.0, (height % renormalizationPeriod) / doublingRate) Math.pow(2.0, (height % renormalizationPeriod) / doublingRate)
} }
@ -186,17 +186,18 @@ class SearchIndex:
} }
} }
for (i in params.src.changes) { for (i in params.src.changes) {
double units = inflateUnits(i.height);
if (i.added) { if (i.added) {
if (ctx._source.trending_score == null) { if (ctx._source.trending_score == null) {
ctx._source.trending_score = spikeMass(i.prev_amount, i.prev_amount + i.new_amount); ctx._source.trending_score = (units * spikeMass(i.prev_amount, i.prev_amount + i.new_amount));
} else { } else {
ctx._source.trending_score += spikeMass(i.prev_amount, i.prev_amount + i.new_amount); ctx._source.trending_score += (units * spikeMass(i.prev_amount, i.prev_amount + i.new_amount));
} }
} else { } else {
if (ctx._source.trending_score == null) { if (ctx._source.trending_score == null) {
ctx._source.trending_score = spikeMass(i.prev_amount, i.prev_amount - i.new_amount); ctx._source.trending_score = (units * spikeMass(i.prev_amount, i.prev_amount - i.new_amount));
} else { } else {
ctx._source.trending_score += spikeMass(i.prev_amount, i.prev_amount - i.new_amount); ctx._source.trending_score += (units * spikeMass(i.prev_amount, i.prev_amount - i.new_amount));
} }
} }
} }

View file

@ -983,42 +983,48 @@ class ResolveClaimTakeovers(BaseResolveTestCase):
claim_id=claim_id claim_id=claim_id
))[0][0]['trending_score'] ))[0][0]['trending_score']
claim_id1 = (await self.stream_create('derp', '2.0'))['outputs'][0]['claim_id'] claim_id1 = (await self.stream_create('derp', '1.0'))['outputs'][0]['claim_id']
claim_id2 = (await self.stream_create('derp', '2.0', allow_duplicate_name=True))['outputs'][0]['claim_id'] claim_id2 = (await self.stream_create('derp', '1.0', allow_duplicate_name=True))['outputs'][0]['claim_id']
claim_id3 = (await self.stream_create('derp', '2.0', allow_duplicate_name=True))['outputs'][0]['claim_id'] claim_id3 = (await self.stream_create('derp', '1.0', allow_duplicate_name=True))['outputs'][0]['claim_id']
claim_id4 = (await self.stream_create('derp', '2.0', allow_duplicate_name=True))['outputs'][0]['claim_id'] claim_id4 = (await self.stream_create('derp', '1.0', allow_duplicate_name=True))['outputs'][0]['claim_id']
claim_id5 = (await self.stream_create('derp', '1.0', allow_duplicate_name=True))['outputs'][0]['claim_id']
COIN = 100_000_000 COIN = 1E9
for height in range(2000): height = 99000
self.conductor.spv_node.server.bp._add_claim_activation_change_notification(
claim_id1, height + 100_000, True, 1_000_000 * COIN * (height + 1), 1_000_000 * COIN
)
self.conductor.spv_node.server.bp._add_claim_activation_change_notification(
claim_id2, height + 100_000, True, 100_000 * COIN * (height + 1), 100_000 * COIN
)
self.conductor.spv_node.server.bp._add_claim_activation_change_notification(
claim_id2, height + 100_000, False, 100_000 * COIN * (height + 1), 100_000 * COIN
)
self.conductor.spv_node.server.bp._add_claim_activation_change_notification(
claim_id3, height + 100_000, True, 1_000 * COIN * (height + 1), 1_000 * COIN
)
await self.generate(1)
self.assertEqual(1093.0813885726313, await get_trending_score(claim_id1))
self.assertEqual(-20.84548486028665, await get_trending_score(claim_id2))
self.assertEqual(109.83445454475519, await get_trending_score(claim_id3))
self.assertEqual(0.5848035382925417, await get_trending_score(claim_id4))
self.conductor.spv_node.server.bp._add_claim_activation_change_notification( self.conductor.spv_node.server.bp._add_claim_activation_change_notification(
claim_id4, 200_000, True, 2 * COIN, 10 * COIN claim_id1, height, True, 1 * COIN, 1_000_000 * COIN
)
self.conductor.spv_node.server.bp._add_claim_activation_change_notification(
claim_id2, height, True, 1 * COIN, 100_000 * COIN
)
self.conductor.spv_node.server.bp._add_claim_activation_change_notification(
claim_id2, height + 1, False, 100_001 * COIN, 100_000 * COIN
)
self.conductor.spv_node.server.bp._add_claim_activation_change_notification(
claim_id3, height, True, 1 * COIN, 1_000 * COIN
)
self.conductor.spv_node.server.bp._add_claim_activation_change_notification(
claim_id4, height, True, 1 * COIN, 10 * COIN
) )
await self.generate(1) await self.generate(1)
self.assertEqual(1.2760741313418618, await get_trending_score(claim_id4))
self.assertEqual(3.1711298570548195e+76, await get_trending_score(claim_id1))
self.assertEqual(-1.369652719234026e+74, await get_trending_score(claim_id2))
self.assertEqual(2.925275298842502e+75, await get_trending_score(claim_id3))
self.assertEqual(5.193711055804491e+74, await get_trending_score(claim_id4))
self.assertEqual(0.6690521635580086, await get_trending_score(claim_id5))
self.conductor.spv_node.server.bp._add_claim_activation_change_notification(
claim_id5, height + 100, True, 2 * COIN, 10 * COIN
)
await self.generate(1)
self.assertEqual(5.664516565750028e+74, await get_trending_score(claim_id5))
search_results = (await self.conductor.spv_node.server.bp.db.search_index.search(claim_name="derp"))[0] search_results = (await self.conductor.spv_node.server.bp.db.search_index.search(claim_name="derp"))[0]
self.assertEqual(4, len(search_results)) self.assertEqual(5, len(search_results))
self.assertListEqual([claim_id1, claim_id3, claim_id2, claim_id4], [c['claim_id'] for c in search_results]) self.assertListEqual([claim_id1, claim_id3, claim_id4, claim_id2, claim_id5], [c['claim_id'] for c in search_results])
class ResolveAfterReorg(BaseResolveTestCase): class ResolveAfterReorg(BaseResolveTestCase):