mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
feat: add soloQ rank of all players in match details
This commit is contained in:
parent
4fd79a5d84
commit
c6d0cd5d4e
9 changed files with 108 additions and 28 deletions
|
|
@ -98,12 +98,15 @@
|
|||
<div class="text-xs text-teal-500">{{ player.champion.name }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center">
|
||||
<div v-show="false" class="ml-1">
|
||||
<svg class="w-6 h-6">
|
||||
<use xlink:href="#rank-silver" />
|
||||
<div class="ml-1 flex items-center">
|
||||
<div v-if="player.rank">
|
||||
<svg class="w-5 h-5">
|
||||
<use :xlink:href="`#rank-${player.rank.tier.toLowerCase()}`" />
|
||||
</svg>
|
||||
<div class="-mt-1 text-blue-200 text-xs">S2</div>
|
||||
<div class="text-blue-300 text-xs">{{ player.rank.shortName }}</div>
|
||||
</div>
|
||||
<div v-else class="w-5 h-5">
|
||||
<div class="-mt-1 text-blue-300 text-2xl">-</div>
|
||||
</div>
|
||||
<MatchItems :items="player.items" :one-row="true" />
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<template>
|
||||
<div :class="oneRow ? 'ml-1 items-center' : 'items-2-rows flex-wrap'" class="flex">
|
||||
<div :class="oneRow ? 'ml-2 items-center' : 'items-2-rows flex-wrap'" class="flex">
|
||||
<Dropdown v-for="(item, index) in items" :key="index">
|
||||
<template v-slot:trigger>
|
||||
<div
|
||||
|
|
|
|||
|
|
@ -6,7 +6,15 @@
|
|||
<symbol id="info" class="stroke-current" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></symbol>
|
||||
<symbol id="award" class="fill-current" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M97.12 362.63c-8.69-8.69-4.16-6.24-25.12-11.85-9.51-2.55-17.87-7.45-25.43-13.32L1.2 448.7c-4.39 10.77 3.81 22.47 15.43 22.03l52.69-2.01L105.56 507c8 8.44 22.04 5.81 26.43-4.96l52.05-127.62c-10.84 6.04-22.87 9.58-35.31 9.58-19.5 0-37.82-7.59-51.61-21.37zM382.8 448.7l-45.37-111.24c-7.56 5.88-15.92 10.77-25.43 13.32-21.07 5.64-16.45 3.18-25.12 11.85-13.79 13.78-32.12 21.37-51.62 21.37-12.44 0-24.47-3.55-35.31-9.58L252 502.04c4.39 10.77 18.44 13.4 26.43 4.96l36.25-38.28 52.69 2.01c11.62.44 19.82-11.27 15.43-22.03zM263 340c15.28-15.55 17.03-14.21 38.79-20.14 13.89-3.79 24.75-14.84 28.47-28.98 7.48-28.4 5.54-24.97 25.95-45.75 10.17-10.35 14.14-25.44 10.42-39.58-7.47-28.38-7.48-24.42 0-52.83 3.72-14.14-.25-29.23-10.42-39.58-20.41-20.78-18.47-17.36-25.95-45.75-3.72-14.14-14.58-25.19-28.47-28.98-27.88-7.61-24.52-5.62-44.95-26.41-10.17-10.35-25-14.4-38.89-10.61-27.87 7.6-23.98 7.61-51.9 0-13.89-3.79-28.72.25-38.89 10.61-20.41 20.78-17.05 18.8-44.94 26.41-13.89 3.79-24.75 14.84-28.47 28.98-7.47 28.39-5.54 24.97-25.95 45.75-10.17 10.35-14.15 25.44-10.42 39.58 7.47 28.36 7.48 24.4 0 52.82-3.72 14.14.25 29.23 10.42 39.59 20.41 20.78 18.47 17.35 25.95 45.75 3.72 14.14 14.58 25.19 28.47 28.98C104.6 325.96 106.27 325 121 340c13.23 13.47 33.84 15.88 49.74 5.82a39.676 39.676 0 0 1 42.53 0c15.89 10.06 36.5 7.65 49.73-5.82zM97.66 175.96c0-53.03 42.24-96.02 94.34-96.02s94.34 42.99 94.34 96.02-42.24 96.02-94.34 96.02-94.34-42.99-94.34-96.02z"></path></symbol>
|
||||
<symbol id="gold" class="fill-current" viewBox="0 0 15 15" fill="fill-current"><title>gold</title><path d="M14 5.63324C14 3.57057 11.7157 1.8999 8.89286 1.8999C6.07 1.8999 3.78571 3.57057 3.78571 5.63324C3.7765 5.76685 3.7765 5.90095 3.78571 6.03457C2.12357 6.65057 1 7.90124 1 9.36657C1 11.4292 3.28429 13.0999 6.10714 13.0999C8.93 13.0999 11.2143 11.4292 11.2143 9.36657C11.2235 9.23295 11.2235 9.09885 11.2143 8.96524C12.8486 8.34924 14 7.08924 14 5.63324ZM6.10714 11.3172C4.315 11.3172 2.85714 10.2999 2.85714 8.94657C2.90787 8.55215 3.06303 8.17865 3.3064 7.86507C3.54978 7.55149 3.87244 7.30934 4.24071 7.1639C4.77538 7.8881 5.47991 8.46817 6.29158 8.85247C7.10324 9.23677 7.99686 9.41338 8.89286 9.36657H9.30143C9.03214 10.4679 7.71357 11.3172 6.10714 11.3172Z" /></symbol>
|
||||
<symbol id="rank-silver" viewBox="0 0 32 32"><title>rank-silver</title><path fill="#80989d" d="M16 6.667c0 0 0.986 1.479 2.534 3.165-0.781-0.321-1.637-0.498-2.534-0.498s-1.753 0.177-2.534 0.498c1.548-1.686 2.534-3.165 2.534-3.165z"></path><path fill="#80989d" d="M22.667 16c0-2.22-1.085-4.186-2.753-5.398 1.976-0.343 6.753-1.935 6.753-1.935 0 1.761-1.034 6.626-4.013 7.761 0.009-0.141 0.013-0.284 0.013-0.428z"></path><path fill="#80989d" d="M19.308 21.789c1.752-1.003 3.005-2.78 3.295-4.864 1.185 0.187 2.73 0.408 2.73 0.408s-1.135 3.406-6.025 4.456z"></path><path fill="#80989d" d="M16 22.667c0.617 0 1.215-0.084 1.782-0.241-0.406 0.781-1.282 2.407-1.782 2.907-0.5-0.5-1.376-2.127-1.782-2.907 0.567 0.157 1.165 0.241 1.782 0.241z"></path><path fill="#80989d" d="M9.392 16.89c0.28 2.1 1.537 3.89 3.3 4.899-4.89-1.050-6.025-4.456-6.025-4.456s1.554-0.25 2.726-0.444z"></path><path fill="#80989d" d="M9.333 16c0 0.129 0.004 0.258 0.011 0.386-2.977-1.324-4.011-6.91-4.011-7.719 0 0 4.777 1.592 6.753 1.935-1.669 1.212-2.753 3.178-2.753 5.398z"></path><path fill="#80989d" d="M20 16c0 2.209-1.791 4-4 4s-4-1.791-4-4c0-2.209 1.791-4 4-4s4 1.791 4 4z"></path></symbol>
|
||||
<symbol id="rank-iron" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 88 88"><path d="M31.9461 26.5c-8 4.8-9.3333 14.6667-9 19-12.8-5.6-15.9733-20.5-12.8066-26 6.5 4 17.5 6 21.8066 7zM14.9462 49.5c2.8-.8 6.4999-1.6667 7.9999-2 2.3999 9.6 9.6667 14.6667 13.0001 16-14-1.6-19.8334-10-21-14zM44.4462 14c-2 1.6-6.1667 7.3333-8 10 5.6-1.6 12.9999-.6667 15.9999 0-2.4-4-6.3333-8.3333-7.9999-10zM73.4462 49.5c-2.8-.8-6.5-1.6667-8-2-2.4 9.6-9.6667 14.6667-13.0001 16 14-1.6 19.8334-10 21.0001-14zM57.4461 44c0 7.1797-5.8202 13-12.9999 13s-13-5.8203-13-13 5.8203-13 13-13 12.9999 5.8203 12.9999 13zM50.4461 64c-4.5 1-6.4999 1-11.9999 0 1.6 4 6.9999 8.5 9.4999 10 0-2 1.6667-7.6667 2.5-10zM56.4462 26.5c8 4.8 9.3333 14.6667 9 19 12.8-5.6 15.9733-20.5 12.8066-26-6.5 4-17.4999 6-21.8066 7z" fill="#574D4F" /></symbol>
|
||||
<symbol id="rank-bronze" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 88 88"><path d="M31.9461 26.5c-8 4.8-9.3333 14.6667-9 19-12.8-5.6-15.9733-20.5-12.8066-26 6.5 4 17.5 6 21.8066 7zM14.9462 49.5c2.8-.8 6.4999-1.6667 7.9999-2 2.3999 9.6 9.6667 14.6667 13.0001 16-14-1.6-19.8334-10-21-14zM44.4462 14c-2 1.6-6.1667 7.3333-8 10 5.6-1.6 12.9999-.6667 15.9999 0-2.4-4-6.3333-8.3333-7.9999-10zM73.4462 49.5c-2.8-.8-6.5-1.6667-8-2-2.4 9.6-9.6667 14.6667-13.0001 16 14-1.6 19.8334-10 21.0001-14zM57.4461 44c0 7.1797-5.8202 13-12.9999 13s-13-5.8203-13-13 5.8203-13 13-13 12.9999 5.8203 12.9999 13zM50.4461 64c-4.5 1-6.4999 1-11.9999 0 1.6 4 4.0538 8 6.5538 9.5 2-1.5 4.6128-7.1667 5.4461-9.5zM56.4462 26.5c8 4.8 9.3333 14.6667 9 19 12.8-5.6 15.9733-20.5 12.8066-26-6.5 4-17.4999 6-21.8066 7z" fill="#8C523A" /></symbol>
|
||||
<symbol id="rank-silver" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 88 88"><path d="M31.9461 26.5c-8 4.8-9.3333 14.6667-9 19-12.8-5.6-15.9733-20.5-12.8066-26 6.5 4 17.5 6 21.8066 7zM14.9462 49.5c2.8-.8 6.4999-1.6667 7.9999-2 2.3999 9.6 9.6667 14.6667 13.0001 16-14-1.6-19.8334-10-21-14zM44.4462 14c-2 1.6-6.1667 7.3333-8 10 5.6-1.6 12.9999-.6667 15.9999 0-2.4-4-6.3333-8.3333-7.9999-10zM73.4462 49.5c-2.8-.8-6.5-1.6667-8-2-2.4 9.6-9.6667 14.6667-13.0001 16 14-1.6 19.8334-10 21.0001-14zM57.4461 44c0 7.1797-5.8202 13-12.9999 13s-13-5.8203-13-13 5.8203-13 13-13 12.9999 5.8203 12.9999 13zM50.4461 64c-4.5 1-6.4999 1-11.9999 0 1.6 4 4.0538 8 6.5538 9.5 2-1.5 4.6128-7.1667 5.4461-9.5zM56.4462 26.5c8 4.8 9.3333 14.6667 9 19 12.8-5.6 15.9733-20.5 12.8066-26-6.5 4-17.4999 6-21.8066 7z" fill="#80989D" /></symbol>
|
||||
<symbol id="rank-gold" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 88 88"><path d="M23.5302 49.5c2 6.4 9.1666 11 12.5 12.5-2.4 3.6-5.3334 6.1667-6.5 7-2.5-10-12.6667-15-19-18.5l13-1zM63.4302 49.5c-2 6.4-9.1667 11-12.5 12.5 2.4 3.6 5.3333 6.1667 6.5 7 2.5-10 12.6666-15 19-18.5l-13-1zM31.5302 25c-7.5 5.5-8.8334 15.1667-8.5 19.5C10.2302 38.9 4.53026 20 5.03017 13 11.5302 17 27.0301 23 31.5302 25zM43.4763 12c-2 1.6-6.1667 7.3333-8 10 5.6-1.6 13-.6667 16 0-2.4-4-6.3334-8.3333-8-10zM56.4763 42c0 7.1797-5.8203 13-13 13s-13-5.8203-13-13 5.8203-13 13-13 13 5.8203 13 13z" fill="#CD8837" /><path d="M51.0301 62c-4.5 1-9.4999 1-14.9999 0-.9462 4.5 4.9461 13 7.4461 14.5 4.5538-4 6.7205-12.1667 7.5538-14.5zM55.5302 25c7.5 5.5 8.8333 15.1667 8.4999 19.5 12.8001-5.6 18.4999-24.5 18-31.5-6.5 4-21.9999 10-26.4999 12z" fill="#CD8837" /></symbol>
|
||||
<symbol id="rank-platinum" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 88 88"><path d="M23.5302 49.5c2 6.4 9.1666 11 12.5 12.5-2.4 3.6-5.3334 6.1667-6.5 7-2.5-10-12.6667-15-19-18.5l13-1zM63.4302 49.5c-2 6.4-9.1667 11-12.5 12.5 2.4 3.6 5.3333 6.1667 6.5 7 2.5-10 12.6666-15 19-18.5l-13-1zM31.5302 25c-7.5 5.5-8.8334 15.1667-8.5 19.5C10.2302 38.9 4.53026 20 5.03017 13 11.5302 17 27.0301 23 31.5302 25zM43.4763 12c-2 1.6-6.1667 7.3333-8 10 5.6-1.6 13-.6667 16 0-2.4-4-6.3334-8.3333-8-10zM56.4763 42c0 7.1797-5.8203 13-13 13s-13-5.8203-13-13 5.8203-13 13-13 13 5.8203 13 13z" fill="#4E9996" /><path d="M51.0301 62c-4.5 1-9.4999 1-14.9999 0-.9462 4.5 4.9461 13 7.4461 14.5 4.5538-4 6.7205-12.1667 7.5538-14.5zM55.5302 25c7.5 5.5 8.8333 15.1667 8.4999 19.5 12.8001-5.6 18.4999-24.5 18-31.5-6.5 4-21.9999 10-26.4999 12z" fill="#4E9996" /></symbol>
|
||||
<symbol id="rank-diamond" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 88 88"><path d="M23.5302 49.5c2 6.4 9.1666 11 12.5 12.5-2.4 3.6-5.3334 6.1667-6.5 7-2.5-10-12.6667-15-19-18.5l13-1zM63.4302 49.5c-2 6.4-9.1667 11-12.5 12.5 2.4 3.6 5.3333 6.1667 6.5 7 2.5-10 12.6666-15 19-18.5l-13-1zM31.5302 25c-7.5 5.5-8.8334 15.1667-8.5 19.5C10.2302 38.9 4.53026 20 5.03017 13 11.5302 17 27.0301 23 31.5302 25zM43.4763 12c-2 1.6-6.1667 7.3333-8 10 5.6-1.6 13-.6667 16 0-2.4-4-6.3334-8.3333-8-10zM56.4763 42c0 7.1797-5.8203 13-13 13s-13-5.8203-13-13 5.8203-13 13-13 13 5.8203 13 13z" fill="#576BCE" /><path d="M51.0301 62c-4.5 1-9.4999 1-14.9999 0-.9462 4.5 4.9461 13 7.4461 14.5 4.5538-4 6.7205-12.1667 7.5538-14.5zM55.5302 25c7.5 5.5 8.8333 15.1667 8.4999 19.5 12.8001-5.6 18.4999-24.5 18-31.5-6.5 4-21.9999 10-26.4999 12z" fill="#576BCE" /></symbol>
|
||||
<symbol id="rank-master" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 88 88"><path d="M57 25c-7.4269-8.5723-13.5-15-13.5-15S37.4269 16.4277 30 25c3.7607-2.6881 8.4362-4.283 13.5-4.283 5.0638 0 9.7393 1.5949 13.5 4.283z" fill="#A5584E" /><path d="M56.6082 25.3539L85 10c0 15.3572-2.1852 30.7111-2.1852 30.7111l-17.4722 7.8974 15.2902 3.0701c-6.5525 4.3863-16.3812 12.0666-16.3812 20.8393l-12.0139-8.776C52.2377 65.9367 45.6852 78 43.5 78s-8.7377-12.0666-8.7377-14.2581c-1.0156 1.2438-12.0139 8.776-12.0139 8.776 0-8.776-9.8287-16.453-16.38119-20.8393l15.29019-3.0701-17.47215-7.8974S2 25.3539 2 10l28.3918 15.3539c-5.3042 4.0013-8.7344 10.3752-8.7344 17.552 0 8.7924 5.1502 16.3772 12.5873 19.8751 2.811 1.3228 5.9463 2.0599 9.2553 2.0599 12.0631 0 21.8426-9.8224 21.8426-21.9383 0-7.1768-3.4302-13.5474-8.7344-17.552v.0033z" fill="#A5584E" /><path d="M43.5 56C50.9554 56 57 50.1793 57 43s-6.0446-13-13.5-13S30 35.8207 30 43s6.0446 13 13.5 13z" fill="#9D48E0" /></symbol>
|
||||
<symbol id="rank-grandmaster" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 88 88"><path d="M57.1993 25.3498C49.9397 16.5776 44.0033 10 44.0033 10s-5.9364 6.5776-13.196 15.3498c3.676-2.7507 8.2463-4.3828 13.196-4.3828 4.9498 0 9.52 1.6321 13.196 4.3828zm.0033.0033L88 10c0 15.3564-2.201 30.7096-2.201 30.7096L66 48.6066l17.598 3.07s-5.5008 12.066-23.0988 20.8383l-7.6985-8.7756c0 .0888-.0363.3159-.0891.6581-.3663 2.3098-1.5477 9.7758 2.2901 13.6026h-22c3.8443-3.8334 2.6497-11.3388 2.2867-13.6224-.0528-.329-.0891-.5528-.0891-.635-1.0229 1.2438-7.6985 8.7755-7.6985 8.7755C9.9028 63.7426 4.40198 51.6799 4.40198 51.6799L22 48.6099l-19.79901-7.897S0 25.3564 0 10.0033l30.7974 15.3531C25.4549 29.3576 22 35.7311 22 42.9076c0 8.792 5.1873 16.3764 12.678 19.8742 2.8312 1.3227 5.9892 2.0598 9.322 2.0598 12.15 0 22-9.822 22-21.9373 0-7.1764-3.4549-13.5467-8.7974-17.5512z" fill="#756572" /><path d="M43.5 56C50.4031 56 56 50.4031 56 43.5S50.4031 31 43.5 31 31 36.5969 31 43.5 36.5969 56 43.5 56z" fill="#CD4545" /></symbol>
|
||||
<symbol id="rank-challenger" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 88 88"><path d="M56 24C49.1233 15.4277 43.5 9 43.5 9S37.8767 15.4277 31 24c3.4821-2.6881 7.8113-4.283 12.5-4.283S52.5179 21.3119 56 24z" fill="#F4C874" /><path d="M56.6025 23.8464L86 9c0 14.8495-2.1009 29.6959-2.1009 29.6959L65 46.3323l16.7981 2.9686s-7.3486 11.6677-22.0489 22.2727l-7.3486-10.605C52.4006 68.0036 46.1009 79 44 79c-2.1009 0-8.4006-11.0186-8.4006-18.0314-.9765 1.2028-7.3486 10.605-7.3486 10.605C13.5505 60.9686 6.20189 49.3009 6.20189 49.3009L23 46.3323 4.10095 38.6959S2 23.8464 2 9l29.3975 14.8464C26.2979 27.7155 23 33.8786 23 40.8182c0 8.5018 4.9516 15.8359 12.1017 19.2182 2.7026 1.2791 5.717 1.9918 8.8983 1.9918 11.5977 0 21-9.4977 21-21.2132 0-6.9395-3.2979-13.0995-8.3975-16.9718v.0032z" fill="#F4C874" /><path d="M44.5 54C51.4031 54 57 48.4031 57 41.5S51.4031 29 44.5 29 32 34.5969 32 41.5 37.5969 54 44.5 54z" fill="#3FBFDD" /></symbol>
|
||||
<symbol id="time" class="stroke-current" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><polyline points="12 6 12 12 16 14"></polyline></symbol>
|
||||
</svg>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import { timeDifference } from '@/helpers/functions.js'
|
|||
import { maps, gameModes } from '@/data/data.js'
|
||||
import summonersJSON from '@/data/summoner.json'
|
||||
|
||||
const uniqueLeagues = ['CHALLENGER', 'GRANDMASTER', 'MASTER']
|
||||
const leaguesNumbers = { 'I': 1, 'II': 2, 'III': 3, 'IV': 4 }
|
||||
|
||||
/**
|
||||
|
|
@ -87,9 +86,7 @@ export function createSummonerData(RiotData) {
|
|||
function getLeagueData(leagueData, leagueName) {
|
||||
if (!leagueData) return null
|
||||
|
||||
leagueData.fullRank = uniqueLeagues.includes(leagueData.tier) ? leagueData.tier : `${leagueData.tier} ${leagueData.rank}`
|
||||
leagueData.rankImgLink = getRankImg(leagueData)
|
||||
leagueData.winrate = +(leagueData.wins * 100 / (leagueData.wins + leagueData.losses)).toFixed(1) + '%'
|
||||
leagueData.name = leagueName
|
||||
return leagueData
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,19 +33,28 @@ class MatchController {
|
|||
* POST - Return details data for one specific match
|
||||
*/
|
||||
async show({ request, response }) {
|
||||
console.time('MatchDetails')
|
||||
console.log('Match details request')
|
||||
const gameId = request.input('gameId')
|
||||
const region = request.input('region')
|
||||
console.log(gameId, region)
|
||||
|
||||
let matchFromRiot = await Jax.Match.get(gameId)
|
||||
let matchDetails = {}
|
||||
const alreadySaved = await DetailedMatch.where({ gameId, region }).first()
|
||||
if (alreadySaved) {
|
||||
console.log('MATCH DETAILS ALREADY SAVED')
|
||||
matchDetails = alreadySaved
|
||||
} else {
|
||||
matchDetails = await Jax.Match.get(gameId)
|
||||
matchDetails = await DetailedMatchTransformer.transform(matchDetails)
|
||||
await DetailedMatch.create(matchDetails)
|
||||
}
|
||||
|
||||
matchFromRiot = await DetailedMatchTransformer.transform(matchFromRiot)
|
||||
|
||||
// DetailedMatch.save(matchFromRiot)
|
||||
console.timeEnd('MatchDetails')
|
||||
|
||||
return response.json({
|
||||
matchDetails: matchFromRiot
|
||||
matchDetails
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class SummonerController {
|
|||
Jax.regionName = region
|
||||
|
||||
try {
|
||||
const account = await Jax.Summoner.summonerName(summoner)
|
||||
const account = await SummonerService.getAccount(summoner, region)
|
||||
// Check if the summoner is found
|
||||
if (!account) return response.json(null)
|
||||
account.region = region
|
||||
|
|
|
|||
|
|
@ -4,21 +4,62 @@ const Jax = use('Jax')
|
|||
const Redis = use('Redis')
|
||||
|
||||
class SummonerService {
|
||||
constructor() {
|
||||
this.uniqueLeagues = ['CHALLENGER', 'GRANDMASTER', 'MASTER']
|
||||
this.leaguesNumbers = { 'I': 1, 'II': 2, 'III': 3, 'IV': 4 }
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to transform League Data from the Riot API
|
||||
* @param league raw data of the league from Riot API
|
||||
*/
|
||||
_getleagueData(league) {
|
||||
if (!league) return null
|
||||
league.fullRank = this.uniqueLeagues.includes(league.tier) ? league.tier : `${league.tier} ${league.rank}`
|
||||
league.winrate = +(league.wins * 100 / (league.wins + league.losses)).toFixed(1) + '%'
|
||||
league.shortName = this.uniqueLeagues.includes(league.tier) ? league.leaguePoints : league.tier[0] + this.leaguesNumbers[league.rank]
|
||||
return league
|
||||
}
|
||||
|
||||
/**
|
||||
* Get account infos for a searched summoner name
|
||||
* @param summonerName
|
||||
* @param region
|
||||
*/
|
||||
async getAccount(summonerName, region) {
|
||||
const name = summonerName.toLowerCase().replace(/ /g, '')
|
||||
const accountCache = await Redis.get(`${region}-${name}`)
|
||||
if (accountCache) {
|
||||
console.log('ACCOUNT CACHED')
|
||||
return JSON.parse(accountCache)
|
||||
}
|
||||
|
||||
const account = await Jax.Summoner.summonerName(name)
|
||||
if (account) {
|
||||
await Redis.set(`${region}-${name}`, JSON.stringify(account), 'EX', 36000)
|
||||
}
|
||||
return account
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ranked data for a specific Summoner
|
||||
* @param account
|
||||
*/
|
||||
async getRanked(account) {
|
||||
const rankedCache = await Redis.get(`ranked-${account.puuid}`)
|
||||
if (rankedCache) {
|
||||
console.log('RANKED CACHED')
|
||||
return JSON.parse(rankedCache)
|
||||
} else {
|
||||
const ranked = await Jax.League.summonerID(account.id)
|
||||
const result = {
|
||||
soloQ: ranked.find(e => e.queueType === 'RANKED_SOLO_5x5') || null,
|
||||
flex5v5: ranked.find(e => e.queueType === 'RANKED_FLEX_SR') || null,
|
||||
flex3v3: ranked.find(e => e.queueType === 'RANKED_FLEX_TT') || null
|
||||
}
|
||||
await Redis.set(`ranked-${account.puuid}`, JSON.stringify(result), 'EX', 10)
|
||||
return result
|
||||
}
|
||||
|
||||
const ranked = await Jax.League.summonerID(account.id)
|
||||
const result = {
|
||||
soloQ: this._getleagueData(ranked.find(e => e.queueType === 'RANKED_SOLO_5x5')) || null,
|
||||
flex5v5: this._getleagueData(ranked.find(e => e.queueType === 'RANKED_FLEX_SR')) || null,
|
||||
flex3v3: this._getleagueData(ranked.find(e => e.queueType === 'RANKED_FLEX_TT')) || null
|
||||
}
|
||||
await Redis.set(`ranked-${account.puuid}`, JSON.stringify(result), 'EX', 1500)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
'use strict'
|
||||
|
||||
const MatchTransformer = use('App/Transformers/MatchTransformer')
|
||||
const SummonerService = use('App/Services/SummonerService')
|
||||
|
||||
/**
|
||||
* DetailedMatchTransformer class
|
||||
|
|
@ -19,8 +20,8 @@ class DetailedMatchTransformer extends MatchTransformer {
|
|||
const globalInfos = super.getGameInfos(match)
|
||||
|
||||
// Teams
|
||||
const firstTeam = this.getTeamData(match, match.teams[0])
|
||||
const secondTeam = this.getTeamData(match, match.teams[1])
|
||||
const firstTeam = await this.getTeamData(match, match.teams[0])
|
||||
const secondTeam = await this.getTeamData(match, match.teams[1])
|
||||
|
||||
return {
|
||||
gameId: match.gameId,
|
||||
|
|
@ -36,7 +37,7 @@ class DetailedMatchTransformer extends MatchTransformer {
|
|||
* @param match raw match data from Riot API
|
||||
* @param team raw team data from Riot API
|
||||
*/
|
||||
getTeamData(match, team) {
|
||||
async getTeamData(match, team) {
|
||||
let win = team.win
|
||||
if (match.gameDuration < 300) {
|
||||
win = 'Remake'
|
||||
|
|
@ -72,10 +73,13 @@ class DetailedMatchTransformer extends MatchTransformer {
|
|||
}
|
||||
|
||||
// Players
|
||||
const players = teamPlayers
|
||||
let players = teamPlayers
|
||||
.map(p => super.getPlayerData(match, p, true, teamStats))
|
||||
.sort(this.sortTeamByRole)
|
||||
|
||||
const requests = players.map(p => this.getPlayerRank(p, match.platformId))
|
||||
players = await Promise.all(requests)
|
||||
|
||||
return {
|
||||
bans,
|
||||
barons: team.baronKills,
|
||||
|
|
@ -89,6 +93,23 @@ class DetailedMatchTransformer extends MatchTransformer {
|
|||
towers: team.towerKills,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the soloQ rank of all the players of the team
|
||||
* @param summoner all the data of the summoner
|
||||
* @param region of the match
|
||||
*/
|
||||
async getPlayerRank(summoner, region) {
|
||||
const account = await SummonerService.getAccount(summoner.name, region)
|
||||
if (account) {
|
||||
const ranked = await SummonerService.getRanked(account)
|
||||
summoner.rank = ranked.soloQ ? (({ tier, shortName }) => ({ tier, shortName }))(ranked.soloQ) : null
|
||||
} else {
|
||||
summoner.rank = null
|
||||
}
|
||||
|
||||
return summoner
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new DetailedMatchTransformer()
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ class MatchTransformer {
|
|||
map: match.mapId,
|
||||
gamemode: match.queueId,
|
||||
date: match.gameCreation,
|
||||
region: match.platformId.toLowerCase(),
|
||||
time: match.gameDuration
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue