-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocialScore.py
168 lines (136 loc) · 4.6 KB
/
socialScore.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
from typing import Dict, Union
from dataclasses import dataclass
import pprint
@dataclass
class EngagementMetrics:
engagement_rate: float
interaction_quality: float
growth_rate: float
@dataclass
class ContentQuality:
frequency: float
originality: float
diversity: float
@dataclass
class Trustworthiness:
trust_score: float
verified_followers: float
reputation_index: float
@dataclass
class SocialImpact:
network_influence: float
trend_setting: float
mentions_reposts: float
@dataclass
class MonetizationPotential:
token_transactions: float
crowdfunding: float
endorsement_success: float
@dataclass
class GovernanceParticipation:
voting_activity: float
proposal_contribution: float
class SocialScoreCalculator:
def __init__(self):
self.weights = {
"engagement": 0.3,
"content": 0.2,
"trust": 0.2,
"impact": 0.15,
"monetization": 0.1,
"governance": 0.05,
}
def calculate_engagement_score(self, metrics: EngagementMetrics) -> float:
return (
0.4 * metrics.engagement_rate
+ 0.3 * metrics.interaction_quality
+ 0.3 * metrics.growth_rate
)
def calculate_content_score(self, quality: ContentQuality) -> float:
return (
0.3 * quality.frequency
+ 0.4 * quality.originality
+ 0.3 * quality.diversity
)
def calculate_trust_score(self, trust: Trustworthiness) -> float:
return (
0.5 * trust.trust_score
+ 0.3 * trust.verified_followers
+ 0.2 * trust.reputation_index
)
def calculate_impact_score(self, impact: SocialImpact) -> float:
return (
0.5 * impact.network_influence
+ 0.3 * impact.trend_setting
+ 0.2 * impact.mentions_reposts
)
def calculate_monetization_score(
self, monetization: MonetizationPotential
) -> float:
return (
0.5 * monetization.token_transactions
+ 0.3 * monetization.crowdfunding
+ 0.2 * monetization.endorsement_success
)
def calculate_governance_score(self, governance: GovernanceParticipation) -> float:
return 0.7 * governance.voting_activity + 0.3 * governance.proposal_contribution
def calculate_social_score(
self,
engagement: EngagementMetrics,
content: ContentQuality,
trust: Trustworthiness,
impact: SocialImpact,
monetization: MonetizationPotential,
governance: GovernanceParticipation,
) -> Dict[str, Union[float, str]]:
e = self.calculate_engagement_score(engagement)
c = self.calculate_content_score(content)
t = self.calculate_trust_score(trust)
i = self.calculate_impact_score(impact)
m = self.calculate_monetization_score(monetization)
g = self.calculate_governance_score(governance)
social_score = (
self.weights["engagement"] * e
+ self.weights["content"] * c
+ self.weights["trust"] * t
+ self.weights["impact"] * i
+ self.weights["monetization"] * m
+ self.weights["governance"] * g
)
tier = self.get_tier(social_score)
return {
"social_score": round(social_score, 2),
"tier": tier,
"engagement_score": round(e, 2),
"content_score": round(c, 2),
"trust_score": round(t, 2),
"impact_score": round(i, 2),
"monetization_score": round(m, 2),
"governance_score": round(g, 2),
}
@staticmethod
def get_tier(score: float) -> str:
if score >= 80:
return "Top-tier influencer"
elif 60 <= score < 80:
return "Mid-tier influencer"
elif 40 <= score < 60:
return "Emerging influencer"
else:
return "Needs improvement"
def main():
# create an instance of SocialScoreCalculator class
calculator = SocialScoreCalculator()
# calculating result using the above instance.
# TODO:This is just dummy data, we have to itegrate the api data here.
result = calculator.calculate_social_score(
engagement=EngagementMetrics(85, 80, 90),
content=ContentQuality(75, 80, 70),
trust=Trustworthiness(90, 85, 95),
impact=SocialImpact(80, 75, 85),
monetization=MonetizationPotential(65, 70, 60),
governance=GovernanceParticipation(70, 70),
)
pprint.pprint(result, indent=2, sort_dicts=False)
if __name__ == "__main__":
main()