-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhtml_local.py
More file actions
223 lines (146 loc) · 12.9 KB
/
html_local.py
File metadata and controls
223 lines (146 loc) · 12.9 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
from styles import tier_colour
from badges import Badge
badge_obj = Badge()
class KaggleStyles:
def __init__(self,extend=False):
if extend == True:
self.scale = "scale(1.2)"
self.scaler = 1.2
badge_obj.scale = 1.35
self.bottom = [120,120]
self.medalText = "Medals :"
self.isExtend = True
else:
self.scale = "scale(1)"
self.scaler = 1
badge_obj.scale = 1
self.bottom = [0,0]
self.medalText = ""
self.isExtend = False
def present(self,data):
style = """<style>
@import url(https://fonts.googleapis.com/css2?family=Inter);
@keyframes currstreak {
0% { font-size: 3px; opacity: 0.2; }
80% { font-size: 34px; opacity: 1; }
100% { font-size: 28px; opacity: 1; }
}
@keyframes fadein {
0% { opacity: 0; }
100% { opacity: 1; }
}
</style>"""
return f"""
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' style='isolation:isolate' viewBox='0 0 {str(495*self.scaler)} 195' width='{str(495*self.scaler)}px' height='195px'>
{style}
<defs>
<clipPath id='_clipPath_OZGVUqgkTHHpPTYeqOmK3uLgktRVSwWw'>
<rect width='495' height='195'/>
</clipPath>
</defs>
<g xmlns="http://www.w3.org/2000/svg" transform="scale({self.scaler},1)">
<path d="M 4.5 0 L 490.5 0 C 492.984 0 495 2.016 495 4.5 L 495 190.5 C 495 192.984 492.984 195 490.5 195 L 4.5 195 C 2.016 195 0 192.984 0 190.5 L 0 4.5 C 0 2.016 2.016 0 4.5 0 Z" style="stroke: #e4e2e2; fill: #fffefe;stroke-miterlimit:10;rx: 4.5;"/>
</g>
<g xmlns="http://www.w3.org/2000/svg" transform="translate(1,48)">
<text x="20" y="-12" dominant-baseline="middle" stroke-width="0" style="font-family: Roboto, system-ui, sans-serif;font-weight:700;font-size:22px;font-style:normal;fill:{tier_colour[data["performanceTier"]]};stroke:none; opacity: 0; animation: fadein 0.5s linear forwards 0.6s;">
{data["displayName"]}
</text>
<text x="20" y="22" dominant-baseline="middle" stroke-width="0" style="font-family: Roboto, system-ui, sans-serif;font-weight:500;font-size:14px;font-style:normal;fill:#151515;stroke:none; opacity: 0; animation: fadein 0.5s linear forwards 0.6s;">
{"" if not data["occupation"] or not data["organization"] else data["occupation"]+" at " + data["organization"]}
</text>
<text x="20" y="40" dominant-baseline="middle" stroke-width="0" style="font-family: Roboto, system-ui, sans-serif;font-weight:500;font-size:14px;font-style:normal;fill:#151515;stroke:none; opacity: 0; animation: fadein 0.5s linear forwards 0.6s;">
{"" if not data["country"] else data["country"]}{"" if not data["region"] else ", "+data["region"]}{"" if not data["city"] else ", " + data["city"]}
</text>
<text x="20" y="68" dominant-baseline="middle" stroke-width="0" style="font-family: Roboto, system-ui, sans-serif;font-weight:500;font-size:16px;font-style:normal;fill:#757678;stroke:none; opacity: 0; animation: fadein 0.5s linear forwards 0.6s;">
Followers : {data["followers"]["count"]}
</text>
<text x="20" y="86" dominant-baseline="middle" stroke-width="0" style="font-family: Roboto, system-ui, sans-serif;font-weight:500;font-size:16px;font-style:normal;fill:#757678;stroke:none; opacity: 0; animation: fadein 0.5s linear forwards 0.6s;">
Following : {data["following"]["count"]}
</text>
</g>
<g xmlns="http://www.w3.org/2000/svg" transform="translate({20+self.bottom[0]},185.000000) scale(0.050000,-0.05)" fill="#ad7615" stroke="none">
<circle xmlns="http://www.w3.org/2000/svg" cx="250" cy="270" r="250" style="fill:#ffd448;opacity: 0; animation: fadein 0.5s linear forwards 0.4s;"/>
<path d="M170 515 c-103 -33 -170 -128 -170 -243 0 -73 15 -114 60 -166 152 -172 440 -63 440 166 0 99 -44 175 -127 220 -62 34 -142 43 -203 23z m172 -71 l31 -16 -134 -134 c-74 -74 -137 -134 -141 -134 -17 0 -38 62 -38 110 0 62 18 106 58 143 59 57 150 69 224 31z"/>
</g>
<g xmlns="http://www.w3.org/2000/svg" transform="translate({200+self.bottom[0]},185.000000) scale(0.050000,-0.05)" fill="#838280" stroke="none">
<circle xmlns="http://www.w3.org/2000/svg" cx="250" cy="270" r="250" style="fill:#e9e9e9;opacity: 0; animation: fadein 0.5s linear forwards 0.4s;"/>
<path d="M170 515 c-103 -33 -170 -128 -170 -243 0 -73 15 -114 60 -166 152 -172 440 -63 440 166 0 99 -44 175 -127 220 -62 34 -142 43 -203 23z m172 -71 l31 -16 -134 -134 c-74 -74 -137 -134 -141 -134 -17 0 -38 62 -38 110 0 62 18 106 58 143 59 57 150 69 224 31z"/>
</g>
<g xmlns="http://www.w3.org/2000/svg" transform="translate({380+self.bottom[0]},185.000000) scale(0.050000,-0.05)" fill="#8e5b3d" stroke="none">
<circle xmlns="http://www.w3.org/2000/svg" cx="250" cy="270" r="250" style="fill:#f0ba7c;opacity: 0; animation: fadein 0.5s linear forwards 0.4s;"/>
<path d="M170 515 c-103 -33 -170 -128 -170 -243 0 -73 15 -114 60 -166 152 -172 440 -63 440 166 0 99 -44 175 -127 220 -62 34 -142 43 -203 23z m172 -71 l31 -16 -134 -134 c-74 -74 -137 -134 -141 -134 -17 0 -38 62 -38 110 0 62 18 106 58 143 59 57 150 69 224 31z"/>
</g>
<text x="20" y="173" dominant-baseline="middle" stroke-width="0" style="font-family: Roboto, system-ui, sans-serif;font-weight:700;font-size:16px;font-style:normal;fill:#56595e;stroke:none; opacity: 0; animation: fadein 0.5s linear forwards 0.6s;">
{self.medalText}
</text>
<g xmlns="http://www.w3.org/2000/svg" transform="translate({40+self.bottom[1]},185)">
<text x="20" y="-12" dominant-baseline="middle" stroke-width="0" style="font-family: Roboto, system-ui, sans-serif;font-weight:700;font-size:16px;font-style:normal;fill:#ad7615;stroke:none; opacity: 0; animation: fadein 0.5s linear forwards 0.6s;">
{self.medalCounts(data,type="gold")}
</text>
<text x="200" y="-12" dominant-baseline="middle" stroke-width="0" style="font-family: Roboto, system-ui, sans-serif;font-weight:700;font-size:16px;font-style:normal;fill:#838280;stroke:none; opacity: 0; animation: fadein 0.5s linear forwards 0.6s;">
{self.medalCounts(data,type="silver")}
</text>
<text x="380" y="-12" dominant-baseline="middle" stroke-width="0" style="font-family: Roboto, system-ui, sans-serif;font-weight:700;font-size:16px;font-style:normal;fill:#8e5b3d;stroke:none; opacity: 0; animation: fadein 0.5s linear forwards 0.6s;">
{self.medalCounts(data,type="bronze")}
</text>
</g>
{badge_obj.gen_badge()[data["performanceTier"]]}
{self.rankStatus(data,self.isExtend)}
<g xmlns="http://www.w3.org/2000/svg" transform="translate({345*(badge_obj.scale)+47},120)">
<text x="0" y="0" word-spacing="-0.2" dominant-baseline="middle" text-anchor="middle" stroke-width="0" style="font-family:sans-serif;font-weight:400;font-size:14px;font-style:normal;fill:{tier_colour[data["performanceTier"]]};stroke:none; opacity: 0; animation: fadein 0.5s linear forwards 0.6s;">
{"Kaggle" if data["performanceTier"]=="staff" else data["performanceTierCategory"].title()}
</text>
<text x="0" y="16" word-spacing="-0.2" dominant-baseline="middle" text-anchor="middle" stroke-width="0" style="font-family:sans-serif;font-weight:400;font-size:14px;font-style:normal;fill:{tier_colour[data["performanceTier"]]};stroke:none; opacity: 0; animation: fadein 0.5s linear forwards 0.6s;">
{"Team" if data["performanceTier"]=="staff" else data["performanceTier"].title()}
</text>
</g>
<!--<g xmlns="http://www.w3.org/2000/svg" style="isolation:isolate" transform="scale(2.5)"><circle r="22.5" cx="24" cy="24" fill="url(#profileimg)" stroke-width="3" style="stroke: rgb(241, 243, 244);"/><path d="M 10.774831823419357 42.20288237343632 A 22.5 22.5 0 1 0 24 1.5" fill="none" style="stroke: rgb(101, 31, 255);" stroke-width="3"/></g>-->
</svg>
"""
def medalCounts(self,data,type = None):
"""
Count the current total medals from each tier.
Arguements
----------
data : Kaggle data in Dictionary format
type : defines the medal type.
Return
------
count : count of total medal of a certain type.
"""
if not type:
return 0
sections = ["competitionsSummary", "scriptsSummary", "discussionsSummary", "datasetsSummary"]
types = {"gold" : "totalGoldMedals", "silver" : "totalSilverMedals", "bronze" : "totalBronzeMedals"}
count = 0
for section in sections:
count += data[section][types[type]]
return count
def rankStatus(self,data,extend=False):
if data["performanceTier"] in ['novice','contributor','staff'] or not extend:
return ""
cat = data['performanceTierCategory']
summary = {"notebooks":"scriptsSummary","discussion":"discussionsSummary","competitions":"competitionsSummary","datasets":"datasetsSummary"}
best = data[summary[cat]]["rankHighest"]
current = data[summary[cat]]["rankCurrent"]
outof = data[summary[cat]]["rankOutOf"]
text = f"""
<g xmlns="http://www.w3.org/2000/svg" transform="translate(400,40)">
<text x="0" y="0" word-spacing="-0.2" dominant-baseline="middle" text-anchor="middle" stroke-width="0" style="font-family:sans-serif;font-weight:900;font-size:14px;font-style:normal;fill:{tier_colour[data["performanceTier"]]};stroke:none; opacity: 0; animation: fadein 0.5s linear forwards 0.6s;">
Current Rank
</text>
<text x="0" y="16" word-spacing="-0.2" dominant-baseline="middle" text-anchor="middle" stroke-width="0" style="font-family:sans-serif;font-weight:400;font-size:14px;font-style:normal;fill:{tier_colour[data["performanceTier"]]};stroke:none; opacity: 0; animation: fadein 0.5s linear forwards 0.6s;">
{current}
</text>
<text x="0" y="32" word-spacing="-0.2" dominant-baseline="middle" text-anchor="middle" stroke-width="0" style="font-family:sans-serif;font-weight:400;font-size:12px;font-style:normal;fill:#56595e;stroke:none; opacity: 0; animation: fadein 0.5s linear forwards 0.6s;">
Out of {outof}
</text>
<text x="0" y="50" word-spacing="-0.2" dominant-baseline="middle" text-anchor="middle" stroke-width="0" style="font-family:sans-serif;font-weight:900;font-size:14px;font-style:normal;fill:{tier_colour[data["performanceTier"]]};stroke:none; opacity: 0; animation: fadein 0.5s linear forwards 0.6s;">
Highest Rank
</text>
<text x="0" y="66" word-spacing="-0.2" dominant-baseline="middle" text-anchor="middle" stroke-width="0" style="font-family:sans-serif;font-weight:400;font-size:14px;font-style:normal;fill:{tier_colour[data["performanceTier"]]};stroke:none; opacity: 0; animation: fadein 0.5s linear forwards 0.6s;">
{best}
</text>
</g>
"""
return text