Skip to content

Commit

Permalink
#1 close MergeValues 동작 변경(List -> Generator)
Browse files Browse the repository at this point in the history
  • Loading branch information
laoraid committed May 24, 2020
1 parent dc0fc48 commit 2c480c0
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 62 deletions.
19 changes: 6 additions & 13 deletions KartRider/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
from .apiwrapper import (
from .apiwrapper import ( # noqa
Api, TooManyRequest, ForbiddenToken, InvalidToken,
NotFound, UnknownStatusCode
)

from .metadata import (
from .user import User # noqa

from .metadata import ( # noqa
set_metadatapath, getCharactersDict, getflyingPetsDict,
getgameTypesDict, getKartsDict, getPetsDict, getTracksDict, getImagePath,
getCharacterName, getCharacterId, getFlyingPetId, getFlyingPetName,
getGameTypeId, getGameTypeName, getKartId, getKartName, getPetId,
getPetName, getTrackId, getTrackName, download_meta, downmeta_ifnotexist)

__all__ = ['Api', 'TooManyRequest', 'ForbiddenToken',
'InvalidToken', 'NotFound', 'UnknownStatusCode',
'set_metadatapath', 'getCharactersDict', 'getflyingPetsDict',
'getgameTypesDict', 'getKartsDict', 'getPetsDict',
'getTracksDict', 'getImagePath', 'getCharacterName',
'getCharacterId', 'getFlyingPetId', 'getFlyingPetName',
'getGameTypeId', 'getGameTypeName', 'getKartId',
'getKartName', 'getPetId', 'getPetName', 'getTrackId',
'getTrackName', 'download_meta', 'downmeta_ifnotexist']
getPetName, getTrackId, getTrackName,
download_meta, downmeta_ifnotexist)
25 changes: 8 additions & 17 deletions KartRider/basedata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import TypeVar, Mapping
from typing import TypeVar, Mapping, Iterator


class _BaseData(object):
Expand Down Expand Up @@ -37,24 +37,15 @@ class MergeAbleDict(dict, Mapping[str, T]):
def __init__(self, *args, **kwargs):
super(MergeAbleDict, self).__init__(*args, **kwargs)

def mergeValues(self) -> list:
"""dict의 리스트 밸류들을 모두 하나로 합칩니다.
def mergeValues(self) -> Iterator[T]:
"""dict의 리스트 밸류들을 순회하는 제너레이터입니다.
게임타입을 key로, 게임 정보의 리스트를 value 로 가지는 dict에서
게임타입을 무시하고게임 정보의 리스트를 합쳐 1차원 리스트로 반환합니다.
게임타입을 무시하고 게임 정보의 리스트를 합쳐 순회합니다.
:return: 게임 정보의 리스트
:rtype: list
:yield: :class:`KartRider.match.MatchDetail` 또는
:class:`KartRider.match.MatchInfo`
:rtype: Iterator[T]
"""
length = sum(len(x) for x in self.values())
li = [None] * length

i = 0

for v in self.values():
for rr in v:
li[i] = rr
i += 1

return li
yield from v
2 changes: 1 addition & 1 deletion __about__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '0.5.0'
__version__ = '0.5.1'
__author__ = 'Laoraid'
2 changes: 1 addition & 1 deletion docs/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 99c50beedd471061f3d6b4a739b0b5a9
config: 8866989c96e9e2b0a44e38098c0762d7
tags: 645f666f9bcd5a90fca523b33c5a78b7
25 changes: 13 additions & 12 deletions docs/KartRider.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>KartRider.py &mdash; KartRider 0.5.0 문서</title>
<title>KartRider.py &mdash; KartRider 0.5.1 문서</title>



Expand Down Expand Up @@ -228,26 +228,26 @@ <h3>가장 최근 매치의 상세 정보 불러오기<a class="headerlink" href

<span class="n">allmatches</span> <span class="o">=</span> <span class="n">api</span><span class="o">.</span><span class="n">getAllMatches</span><span class="p">(</span><span class="n">limit</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>

<span class="n">game</span> <span class="o">=</span> <span class="n">allmatches</span><span class="o">.</span><span class="n">mergeValues</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">game</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">allmatches</span><span class="o">.</span><span class="n">mergeValues</span><span class="p">())[</span><span class="mi">0</span><span class="p">]</span>

<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;게임 : </span><span class="si">{}</span><span class="s1">, 채널 이름 : </span><span class="si">{}</span><span class="s1">, 트랙 이름 : </span><span class="si">{}</span><span class="s1">&#39;</span>
<span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">game</span><span class="o">.</span><span class="n">matchType</span><span class="p">,</span> <span class="n">game</span><span class="o">.</span><span class="n">channelName</span><span class="p">,</span> <span class="n">game</span><span class="o">.</span><span class="n">track</span><span class="p">))</span>
<span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">game</span><span class="o">.</span><span class="n">matchType</span><span class="p">,</span> <span class="n">game</span><span class="o">.</span><span class="n">channelName</span><span class="p">,</span> <span class="n">game</span><span class="o">.</span><span class="n">track</span><span class="p">))</span>

<span class="k">if</span> <span class="n">game</span><span class="o">.</span><span class="n">isTeamGame</span><span class="p">:</span>
<span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">players</span> <span class="ow">in</span> <span class="n">game</span><span class="o">.</span><span class="n">teams</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">{}</span><span class="s1">팀 :&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">i</span><span class="p">))</span>
<span class="k">for</span> <span class="n">player</span> <span class="ow">in</span> <span class="n">players</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;닉네임 : </span><span class="si">{}</span><span class="s1">, 캐릭터 : </span><span class="si">{}</span><span class="s1">, 카트 : </span><span class="si">{}</span><span class="s1">, 순위 : </span><span class="si">{}</span><span class="s1">, 리타이어 여부 : </span><span class="si">{}</span><span class="s1">&#39;</span>
<span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">player</span><span class="o">.</span><span class="n">characterName</span><span class="p">,</span> <span class="n">player</span><span class="o">.</span><span class="n">character</span><span class="p">,</span> <span class="n">player</span><span class="o">.</span><span class="n">kart</span><span class="p">,</span>
<span class="n">player</span><span class="o">.</span><span class="n">matchRank</span><span class="p">,</span> <span class="n">player</span><span class="o">.</span><span class="n">matchRetired</span><span class="p">))</span>
<span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">player</span><span class="o">.</span><span class="n">characterName</span><span class="p">,</span> <span class="n">player</span><span class="o">.</span><span class="n">character</span><span class="p">,</span> <span class="n">player</span><span class="o">.</span><span class="n">kart</span><span class="p">,</span>
<span class="n">player</span><span class="o">.</span><span class="n">matchRank</span><span class="p">,</span> <span class="n">player</span><span class="o">.</span><span class="n">matchRetired</span><span class="p">))</span>
<span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>

<span class="k">else</span><span class="p">:</span>
<span class="k">for</span> <span class="n">player</span> <span class="ow">in</span> <span class="n">game</span><span class="o">.</span><span class="n">players</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;닉네임 : </span><span class="si">{}</span><span class="s1">, 캐릭터 : </span><span class="si">{}</span><span class="s1">, 카트 : </span><span class="si">{}</span><span class="s1">, 순위 : </span><span class="si">{}</span><span class="s1">, 리타이어 여부 : </span><span class="si">{}</span><span class="s1">&#39;</span>
<span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">player</span><span class="o">.</span><span class="n">characterName</span><span class="p">,</span> <span class="n">player</span><span class="o">.</span><span class="n">character</span><span class="p">,</span> <span class="n">player</span><span class="o">.</span><span class="n">kart</span><span class="p">,</span>
<span class="n">player</span><span class="o">.</span><span class="n">matchRank</span><span class="p">,</span> <span class="n">player</span><span class="o">.</span><span class="n">matchRetired</span><span class="p">))</span>
<span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">player</span><span class="o">.</span><span class="n">characterName</span><span class="p">,</span> <span class="n">player</span><span class="o">.</span><span class="n">character</span><span class="p">,</span> <span class="n">player</span><span class="o">.</span><span class="n">kart</span><span class="p">,</span>
<span class="n">player</span><span class="o">.</span><span class="n">matchRank</span><span class="p">,</span> <span class="n">player</span><span class="o">.</span><span class="n">matchRetired</span><span class="p">))</span>
</pre></div>
</div>
</div>
Expand Down Expand Up @@ -714,15 +714,16 @@ <h2>레퍼런스<a class="headerlink" href="#id6" title="제목 주소">¶</a></
<dl class="method">
<dt id="KartRider.basedata.MergeAbleDict.mergeValues">
<code class="sig-name descname">mergeValues</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#KartRider.basedata.MergeAbleDict.mergeValues" title="정의 주소"></a></dt>
<dd><p>dict의 리스트 밸류들을 모두 하나로 합칩니다.</p>
<dd><p>dict의 리스트 밸류들을 순회하는 제너레이터입니다.</p>
<p>게임타입을 key로, 게임 정보의 리스트를 value 로 가지는 dict에서
게임타입을 무시하고게임 정보의 리스트를 합쳐 1차원 리스트로 반환합니다.</p>
게임타입을 무시하고 게임 정보의 리스트를 합쳐 순회합니다.</p>
<dl class="field-list simple">
<dt class="field-odd">반환값</dt>
<dd class="field-odd"><p>게임 정보의 리스트</p>
<dt class="field-odd">Yield</dt>
<dd class="field-odd"><p><a class="reference internal" href="#KartRider.match.MatchDetail" title="KartRider.match.MatchDetail"><code class="xref py py-class docutils literal notranslate"><span class="pre">KartRider.match.MatchDetail</span></code></a> 또는
<a class="reference internal" href="#KartRider.match.MatchInfo" title="KartRider.match.MatchInfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">KartRider.match.MatchInfo</span></code></a></p>
</dd>
<dt class="field-even">반환 형식</dt>
<dd class="field-even"><p>list</p>
<dd class="field-even"><p>Iterator[T]</p>
</dd>
</dl>
</dd></dl>
Expand Down
12 changes: 6 additions & 6 deletions docs/KartRider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,26 @@ API KEY는 공개적으로 저장하지 마세요.
allmatches = api.getAllMatches(limit=1)
game = allmatches.mergeValues()[0]
game = list(allmatches.mergeValues())[0]
print('게임 : {}, 채널 이름 : {}, 트랙 이름 : {}'
.format(game.matchType, game.channelName, game.track))
.format(game.matchType, game.channelName, game.track))
if game.isTeamGame:
i = 0
for players in game.teams:
print('{}팀 :'.format(i))
for player in players:
print('닉네임 : {}, 캐릭터 : {}, 카트 : {}, 순위 : {}, 리타이어 여부 : {}'
.format(player.characterName, player.character, player.kart,
player.matchRank, player.matchRetired))
.format(player.characterName, player.character, player.kart,
player.matchRank, player.matchRetired))
i += 1
else:
for player in game.players:
print('닉네임 : {}, 캐릭터 : {}, 카트 : {}, 순위 : {}, 리타이어 여부 : {}'
.format(player.characterName, player.character, player.kart,
player.matchRank, player.matchRetired))
.format(player.characterName, player.character, player.kart,
player.matchRank, player.matchRetired))
----------------------------
Expand Down
12 changes: 6 additions & 6 deletions docs/_sources/KartRider.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,26 @@ API KEY는 공개적으로 저장하지 마세요.
allmatches = api.getAllMatches(limit=1)
game = allmatches.mergeValues()[0]
game = list(allmatches.mergeValues())[0]
print('게임 : {}, 채널 이름 : {}, 트랙 이름 : {}'
.format(game.matchType, game.channelName, game.track))
.format(game.matchType, game.channelName, game.track))
if game.isTeamGame:
i = 0
for players in game.teams:
print('{}팀 :'.format(i))
for player in players:
print('닉네임 : {}, 캐릭터 : {}, 카트 : {}, 순위 : {}, 리타이어 여부 : {}'
.format(player.characterName, player.character, player.kart,
player.matchRank, player.matchRetired))
.format(player.characterName, player.character, player.kart,
player.matchRank, player.matchRetired))
i += 1
else:
for player in game.players:
print('닉네임 : {}, 캐릭터 : {}, 카트 : {}, 순위 : {}, 리타이어 여부 : {}'
.format(player.characterName, player.character, player.kart,
player.matchRank, player.matchRetired))
.format(player.characterName, player.character, player.kart,
player.matchRank, player.matchRetired))
----------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>색인 &mdash; KartRider 0.5.0 문서</title>
<title>색인 &mdash; KartRider 0.5.1 문서</title>



Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Welcome to KartRider’s documentation! &mdash; KartRider 0.5.0 문서</title>
<title>Welcome to KartRider’s documentation! &mdash; KartRider 0.5.1 문서</title>



Expand Down
2 changes: 1 addition & 1 deletion docs/py-modindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Python 모듈 목록 &mdash; KartRider 0.5.0 문서</title>
<title>Python 모듈 목록 &mdash; KartRider 0.5.1 문서</title>



Expand Down
2 changes: 1 addition & 1 deletion docs/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>검색 &mdash; KartRider 0.5.0 문서</title>
<title>검색 &mdash; KartRider 0.5.1 문서</title>



Expand Down
Loading

0 comments on commit 2c480c0

Please sign in to comment.