Add Player and Tournament classes in smashgg
These classes do not match 1:1 with their smash.gg equivalent, but are more specific to this app.master
parent
01533d3d7b
commit
f4116f46cb
|
@ -8,6 +8,121 @@ API_URL = "{scheme}://{host}/{endpoint}".format(
|
||||||
endpoint = API_ENDPOINT,
|
endpoint = API_ENDPOINT,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
class Player():
|
||||||
|
"""A Player, as registered by the smash.gg API, and their characters
|
||||||
|
choices and placement in a tournament"""
|
||||||
|
|
||||||
|
CHARACTERS =
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------------
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
id,
|
||||||
|
prefix,
|
||||||
|
gamerTag,
|
||||||
|
placement,
|
||||||
|
seeding,
|
||||||
|
twitterHandle = None,
|
||||||
|
chars = {}
|
||||||
|
)
|
||||||
|
self.id = id
|
||||||
|
self.prefix = prefix
|
||||||
|
self.gamerTag = gamerTag
|
||||||
|
self.placement = placement
|
||||||
|
self.seeding = seeding
|
||||||
|
self.twitterHandle = twitterHandle
|
||||||
|
|
||||||
|
self.chars = chars
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------------
|
||||||
|
def add_character_selection(self, character, win):
|
||||||
|
try:
|
||||||
|
self.chars[character] += ( 1.01 if win else 1.00 )
|
||||||
|
# This 1.01 / 1.00 tricks should hold until the player loses 101
|
||||||
|
# matches with one character and wins 100 matches with another...
|
||||||
|
# during one tournament.
|
||||||
|
except KeyError:
|
||||||
|
self.chars[character] = ( 1.01 if win else 1.00 )
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------------
|
||||||
|
def conf(self):
|
||||||
|
|
||||||
|
charslist = ", ".join(
|
||||||
|
[ "{} ({:.2f})".format(c,self.chars[c]) for c in self.chars ]
|
||||||
|
)
|
||||||
|
|
||||||
|
return """
|
||||||
|
[player {tag}]
|
||||||
|
tag: {tag}
|
||||||
|
team: {pfx}
|
||||||
|
seeding: {seed}
|
||||||
|
placement: {plc}
|
||||||
|
twitter: {twi}
|
||||||
|
characters: {charslist}""" \
|
||||||
|
.format(
|
||||||
|
tag = self.gamerTag,
|
||||||
|
pfx = self.prefix,
|
||||||
|
seed = self.seeding,
|
||||||
|
plc = self.placement,
|
||||||
|
twi = self.twitterHandle,
|
||||||
|
charslist = charslist,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
class Tournament():
|
||||||
|
"""A Tournament, as registered by the smash.gg API"""
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------------
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
slug,
|
||||||
|
startAt,
|
||||||
|
numEntrants,
|
||||||
|
venueAddress = None,
|
||||||
|
venueName = None,
|
||||||
|
city = None,
|
||||||
|
countryCode = None,
|
||||||
|
hashtag = None,
|
||||||
|
):
|
||||||
|
self.id = id
|
||||||
|
self.name = name
|
||||||
|
self.slug = slug
|
||||||
|
self.startAt = startAt
|
||||||
|
self.numEntrants = numEntrants
|
||||||
|
self.venueAddress = venueAddress
|
||||||
|
self.venueName = venueName
|
||||||
|
self.city = city
|
||||||
|
self.countryCode = countryCode
|
||||||
|
self.hashtag = hashtag
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------------
|
||||||
|
def conf(self):
|
||||||
|
return """
|
||||||
|
[Tournament]
|
||||||
|
name: {name}
|
||||||
|
date: {date}
|
||||||
|
location: {loc}
|
||||||
|
slug: {slug}
|
||||||
|
numEntrants: {nbe}""" \
|
||||||
|
.format(
|
||||||
|
id = self.id,
|
||||||
|
name = self.name,
|
||||||
|
date = self.startAt,
|
||||||
|
loc = self.venueName,
|
||||||
|
slug = self.slug,
|
||||||
|
nbe = self.numEntrants,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
def run_query(
|
def run_query(
|
||||||
query_name,
|
query_name,
|
||||||
|
|
Loading…
Reference in New Issue