⬅ src/utils/hive_blog.py source

1 import pandas as pd
2  
3 from src.static import static_values_enum
4 from src.static.static_values_enum import Leagues, sps_icon_url, dec_icon_url, coins_icon_url, glint_icon_url, \
5 voucher_icon_url, merit_icon_url, wild_league_icon_url, modern_league_icon_url, edition_img_mapping
6  
7 image_hive_blog_20_url = 'https://images.hive.blog/20x0/'
8 image_hive_blog_150_url = 'https://images.hive.blog/150x0/'
9  
10 credit_icon = image_hive_blog_20_url + coins_icon_url
11 dec_icon = image_hive_blog_20_url + dec_icon_url
12 sps_icon = image_hive_blog_20_url + sps_icon_url
13 voucher_icon = image_hive_blog_20_url + voucher_icon_url
14 glint_icon = image_hive_blog_20_url + glint_icon_url
15 merits_icon = image_hive_blog_20_url + merit_icon_url
16  
17 intro_img = ('https://images.hive.blog/0x0/https://files.peakd.com/file/peakd-hive/beaker007/'
18 '23tvcWHTtW5SAv63Z2J86Zuyvn5Jk2BQQ5qBQrGBvv5hRm1DUaVKJN4Z8X9eFfSokovT1.png')
19  
20 earnings_divider = ('![Earnings divider.png](https://files.peakd.com/file/peakd-hive/beaker007/'
21 '23u5tAfbYKhy3zti8o5cVxxgE2LfnjkAV4xZtm1CLAqpJL9zzEF67C7Ec8Tx6b7odFvvK.png)')
22 market_divider = ('![Card Market divider.png](https://files.peakd.com/file/peakd-hive/beaker007/'
23 '23tGyBstuQdzC1Pjv1CiAvt9S3W6sfo5qzCTa6Uv2mQTpfHkwkQ89YxncGYmqsrpynjEv.png)')
24 tournament_divider = ('![tournament divider1.png](https://files.peakd.com/file/peakd-hive/beaker007/'
25 '23u5vZxRCDsEy53q1Rd2sXkXvnAg94fBPj2kCVNoPnjVDiyQfiPecgCJMvoSdqwe4vjQp.png)')
26 closing_notes_divider = ('![Closing notes divider.png](https://files.peakd.com/file/peakd-hive/beaker007/'
27 '23tSMhwJoyukZ42QAed1tFdaMc2XGwQZXAoTga9AByndMur5RT4oj5rMFeNJXwBeXr4tP.png)')
28 season_overview_divider = ('![Season summary divider.png](https://files.peakd.com/file/peakd-hive/beaker007/'
29 '23tSKXK2kCpyZXosK34FeU6MPbw4RGCrrs7TY1tgy4k5Lgndj2JNPEbpjr8JAgQ7kW8v1.png)')
30 season_result_divider = ('![Season result divider.png](https://files.peakd.com/file/peakd-hive/beaker007/'
31 '23tGwQHB4Z1zXu1MnXFvSF7REdndP7Gu67aQgWuwp9VoWurqjvGq81w2M6WkfCtovhXo4.png)')
32  
33 git_repo_link = '[git-repo](https://github.com/gamerbeaker007/splinterlands-statistics)'
34 beneficiaries_img = ('https://images.hive.blog/0x0/https://files.peakd.com/file/peakd-hive/beaker007/'
35 '23tkhySrnBbRV3iV2aD2jH7uuYJuCsFJF5j8P8EVG1aarjqSR7cRLRmuTDhji5MnTVKSM.png')
36  
37 referral_link = '[beaker007](https://splinterlands.com?ref=beaker007)'
38  
39  
40 def get_last_season_statistics_table(last_season_wild_battles, last_season_modern_battles):
41 if not last_season_wild_battles.empty and not last_season_wild_battles.rating.isna().values[0]:
42 last_season_wild_battles = last_season_wild_battles.iloc[0]
43 wild_league = last_season_wild_battles.league.astype(int)
44 wild_battles = int(last_season_wild_battles.battles)
45 rank_value = last_season_wild_battles['rank']
46 if pd.isna(rank_value):
47 wild_rank = 'NA'
48 else:
49 wild_rank = int(rank_value)
50 wild_rating = int(last_season_wild_battles.rating)
51 wild_league_name = Leagues(wild_league).name
52 wild_max_rating = int(last_season_wild_battles.max_rating)
53 wild_win = int(last_season_wild_battles.wins)
54 wild_win_pct = round((wild_win / wild_battles * 100), 2)
55 wild_longest_streak = int(last_season_wild_battles.longest_streak)
56 else:
57 wild_league = 0
58 wild_league_name = 'NA'
59 wild_battles = 'NA'
60 wild_rank = 'NA'
61 wild_rating = 'NA'
62 wild_max_rating = 'NA'
63 wild_win = 'NA'
64 wild_win_pct = 'NA'
65 wild_longest_streak = 'NA'
66  
67 if not last_season_modern_battles.empty and not last_season_modern_battles.rating.isna().values[0]:
68 last_season_modern_battles = last_season_modern_battles.iloc[0]
69 modern_league = last_season_modern_battles.league.astype(int)
70 modern_battles = int(last_season_modern_battles.battles)
71 rank_value = last_season_modern_battles['rank']
72 if pd.isna(rank_value):
73 modern_rank = 'NA'
74 else:
75 modern_rank = int(rank_value)
76 modern_rating = int(last_season_modern_battles.rating)
77 modern_league_name = Leagues(modern_league).name
78 modern_max_rating = int(last_season_modern_battles.max_rating)
79 modern_win = int(last_season_modern_battles.wins)
80 modern_win_pct = round((modern_win / modern_battles * 100), 2)
81 modern_longest_streak = int(last_season_modern_battles.longest_streak)
82 else:
83 modern_league = 0
84 modern_league_name = 'NA'
85 modern_battles = 'NA'
86 modern_rank = 'NA'
87 modern_rating = 'NA'
88 modern_max_rating = 'NA'
89 modern_win = 'NA'
90 modern_win_pct = 'NA'
91 modern_longest_streak = 'NA'
92  
93 wild_league_logo = 'https://images.hive.blog/75x0/' + wild_league_icon_url
94 wild_league_logo = wild_league_logo.replace('0.png', str(wild_league) + '.png')
95 modern_league_logo = 'https://images.hive.blog/75x0/' + modern_league_icon_url
96 modern_league_logo = modern_league_logo.replace('0.png', str(modern_league) + '.png')
97  
98 extra_space = '     '
99 result = ('| Statistic | ' + wild_league_logo + '<br>' +
100 extra_space + 'Wild| ' + modern_league_logo + '<br>' +
101 extra_space + 'Modern | \n')
102 result += '| - | - | - |\n'
103 result += '| Battles | ' + str(wild_battles) + ' | '
104 result += str(modern_battles) + ' | \n'
105 result += '| Rank | ' + str(wild_rank) + ' | '
106 result += str(modern_rank) + ' | \n'
107 result += '| Rating | ' + str(wild_rating) + ' - ' + str(wild_league_name) + ' | '
108 result += str(modern_rating) + ' - ' + str(modern_league_name) + ' | \n'
109 result += '| Rating High | ' + str(wild_max_rating) + ' | '
110 result += str(modern_max_rating) + ' | \n'
111 result += '| Win PCT (Wins/battles * 100) | ' + str(wild_win_pct) + ' (' + str(wild_win) + '/' + str(
112 wild_battles) + ') |'
113 result += str(modern_win_pct) + ' (' + str(modern_win) + '/' + str(modern_battles) + ') |\n'
114 result += '| Longest Streak | ' + str(wild_longest_streak) + ' |'
115 result += str(modern_longest_streak) + ' |\n'
116  
117 return result
118  
119  
120 def get_last_season_costs_table(account, season_info_store, skip_zeros):
121 costs_rows = ''
122 dec_df = season_info_store['dec']
123 dec_df = dec_df.loc[(dec_df.player == account)].fillna(0)
124 if not dec_df.empty:
125 dec_df = dec_df.iloc[0]
126 if 'cost_rental_payment' in dec_df:
127 costs_rows += cost_earning_row('DEC rental payments', dec_icon, dec_df.cost_rental_payment, skip_zeros)
128  
129 if 'rental_payment_fees' in dec_df:
130 costs_rows += cost_earning_row('DEC rental fees', dec_icon, dec_df.rental_payment_fees, skip_zeros)
131 if 'enter_tournament' in dec_df:
132 costs_rows += cost_earning_row('DEC tournament entry fees', dec_icon, dec_df.enter_tournament,
133 skip_zeros)
134 if 'market_rental' in dec_df:
135 costs_rows += cost_earning_row('DEC market rental', dec_icon, dec_df.market_rental, skip_zeros)
136 if 'purchased_energy' in dec_df:
137 costs_rows += cost_earning_row('DEC purchased energy', dec_icon,
138 dec_df.purchased_energy, skip_zeros)
139 if 'buy_market_purchase' in dec_df:
140 costs_rows += cost_earning_row('DEC market buy', dec_icon, dec_df.buy_market_purchase, skip_zeros)
141 if 'market_fees' in dec_df:
142 costs_rows += cost_earning_row('DEC market fees', dec_icon, dec_df.market_fees, skip_zeros)
143 if 'market_list_fee' in dec_df:
144 costs_rows += cost_earning_row('DEC market list fee', dec_icon, dec_df.market_list_fee, skip_zeros)
145  
146 sps_df = season_info_store['sps']
147 sps_df = sps_df.loc[(sps_df.player == account)].fillna(0)
148 if not sps_df.empty:
149 sps_df = sps_df.iloc[0]
150 if 'enter_tournament' in sps_df:
151 costs_rows += cost_earning_row('SPS tournament entry fees', sps_icon, sps_df.enter_tournament,
152 skip_zeros)
153 if 'delegation_modern' in sps_df:
154 costs_rows += cost_earning_row('SPS ranked battle (modern) (fees)', sps_icon, sps_df.delegation_modern,
155 skip_zeros)
156 if 'delegation_wild' in sps_df:
157 costs_rows += cost_earning_row('SPS ranked battle (wild) (fees)', sps_icon, sps_df.delegation_wild,
158 skip_zeros)
159 if 'delegation_focus' in sps_df:
160 costs_rows += cost_earning_row('SPS daily focus (fees)', sps_icon, sps_df.delegation_focus, skip_zeros)
161 if 'delegation_season' in sps_df:
162 costs_rows += cost_earning_row('SPS season (fees)', sps_icon, sps_df.delegation_season, skip_zeros)
163 if 'delegation_land' in sps_df:
164 costs_rows += cost_earning_row('SPS land (fees)', sps_icon, sps_df.delegation_land, skip_zeros)
165 if 'delegation_nightmare' in sps_df:
166 costs_rows += cost_earning_row('SPS nightmare (TD) (fees)', sps_icon, sps_df.delegation_nightmare,
167 skip_zeros)
168 if 'delegation_brawl' in sps_df:
169 costs_rows += cost_earning_row('SPS brawl delegation', sps_icon, sps_df.delegation_brawl, skip_zeros)
170  
171 glint_df = season_info_store['glint']
172 if not glint_df.empty:
173 glint_df = glint_df.loc[(glint_df.player == account)].fillna(0)
174 glint_df = glint_df.iloc[0]
175 if 'purchase_reward_draw' in glint_df:
176 costs_rows += cost_earning_row('GLINT rewards draws', glint_icon, glint_df.purchase_reward_draw,
177 skip_zeros)
178  
179 result = 'None'
180 if costs_rows != '':
181 result = '| Costs | # |\n'
182 result += '| - | - |\n'
183 result += costs_rows
184  
185 return result
186  
187  
188 def cost_earning_row(title, icon, value, skip_zeros):
189 if skip_zeros and value == 0:
190 return ''
191 else:
192 return '| ' + str(title) + ' | ' + icon + ' ' + str(round(value, 3)) + ' |\n'
193  
194  
195 def get_last_season_earnings_table(account, season_info_store, skip_zeros):
196 earning_rows = ''
197 dec_df = season_info_store['dec']
198 dec_df = dec_df.loc[(dec_df.player == account)].fillna(0)
199 if not dec_df.empty:
200 dec_df = dec_df.iloc[0]
201 if 'earn_rental_payment' in dec_df:
202 earning_rows += cost_earning_row('DEC rental payments', dec_icon, dec_df.earn_rental_payment, skip_zeros)
203 if 'sell_market_purchase' in dec_df:
204 earning_rows += cost_earning_row('DEC market sell', dec_icon, dec_df.sell_market_purchase, skip_zeros)
205 if 'tournament_prize' in dec_df:
206 earning_rows += cost_earning_row('DEC tournament rewards', dec_icon, dec_df.tournament_prize,
207 skip_zeros)
208 if 'modern_leaderboard_prizes' in dec_df:
209 earning_rows += cost_earning_row('DEC modern leaderboard rewards', dec_icon,
210 dec_df.modern_leaderboard_prizes, skip_zeros)
211 if 'leaderboard_prizes' in dec_df:
212 earning_rows += cost_earning_row('DEC wild leaderboard rewards', dec_icon,
213 dec_df.leaderboard_prizes, skip_zeros)
214  
215 sps_df = season_info_store['sps']
216 sps_df = sps_df.loc[(sps_df.player == account)].fillna(0)
217 if not sps_df.empty:
218 sps_df = sps_df.iloc[0]
219 if 'tournament_prize' in sps_df:
220 earning_rows += cost_earning_row('SPS tournament rewards', sps_icon,
221 sps_df.tournament_prize,
222 skip_zeros)
223 if 'token_transfer_multi' in sps_df:
224 earning_rows += cost_earning_row('SPS tournament rewards (multi token)', sps_icon,
225 sps_df.token_transfer_multi,
226 skip_zeros)
227 if 'claim_staking_rewards' in sps_df:
228 earning_rows += cost_earning_row('SPS staking reward', sps_icon, sps_df.claim_staking_rewards,
229 skip_zeros)
230 if 'claim_staking_rewards_staking_rewards' in sps_df:
231 earning_rows += cost_earning_row('SPS staking reward',
232 sps_icon,
233 sps_df.claim_staking_rewards_staking_rewards,
234 skip_zeros)
235 if 'claim_staking_rewards_validator_rewards' in sps_df:
236 earning_rows += cost_earning_row('SPS validator reward',
237 sps_icon,
238 sps_df.claim_staking_rewards_validator_rewards,
239 skip_zeros)
240 if 'validate_block' in sps_df:
241 earning_rows += cost_earning_row('SPS validator block validation',
242 sps_icon,
243 sps_df.validate_block,
244 skip_zeros)
245  
246 if 'token_award' in sps_df:
247 earning_rows += cost_earning_row('SPS token award (pools)', sps_icon, sps_df.token_award, skip_zeros)
248  
249 unclaimed_sps_df = season_info_store['unclaimed_sps']
250 unclaimed_sps_df = unclaimed_sps_df.loc[(unclaimed_sps_df.player == account)].fillna(0)
251 if not unclaimed_sps_df.empty:
252 unclaimed_sps_df = unclaimed_sps_df.iloc[0]
253 if 'modern' in unclaimed_sps_df:
254 earning_rows += cost_earning_row('SPS ranked battle (modern)', sps_icon, unclaimed_sps_df.modern,
255 skip_zeros)
256 if 'wild' in unclaimed_sps_df:
257 earning_rows += cost_earning_row('SPS ranked battle (wild)', sps_icon, unclaimed_sps_df.wild, skip_zeros)
258 if 'survival' in unclaimed_sps_df:
259 earning_rows += cost_earning_row('SPS survival battle', sps_icon, unclaimed_sps_df.survival, skip_zeros)
260 if 'survival_bracket' in unclaimed_sps_df:
  • E501 Line too long (124 > 120 characters)
