forked from davidbeard741/arcticfrenz-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rank-holders_quekz.py
102 lines (84 loc) · 4.61 KB
/
rank-holders_quekz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import json
from datetime import date, datetime
import traceback
from math import exp
import numpy as np
try:
with open('quekz/by-holder.json') as f:
data = json.load(f)
quantityNfts_weight = 1.1
rarityScore_weight = 0.1
daysHeld_weight = 1.34
daysHeld_decay_factor = 0.1
"""
print(f"Weight given to the number of NFTs held: {quantityNfts_weight}")
print(f"Weight given to rarity scores: {rarityScore_weight}")
print(f"Weight given to days held scores: {daysHeld_weight}")
print(f"Factor controlling the decay of score based on days held: {daysHeld_decay_factor}")
"""
max_nfts = max([holder["quantityNfts"] for holder in data])
# print(f"The total number of NFTs owned by the individual with the largest NFT collection: {max_nfts}")
avg_rarity_per_holder = [(holder["holderAddress"], sum(subnft["rarityScore"] for subnft in holder["holdingNfts"]) / holder["quantityNfts"]) for holder in data]
rarity_sniper = max(avg_rarity_per_holder, key=lambda x: x[1])
highest_rarity_average = rarity_sniper[1]
# print(f"The average rarity score of the owner who possesses the highest average rarity score: {highest_rarity_average}")
days_held_per_holder = [(holder["holderAddress"], sum(subnft["daysHeld"] for subnft in holder["holdingNfts"])) for holder in data]
diamond_hands = max(days_held_per_holder, key=lambda x: x[1])
hold_door = diamond_hands[1]
# print(f"Th total duration held by the owner possessing the maximum cumulative duration of all NFTs they own : {hold_door}")
today = date.today()
def score_address(addr):
holder_data = [holder for holder in data if holder["holderAddress"] == addr]
if not holder_data:
return 0
holder_data = holder_data[0]
nfts = holder_data["quantityNfts"]
nfts_normalized = nfts / max_nfts
nfts_weighted = nfts_normalized * quantityNfts_weight
rarity_scores = [subnft["rarityScore"] for subnft in holder_data["holdingNfts"]]
rarity_scores_log = [np.log(score + 1) for score in rarity_scores]
rarity_score_average = sum(rarity_scores_log) / len(rarity_scores_log)
rarity_score_normalized = rarity_score_average / np.log(highest_rarity_average + 1)
rarity_score_weighted = rarity_score_normalized * rarityScore_weight
days_held = sum([subnft["daysHeld"] for subnft in holder_data["holdingNfts"]])
days_held_normalized = days_held / hold_door
decay_factor = exp(-days_held_normalized * daysHeld_decay_factor)
days_held_with_decay = days_held_normalized * decay_factor
days_held_weighted = days_held_with_decay * daysHeld_weight
# print(f"Address: {addr}, NFTs Weighted: {nfts_weighted}, Rarity Score Weighted: {rarity_score_weighted}, Days Held Weighted: {days_held_weighted}")
scoreHold = (nfts_weighted + rarity_score_weighted + days_held_weighted)
return scoreHold, # nfts_weighted, rarity_score_weighted, days_held_weighted
# Review the calculated averages to consider adjustments to the weights assigned to the number
# of NFTs (`quantityNfts_weight`), rarity score (`rarityScore_weight`), and holding duration
# (`daysHeld_weight`). This evaluation will help in fine-tuning the scoring system for more
# accurate assessments.
"""
sum_nfts_weighted = 0
sum_nfts_weighted = 0
sum_rarity_score_weighted = 0
sum_days_held_weighted = 0
for holder in data:
_, nfts_weighted, rarity_score_weighted, days_held_weighted = score_address(holder["holderAddress"])
sum_nfts_weighted += nfts_weighted
sum_rarity_score_weighted += rarity_score_weighted
sum_days_held_weighted += days_held_weighted
average_nfts_weighted = sum_nfts_weighted / len(data)
average_rarity_score_weighted = sum_rarity_score_weighted / len(data)
average_days_held_weighted = sum_days_held_weighted / len(data)
print(f"Average Score of Holder's NFTs Owned: {average_nfts_weighted}")
print(f"Average Score of Holder's Rarity: {average_rarity_score_weighted}")
print(f"Average Score of Holder's Days Held: {average_days_held_weighted}")
now_utc = datetime.utcnow()
print(f"Date Tuned (UTC): {now_utc.strftime('%Y-%m-%d %H:%M:%S')}")
"""
scored = []
for holder in data:
score = score_address(holder["holderAddress"])
holder["holderScore"] = score
scored.append(holder)
ranked = sorted(scored, key=lambda x: x["holderScore"], reverse=True)
with open('quekz/ranked-holders.json', 'w') as f:
json.dump(ranked, f, indent=4)
except Exception as e:
print(f"Error: {e}")
traceback.print_exc()