261 earning_rows += cost_earning_row('SPS survival battle', sps_icon, unclaimed_sps_df.survival_bracket, skip_zeros)
262 if 'focus' in unclaimed_sps_df:
263 earning_rows += cost_earning_row('SPS daily focus', sps_icon, unclaimed_sps_df.focus, skip_zeros)
264 if 'season' in unclaimed_sps_df:
265 earning_rows += cost_earning_row('SPS season', sps_icon, unclaimed_sps_df.season, skip_zeros)
266 if 'land' in unclaimed_sps_df:
267 earning_rows += cost_earning_row('SPS land', sps_icon, unclaimed_sps_df.land, skip_zeros)
268 if 'nightmare' in unclaimed_sps_df:
269 earning_rows += cost_earning_row('SPS nightmare (TD) ', sps_icon, unclaimed_sps_df.nightmare, skip_zeros)
270 if 'brawl' in unclaimed_sps_df:
271 earning_rows += cost_earning_row('SPS brawl', sps_icon, unclaimed_sps_df.brawl, skip_zeros)
272  
273 merits_df = season_info_store['merits']
274 merits_df = merits_df.loc[(merits_df.player == account)].fillna(0)
275 if not merits_df.empty:
276 merits_df = merits_df.iloc[0]
277 if 'quest_rewards' in merits_df:
278 earning_rows += cost_earning_row('MERITS quest reward', merits_icon, merits_df.quest_rewards, skip_zeros)
279 if 'season_rewards' in merits_df:
280 earning_rows += cost_earning_row('MERITS season rewards', merits_icon, merits_df.season_rewards, skip_zeros)
281 if 'brawl_prize' in merits_df:
282 earning_rows += cost_earning_row('MERITS brawl prizes', merits_icon, merits_df.brawl_prize, skip_zeros)
283  
284 voucher_df = season_info_store['vouchers']
285 voucher_df = voucher_df.loc[(voucher_df.player == account)].fillna(0)
286 if not voucher_df.empty:
287 voucher_df = voucher_df.iloc[0]
288 if 'claim_staking_rewards' in voucher_df:
289 earning_rows += cost_earning_row('VOUCHER earned', voucher_icon, voucher_df.claim_staking_rewards,
290 skip_zeros)
291 glint_df = season_info_store['glint']
292 if not glint_df.empty:
293 glint_df = glint_df.loc[(glint_df.player == account)].fillna(0)
294 glint_df = glint_df.iloc[0]
295 if 'ranked_rewards' in glint_df:
296 earning_rows += cost_earning_row('GLINT ranked', glint_icon, glint_df.ranked_rewards,
297 skip_zeros)
298 if 'season_rewards' in glint_df:
299 earning_rows += cost_earning_row('GLINT season', glint_icon, glint_df.season_rewards,
300 skip_zeros)
301  
302 result = 'None'
303 if earning_rows != '':
304 result = '| Earnings | # | \n'
305 result += '| - | - |\n'
306 result += earning_rows
307  
308 return result
309  
310  
311 def get_tournament_info(tournaments_info):
312 result = '|Tournament name | League | finish / entrants | wins/losses/draws | entry fee | prize | \n'
313 result += '|-|-|-|-|-|-| \n'
314  
315 if not tournaments_info.empty:
316 for index, tournament in tournaments_info.iterrows():
317 if tournament.finish:
318 entry_fee = str(tournament.entry_fee) if tournament.entry_fee is not None else str(0)
319  
320 result += '| ' + tournament['name']
321 result += '| ' + tournament.league
322 result += '| ' + str(int(tournament.finish)) + ' / ' + str(int(tournament.num_players))
323 result += '| ' + str(int(tournament.wins)) + ' / ' + str(int(tournament.losses)) + ' / ' + str(
324 int(tournament.draws))
325 result += '| ' + str(entry_fee)
326 result += '| ' + str(tournament.prize_qty) + ' ' + str(tournament.prize_type)
327 result += '| \n'
328  
329 filters_sps_prizes = tournaments_info[tournaments_info.prize_type == 'SPS']
330 total_sps_earned = pd.to_numeric(filters_sps_prizes[['prize_qty']].sum(1), errors='coerce').sum()
331  
332 filters_sps_entry_fee = tournaments_info[
333 tournaments_info.entry_fee.notna() &
334 tournaments_info.entry_fee.str.contains('SPS')
335 ].copy()
336 split = filters_sps_entry_fee.loc[:, 'entry_fee'].str.split(' ', expand=True)
337 total_sps_fee = 0
338 if not split.empty:
339 filters_sps_entry_fee.loc[:, 'fee_qty'] = split[0]
340 filters_sps_entry_fee.loc[:, 'fee_type'] = split[1]
341 total_sps_fee = pd.to_numeric(filters_sps_entry_fee[['fee_qty']].sum(1), errors='coerce').sum()
342  
343 result += '|**Total SPS** | | | | **' + str(total_sps_fee) + '**|**' + str(total_sps_earned) + '**| \n'
344  
345 return result
346  
347  
348 def get_card_table(cards_df, print_count=False):
349 base_card_url = 'https://images.hive.blog/150x0/https://d36mxiodymuqjm.cloudfront.net/cards_by_level/'
350  
351 if cards_df is not None and len(cards_df) > 0:
352 cards_df = cards_df.dropna(subset=['card_detail_id']).copy()
353 cards_df.loc[:, 'bcx_new'] = cards_df['bcx'].astype(float).astype(int)
354 cards_df = cards_df.drop(columns=['bcx'])
355 cards_df = cards_df.rename(columns={'bcx_new': 'bcx'})
356  
357 unique_card_list = cards_df.card_name.unique()
358 temp = pd.DataFrame()
359 for card_name in unique_card_list:
360 temp = pd.concat([temp, pd.DataFrame({
361 'card_name': card_name,
362 'edition': str(cards_df[(cards_df['card_name'] == card_name)].edition.values[0]),
363 'quantity_regular': len(cards_df[(cards_df['card_name'] == card_name) & (~cards_df['gold'])]),
364 'quantity_gold': len(cards_df[(cards_df['card_name'] == card_name) & (cards_df['gold'])]),
365 'bcx': str(cards_df[(cards_df['card_name'] == card_name) & (~cards_df['gold'])].bcx.sum()),
366 'bcx_gold': str(cards_df[(cards_df['card_name'] == card_name) & (cards_df['gold'])].bcx.sum())
367 }, index=[0])], ignore_index=True)
368  
369 if len(temp.index) > 5:
370 result = '| | | | | |\n'
371 result += '|-|-|-|-|-|\n'
372 else:
373 # print all in one row
374 table_row = '|'
375 for i in range(0, len(temp.index)):
376 table_row += ' |'
377 result = table_row + '\n' + table_row.replace(' ', '-') + '\n'
378  
379 result += '|'
380 for index, card in temp.iterrows():
381 if index > 0 and index % 5 == 0:
382 result += '\n'
383 edition_name = edition_img_mapping.get(int(float(card.edition)))
384  
385 prefix = str(base_card_url) + str(edition_name) + '/' + str(card.card_name).replace(' ', '%20')
386 count_str = ''
387 gold_suffix = ''
388 bcx_str = ''
389 if card.quantity_regular > 0:
390 if card.quantity_gold == 0:
391 bcx_str = str('<br> bcx: ' + str(card.bcx))
392 else:
393 bcx_str = str('<br> regular bcx: ' + str(card.bcx))
394  
395 if card.quantity_gold > 0:
396 gold_suffix = '_gold'
397 bcx_str += str('<br> gold bcx: ' + str(card.bcx_gold))
398  
399 if print_count:
400 count_str = ' <br> ' + str(card.quantity_regular + card.quantity_gold) + 'x'
401  
402 card_image_url = prefix + '_lv1' + gold_suffix + '.png'
403 result += '' + str(card_image_url) + count_str + bcx_str
404 result += ' |'
405 else:
406 result = 'None'
407 return result
408  
409  
410 def get_introduction_chapter(account_names):
411 account_suffix = ''
412 if len(account_names) > 1:
413 account_suffix = ' (' + str(get_account_names_str(account_names)) + ')'
414 return intro_img + """
415 <br><br><br>
416 """ + season_overview_divider + """
417 # <div class="phishy"><center>Season Summary""" + str(account_suffix) + """</center></div>
418  
419 """
420  
421  
422 def get_closure_chapter():
423 return """
424 <br><br>
425 """ + closing_notes_divider + """
426 ## <div class="phishy"><center>Closing notes</center></div>
427 This report is generated with the splinterlands statistics tool from @beaker007 """ + git_repo_link + """.
428 Any comment/remarks/errors pop me a message on peakd.
429 If you like the content, consider adding @beaker007 as beneficiaries of your post created with the help of this tool.
430 """ + beneficiaries_img + """
431  
432  
433 If you are not playing splinterlands consider using my referral link """ + referral_link + """.
434  
435 Thx all for reading
436  
437 <center>https://d36mxiodymuqjm.cloudfront.net/website/splinterlands_logo.png</center>
438 """
439  
440  
441 def get_plot_placeholder(account_name=None):
442 account_suffix = ""
443 if account_name:
444 account_suffix = " (" + str(account_name) + ")"
445  
446 return """
447 ## <div class="phishy"><center>Season overall stats and history""" + str(account_suffix) + """</center></div>
448  
449 ### Battles
450  
451 ### Earnings
452  
453  
454 """
455  
456  
457 def get_last_season_results(season_battles_wild, season_battles_modern, previous_season_id, account_name=None):
458 account_suffix = ''
459 if account_name:
460 account_suffix = ' (' + str(account_name) + ')'
461 return """
462 <br><br>
463 """ + season_result_divider + """
464 # <div class="phishy"><center>Last Season results""" + str(account_suffix) + """</center></div>
465 """ + str(get_last_season_statistics_table(season_battles_wild, season_battles_modern)) + """
466  
467 """
468  
469  
470 def get_tournament_results(tournaments_info, account_name=None):
471 account_suffix = ''
472 if account_name:
473 account_suffix = ' (' + str(account_name) + ')'
474  
475 if not tournaments_info.empty:
476 return """
477 <br><br>
478 """ + tournament_divider + """
479 ## <div class="phishy"><center>Tournaments""" + str(account_suffix) + """</center></div>
480 """ + str(get_tournament_info(tournaments_info)) + """
481  
482 """
483 return ''
484  
485  
486 def get_last_season_earning_costs(account, season_info_store, skip_zeros, account_name=None):
487 account_suffix = ''
488 if account_name:
489 account_suffix = ' (' + str(account_name) + ')'
490  
491 return """
492 <br><br>
493 """ + earnings_divider + """
494 ## <div class="phishy"><center>Earnings and costs""" + str(account_suffix) + """</center></div>
495 """ + str(get_last_season_earnings_table(account, season_info_store, skip_zeros)) + """
496  
497 ## <div class="phishy"><center>Costs</center></div>
498 """ + str(get_last_season_costs_table(account, season_info_store, skip_zeros)) + """
499 """
500  
501  
502 def get_sub_type_sum(df, name):
503 if df.empty:
504 return 0
505 else:
506 return df.loc[df.sub_type == name].sub_type.count()
507  
508  
509 def get_quantity_sum(df, reward_type):
510 if df.empty or df.loc[df.type == reward_type].empty:
511 return 0
512 else:
513 return df.loc[df.type == reward_type].quantity.sum()
514  
515  
516 def get_quantity_potion_sum(df, reward_type, potion_type):
517 if df.empty or df.loc[df.type == reward_type].empty:
518 return 0
519 else:
520 return df.loc[(df.type == reward_type) & (df.potion_type == potion_type)].quantity.sum()
521  
522  
523 def get_quantity_jackpot_sum(df, reward_type, prize_type):
524 if df.empty or df.loc[df.type == reward_type].empty:
525 return 0
526 else:
527 return df.loc[(df.type == reward_type) & (df.prize_type == prize_type)].quantity.sum()
528  
529  
530 def get_reward_draws_table(df):
531 result = '|' + image_hive_blog_150_url + static_values_enum.reward_draw_common_icon_url
532 result += '|' + image_hive_blog_150_url + static_values_enum.reward_draw_rare_icon_url
533 result += '|' + image_hive_blog_150_url + static_values_enum.reward_draw_epic_icon_url
534 result += '|' + image_hive_blog_150_url + static_values_enum.reward_draw_legendary_icon_url
535 result += '|\n'
536 result += '|-|-|-|-|\n'
537 result += '| <center>Common: ' + str(get_sub_type_sum(df, 'common_draw')) + 'x</center>'
538 result += '| <center>Rare: ' + str(get_sub_type_sum(df, 'rare_draw')) + 'x</center>'
539 result += '| <center>Epic: ' + str(get_sub_type_sum(df, 'epic_draw')) + 'x</center>'
540 result += '| <center>Legendary: ' + str(get_sub_type_sum(df, 'legendary_draw')) + 'x</center>'
541 result += '|\n'
542 result += '|' + image_hive_blog_150_url + static_values_enum.reward_draw_common_gold_icon_url
543 result += '|' + image_hive_blog_150_url + static_values_enum.reward_draw_rare_gold_icon_url
544 result += '|' + image_hive_blog_150_url + static_values_enum.reward_draw_epic_gold_icon_url
545 result += '|' + image_hive_blog_150_url + static_values_enum.reward_draw_legendary_gold_icon_url
546 result += '|\n'
547 result += '| <center>GOLD Common: ' + str(get_sub_type_sum(df, 'gf_common_draw')) + 'x</center>'
548 result += '| <center>GOLD Rare: ' + str(get_sub_type_sum(df, 'gf_rare_draw')) + 'x</center>'
549 result += '| <center>GOLD Epic: ' + str(get_sub_type_sum(df, 'gf_epic_draw')) + 'x</center>'
550 result += '| <center>GOLD Legendary: ' + str(get_sub_type_sum(df, 'gf_legendary_gold_draw')) + 'x</center>'
551 result += '|\n'
552 result += '|' + image_hive_blog_150_url + static_values_enum.reward_draw_minor_icon_url
553 result += '|' + image_hive_blog_150_url + static_values_enum.reward_draw_major_icon_url
554 result += '|' + image_hive_blog_150_url + static_values_enum.reward_draw_ultimate_icon_url
555 result += '| '
556 result += '|\n'
557 result += '| <center>Minor chest: ' + str(get_sub_type_sum(df, 'minor_draw')) + 'x</center>'
558 result += '| <center>Medium chest: ' + str(get_sub_type_sum(df, 'major_draw')) + 'x</center>'
559 result += '| <center>Ultimate chest: ' + str(get_sub_type_sum(df, 'ultimate_draw')) + 'x</center>'
560 result += '| '
561 result += '|\n'
562  
563 return result
564  
565  
566 def get_rewards_draws_result_table(df):
567 if df.empty:
568 return 'None'
569  
570 result = '| ' + image_hive_blog_150_url + static_values_enum.merit_icon_url
571 result += '| ' + image_hive_blog_150_url + static_values_enum.energy_icon_url
572 result += '| ' + image_hive_blog_150_url + static_values_enum.potion_gold_icon_url
573 result += '| ' + image_hive_blog_150_url + static_values_enum.potion_legendary_icon_url
574 result += '| ' + image_hive_blog_150_url + static_values_enum.beta_pack_icon
575 result += '| ' + image_hive_blog_150_url + static_values_enum.land_plot_icon_url
576 result += '|\n'
577 result += '|-|-|-|-|-|-|\n'
578 result += '| <center>' + str(get_quantity_sum(df, 'merits')) + '</center>'
579 result += '| <center>' + str(get_quantity_sum(df, 'energy')) + '</center>'
580 result += '| <center>' + str(get_quantity_potion_sum(df, 'potion', 'gold')) + '</center>'
581 result += '| <center>' + str(get_quantity_potion_sum(df, 'potion', 'legendary')) + '</center>'
582 result += '| <center>' + str(get_quantity_jackpot_sum(df, 'jackpot', 'BETA')) + '</center>'
583 result += '| <center>' + str(get_quantity_jackpot_sum(df, 'jackpot', 'PLOT')) + '</center>'
584 result += '|\n'
585  
586 return result
587  
588  
589 def get_season_league_rewards_table(df):
590 if df.empty:
591 return 'None'
592  
593 wild_df = df[(df.format == 'wild')]
594 modern_df = df[(df.format == 'modern')]
595 wild_league_logo = 'https://images.hive.blog/50x0/' + wild_league_icon_url
596 modern_league_logo = 'https://images.hive.blog/50x0/' + modern_league_icon_url
597 suffix = ')'
598  
599 result = '| <center>Format</center> '
600 result += '|' + image_hive_blog_150_url + static_values_enum.reward_draw_minor_icon_url
601 result += '|' + image_hive_blog_150_url + static_values_enum.reward_draw_major_icon_url
602 result += '|' + image_hive_blog_150_url + static_values_enum.reward_draw_ultimate_icon_url
603 result += '|\n'
604 result += '|-|-|-|-|\n'
605  
606 result += '|'
607 for badge in modern_df.tier.unique().tolist():
608 prefix = '![' + Leagues(badge).name + ']('
609 result += prefix + modern_league_logo.replace('0.png', str(badge) + '.png') + suffix
610 result += '| <center>' + str(get_sub_type_sum(modern_df, 'minor')) + 'x</center>'
611 result += '| <center>' + str(get_sub_type_sum(modern_df, 'major')) + 'x</center>'
612 result += '| <center>' + str(get_sub_type_sum(modern_df, 'ultimate')) + 'x</center>'
613 result += '|\n'
614  
615 result += '|'
616 for badge in wild_df.tier.unique().tolist():
617 prefix = '![' + Leagues(badge).name + ']('
618 result += prefix + wild_league_logo.replace('0.png', str(badge) + '.png') + suffix
619 result += '| <center>' + str(get_sub_type_sum(wild_df, 'minor')) + 'x</center>'
620 result += '| <center>' + str(get_sub_type_sum(wild_df, 'major')) + 'x</center>'
621 result += '| <center>' + str(get_sub_type_sum(wild_df, 'ultimate')) + 'x</center>'
622 result += '|\n'
623  
624 return result
625  
626  
627 def get_last_season_rewards(last_season_rewards, account_name=None):
628 account_suffix = ''
629 if account_name:
630 account_suffix = ' (' + str(account_name) + ')'
631  
632 return """
633 ## <div class="phishy"><center>Reward draws purchased """ + str(account_suffix) + """</center></div>
634 """ + str(get_reward_draws_table(last_season_rewards)) + """
635  
636 ### <div class="phishy"><center>Special items earned""" + str(account_suffix) + """</center></div>
637 """ + str(get_rewards_draws_result_table(last_season_rewards)) + """
638  
639 ### <div class="phishy"><center>Cards earned""" + str(account_suffix) + """</center></div>
640 """ + str(get_card_table(last_season_rewards)) + """
641 """
642  
643  
644 def get_last_season_league_rewards(last_season_league_rewards, account_name=None):
645 account_suffix = ''
646 if account_name:
647 account_suffix = ' (' + str(account_name) + ')'
648  
649 return """
650 ## <div class="phishy"><center>League rewards""" + str(account_suffix) + """</center></div>
651 """ + str(get_season_league_rewards_table(last_season_league_rewards)) + """
652  
653 ### <div class="phishy"><center>League rewards special items earned""" + str(account_suffix) + """</center></div>
654 """ + str(get_rewards_draws_result_table(last_season_league_rewards)) + """
655  
656 ### <div class="phishy"><center>League rewards cards earned""" + str(account_suffix) + """</center></div>
657 """ + str(get_card_table(last_season_league_rewards)) + """
658 """
659  
660  
661 def get_last_season_market_transactions(purchases_cards, sold_cards, account_name=None):
662 account_suffix = ''
663 if account_name:
664 account_suffix = ' (' + str(account_name) + ')'
665  
666 return """
667 <br><br>
668 """ + market_divider + """
669 ## <div class="phishy"><center>Cards Purchased""" + str(account_suffix) + """</center></div>
670 Note: Completed splex.gg and peakmonsters bids are not in this overview, those are purchased by other accounts.
671  
672 """ + str(get_card_table(purchases_cards, True)) + """
673  
674  
675 ## <div class="phishy"><center>Cards Sold""" + str(account_suffix) + """</center></div>
676 Note: Only cards that are listed and sold in this season are displayed here.
677 """ + str(get_card_table(sold_cards, True)) + """
678  
679 """
680  
681  
682 def get_account_introduction(account_names, previous_season_id):
683 result = 'Tracking my result for season ' + str(previous_season_id) + ' : ' \
684 + str(get_account_names_str(account_names)) + '\n\n'
685 return result
686  
687  
688 def get_account_names_str(account_names):
689 result = ''
690 for account_name in account_names:
691 result += str(account_name)
692 if account_name != account_names[-1]:
693 result += ', '
694 return result
695  
696  
697 def write_blog_post(account_names,
698 season_info_store,
699 last_season_rewards_dict,
700 last_season_league_rewards_dict,
701 tournaments_info_dict,
702 purchases_cards_dict,
703 sold_cards_dict,
704 previous_season_id,
705 skip_zeros=True):
706 single_account = (len(account_names) == 1)
707 post = get_account_introduction(account_names, previous_season_id)
708 post += get_introduction_chapter(account_names)
709  
710 wild_battle_df = season_info_store['wild_battle']
711 modern_battle_df = season_info_store['modern_battle']
712 for account_name in account_names:
713 # If there is only one account so a single post do not use account name in post.
714 if single_account:
715 print_account_name = None
716 else:
717 print_account_name = account_name
718  
719 post += get_plot_placeholder(account_name=print_account_name)
720 post += get_last_season_results(wild_battle_df.loc[wild_battle_df.player == account_name],
721 modern_battle_df.loc[modern_battle_df.player == account_name],
722 previous_season_id,
723 account_name=print_account_name)
724 post += get_tournament_results(tournaments_info_dict[account_name],
725 account_name=account_name)
726 post += get_last_season_earning_costs(account_name,
727 season_info_store,
728 skip_zeros,
729 account_name=print_account_name)
730 post += get_last_season_market_transactions(purchases_cards_dict[account_name],
731 sold_cards_dict[account_name],
732 account_name=print_account_name)
733 post += get_last_season_rewards(last_season_rewards_dict[account_name],
734 account_name=print_account_name)
735 post += get_last_season_league_rewards(last_season_league_rewards_dict[account_name],
736 account_name=print_account_name)
737  
738 if single_account:
739 post += get_closure_chapter()
740  
741 if not single_account:
742 post += get_closure_chapter()
743 return post