Exemple #1
0
    def __init__(self, match, show_href=False):
        home_record, away_record = match.get_team_records_query().fetch(2)

        self.team_data = {}
        for which, record in (("home", home_record), ("away", away_record)):
            self.team_data[which] = {
                'team_href': record.team.get_box_href(),
                'record': record,
                'text_color':
                misc.get_contrasting_monochrome(record.team.color),
            }

        scorer_records = match.get_player_records_query().filter(
            "tds_for >", 0)
        scorer_data = [(r.tds_for if r.tds_for > 1 else None,
                        0 if r.team_record.key() == home_record.key() else 1,
                        r.player.get_box_anchor("match_players"))
                       for r in scorer_records]

        self.disconnect = match.disconnect
        self.tournament_match_up = match.tournamentmatchup_set.get()
        self.scorer_data = scorer_data
        self.time = match.created.strftime("%A %B %d, %Y, %I:%M%p")

        if show_href:
            self.href = match.get_box_href()
Exemple #2
0
  def __init__(self, match, show_href=False):
    home_record, away_record = match.get_team_records_query().fetch(2)

    self.team_data = {}
    for which, record in (("home", home_record), ("away", away_record)):
      self.team_data[which] = {
          'team_href': record.team.get_box_href(),
          'record': record,
          'text_color': misc.get_contrasting_monochrome(record.team.color),
          }

    scorer_records = match.get_player_records_query().filter("tds_for >", 0)
    scorer_data = [
        ( r.tds_for if r.tds_for > 1 else None,
          0 if r.team_record.key() == home_record.key() else 1,
          r.player.get_box_anchor("match_players"))
      for r in scorer_records]

    self.disconnect = match.disconnect
    self.tournament_match_up = match.tournamentmatchup_set.get()
    self.scorer_data = scorer_data
    self.time = match.created.strftime("%A %B %d, %Y, %I:%M%p")

    if show_href:
      self.href = match.get_box_href()
Exemple #3
0
    def get(self):

        # check for a cached version
        #--------------------------------------------------------------------#

        coach_key = db.Key.from_path("Coach",
                                     self.request.get("coach_key_name"))
        if self.emit(self.response.out, coach_key):
            return

        # not cached or evicted from cache; regenerate
        #--------------------------------------------------------------------#

        coach = Coach.get(coach_key)
        if not coach:
            return

        coach_stats = CoachStats.all().ancestor(coach).get()
        # win/draw/loss bars and banner text color
        #--------------------------------------------------------------------#

        longest_bar_length = max(coach_stats.wins, coach_stats.draws,
                                 coach_stats.losses)
        banner_text_color = misc.get_contrasting_monochrome(coach.color)

        # team_table
        #--------------------------------------------------------------------#

        def name_getter(team):
            return "<a rel='team' href='%s'>%s</a>" % (team.get_box_href(),
                                                       team.key().name())

        def race_getter(team):
            return "<img title='%s' src='%s' />" % (
                team.race.key().name(), team.race.get_image_src(thumb=True))

        def awp_getter(team):
            return "%0.3f" % team.awp

        def glicko_getter(team):
            return "%4.0f" % team.glicko_r

        teams = query = Team.all().filter("coach =",
                                          coach).filter("matches >",
                                                        0).order("-matches")
        team_table = Table(
            columns=[
                # profile
                Column(" ", "Race", race_getter, center=True),
                Column("Team Name", "Team name", name_getter),
                Column("TV",
                       "Team value (approximate)",
                       attrgetter("tv"),
                       divider=True),

                # record
                Column("Pl", "Matches played", attrgetter("matches")),
                Column("W", "Matches won", attrgetter("wins")),
                Column("D", "Matches drawn", attrgetter("draws")),
                Column("L", "Matches lost", attrgetter("losses"),
                       divider=True),

                # rankings
                Column("AWP", "Adjusted win percentage", awp_getter),
                Column("TPts", "Tournament Points", attrgetter("tpts")),
                Column("Rating", "Glicko Rating", glicko_getter, divider=True),

                ## touchdowns
                #Column("TD+",       "Touchdowns for",     attrgetter("tds_for")),
                #Column("TD-",       "Touchdowns against", attrgetter("tds_against")),
                #Column("<span class='over'>TD+</span>",  "Average touchdowns for",
                #  get_ave_getter("tds_for")),
                #Column("<span class='over'>TD-</span>",  "Average touchdowns against",
                #  get_ave_getter("tds_against")),

                ## casualties
                #Column("C+",        "Casualties for",     attrgetter("cas_for")),
                #Column("C-",        "Casualties against", attrgetter("cas_against")),
                #Column("<span class='over'>C+</span>",  "Average casualties for",
                #  get_ave_getter("cas_for")),
                #Column("<span class='over'>C-</span>",  "Average casualties against",
                #  get_ave_getter("cas_against")),
            ],
            query=teams,
            id="%s-team-table" % coach.key(),
            cls="tablesorter",
        )

        # coach_stat_table
        #--------------------------------------------------------------------#

        def get_left_header(tuple):
            coach_stats, which = tuple
            return which.capitalize()

        def getter(stat):
            def getter_closure(tuple):
                coach_stats, which = tuple
                attr = getattr(coach_stats, "%s_%s" % (stat, which))
                return (("<span class='tot_stat'>%d</span>" % attr) +
                        ("<span class='ave_stat'>%.1f</span>" %
                         (attr / float(coach_stats.matches))))

            return getter_closure

        stat_table = Table(
            columns=[
                Column(
                    "<span class='link' id='%s-show-averages-toggle'></span>" %
                    coach.key(), "", get_left_header),
                Column("TD", "Touchdowns", getter("tds")),
                Column("P", "Pass completions", getter("passes")),
                Column("YP", "Yards passing", getter("pyards")),
                Column("R", "Pass receptions", getter("rec")),
                Column("YR", "Yards rushing", getter("ryards")),
                Column("K", "Kills", getter("kills")),
                Column("C", "Casualties", getter("cas")),
                Column("KO", "Knock outs", getter("ko")),
                Column("S", "Stuns", getter("stun")),
                Column("T", "Tackles", getter("tckl")),
                Column("I", "Interceptions", getter("int")),
            ],
            query=((coach_stats, "for"), (coach_stats, "against")),
            cls="fancytable stats",
        )

        # match_tables
        #--------------------------------------------------------------------#

        def name_getter(record):
            if record.team.key() == team.key():
                return team.key().name()
            else:
                return "<a rel='team_opponents' href='%s'>%s</a>" % (
                    record.team.get_box_href(), record.team.key().name())

        def race_getter(record):
            return "<img src='%s' />" % record.team.race.get_image_src(
                thumb=True)

        def link_getter(record):
            return """
      <a rel='team_matches' href='%s'>
      <span class="go_to_arrow" title='Go to match page'>&rarr;</span></a>""" % (
                record.get_match().get_box_href())

        def glicko_getter(record):
            return "%4.0f" % record.glicko_r

        match_columns = [
            Column(" ", "Race", race_getter, center=True),
            Column("Team", "Team name", name_getter),
            Column("Rating", "Team rating", glicko_getter),
            Column("TV", "Team value", attrgetter("tv_for")),
            Column("TD", "Touchdowns", attrgetter("tds_for")),
            Column("P", "Pass completions", attrgetter("passes_for")),
            Column("YP", "Yards passing", attrgetter("pyards_for")),
            Column("R", "Pass receptions", attrgetter("rec_for")),
            Column("YR", "Yards rushing", attrgetter("ryards_for")),
            Column("K", "Kills", attrgetter("kills_for")),
            Column("C", "Casualties", attrgetter("cas_for")),
            Column("KO", "Knock outs", attrgetter("ko_for")),
            Column("S", "Stuns", attrgetter("stun_for")),
            Column("T", "Tackles", attrgetter("tckl_for")),
            Column("I", "Interceptions", attrgetter("int_for")),
            Column("", "", link_getter, center=True, rowspan=2)
        ]

        # get matches from match_records and sort in order of most recent
        result = []
        for team in teams:
            for record in TeamRecord.all().filter("team =", team):
                if record is not None:
                    result.append(record)

        matches = sorted([record.get_match() for record in result],
                         key=lambda m: m.created,
                         reverse=True)[:30]

        match_tables = []
        for match in matches:
            # sort with this team's match record first
            match_records = sorted(match.get_team_records_query(),
                                   key=lambda mr: mr.team.coach == coach,
                                   reverse=True)

            result_map = {1: "WIN!", 0: "DRAW", -1: "LOSS"}

            coach_flag = 0
            if match_records[1].team.coach:
                if coach.key() == match_records[1].team.coach.key():
                    coach_flag = 1
            title = "(%s) <b>%s-%s %s</b> %s  vs. %s" % (
                match.created.date(), match_records[0].tds_for,
                match_records[1].tds_for,
                result_map[match_records[coach_flag].result],
                match_records[0].team.key().name(),
                match_records[1].team.key().name())

            if match.disconnect:
                title += " (Disconnect/Forfeit)"

            match_table = Table(columns=match_columns,
                                query=match_records,
                                cls="tablesorter match_stats",
                                title=title)

            match_tables.append((match.get_box_href(), match_table))


#    active_member = team.get_active_tournament_membership()
#    active_tournament = active_member.parent() if active_member else None

# render and update (TODO: move to bottom after implementing bottom code)
#--------------------------------------------------------------------#

        coach_box = misc.render('coach_box.html', locals())
        self.update(coach_box, coach_key)

        self.response.out.write(coach_box)
Exemple #4
0
  def get(self):

    # check for a cached version
    #--------------------------------------------------------------------#

    player_key = db.Key.from_path("Player", self.request.get("player_key_name"))
    if self.emit(self.response.out, player_key):
      return

    # not cached or evicted from cache; regenerate
    #--------------------------------------------------------------------#

    player = Player.get(player_key)
    if not player:
      return

    # player card
    #--------------------------------------------------------------------#

    banner_text_color = misc.get_contrasting_monochrome(player.team.color)

    attr_table = Table(
        columns = [
          Column("MV", "Movement Allowance", attrgetter("mv")),
          Column("ST", "Strength",           attrgetter("st")),
          Column("AG", "Agility",            attrgetter("ag")),
          Column("AV", "Armor Value",        attrgetter("av")),
          ],
        query = (player,),
        cls = "attr",
        )

    injuries = []
    for injury_key in player.injuries:
      injury = db.get(injury_key)
      if injury.key().name() == "Dead":
        injuries.append("DEAD")
      elif injury.permanent:
        injuries.append("%s (%s)" % (injury.key().name(), injury.effect))
    injuries = ", ".join(x for x in injuries)

    skills = [k.name() for k in player.skills]
    if player.level_up_pending:
      skills.append("<i>Pending Level-Up</i>")
    skills = ", ".join(skills)

    # stat_table
    #--------------------------------------------------------------------#

    def get_left_header(tuple):
      player, which = tuple
      return which.capitalize()

    def getter(stat):
      def getter_closure(tuple):
        player, which = tuple
        try:
          attr = getattr(player, "%s_%s" % (stat, which))
          ave_attr = attr if player.played == 0 else attr / float(player.played)
          return """<div class='tot_stat'>%d</div>
                    <div class='ave_stat'>%.1f</div>""" % (
                        attr, ave_attr)
        except AttributeError:
          return "-"

      return getter_closure

    stat_table = Table(
        columns = [
          Column("<span class='link' id='%s-show-averages-toggle'></span>" %
            player.key(), "", get_left_header),
          Column("TD", "Touchdowns",       getter("tds")),
          Column("P",  "Pass completions", getter("passes")),
          Column("YP", "Yards passing",    getter("pyards")),
          Column("R",  "Pass receptions",  getter("rec")),
          Column("YR", "Yards rushing",    getter("ryards")),
          Column("K",  "Kills",            getter("kills")),
          Column("C",  "Casualties",       getter("cas")),
          Column("KO", "Knock outs",       getter("ko")),
          Column("S",  "Stuns",            getter("stun")),
          Column("T",  "Tackles",          getter("tckl")),
          Column("I",  "Interceptions",    getter("int")),
          ],
        query = ((player, "for"), (player, "against")),
        cls = "fancytable stats",
        )

    # match_table
    #--------------------------------------------------------------------#

    def name_getter(record):
      opponent = record.team_record.opponent_record.team
      return "<a rel='player_opponents' href='%s'>%s</a>" % (
          opponent.get_box_href(), opponent.key().name())

    def race_getter(record):
      opponent = record.team_record.opponent_record.team
      return "<img src='%s' />" % opponent.race.get_image_src(thumb=True)

    def date_getter(record):
      return record.get_match().created.date()

    def link_getter(record):
      return """
      <a rel='player_matches' href='%s'>
      <span class='go_to_arrow' title='Go to match page'>&rarr;</span></a>""" % (
          record.get_match().get_box_href())

    match_table = Table(
        columns = [
          Column("Date",      "Match date",            date_getter),
          Column("Opponent",  "Opponent name",         name_getter),
          Column(" ",         "Race",                  race_getter,
            center=True),
          Column("TD",        "Touchdowns",            attrgetter("tds_for")),
          Column("MVP",       "Most Valuable Player Awards", attrgetter("mvps")),
          Column("P",         "Pass completions",      attrgetter("passes_for")),
          Column("YP",        "Yards passing",         attrgetter("pyards_for")),
          Column("R",         "Pass receptions",       attrgetter("rec_for")),
          Column("YR",        "Yards rushing",         attrgetter("ryards_for")),
          Column("K+",        "Kills for",             attrgetter("kills_for")),
          Column("C+",        "Casualties for",        attrgetter("cas_for")),
          Column("KO+",       "Knock outs for",        attrgetter("ko_for")),
          Column("S+",        "Stuns for",             attrgetter("stun_for")),
          Column("T+",        "Tackles for",           attrgetter("tckl_for")),
          Column("I+",        "Interceptions for",     attrgetter("int_for")),
          Column("K-",        "Kills against",         attrgetter("kills_against")),
          Column("C-",        "Casualties against",    attrgetter("cas_against")),
          Column("KO-",       "Knock outs against",    attrgetter("ko_against")),
          Column("S-",        "Stuns against",         attrgetter("stun_against")),
          Column("T-",        "Tackles against",       attrgetter("tckl_against")),
          Column("I-",        "Interceptions against", attrgetter("int_against")),
          Column("", "", link_getter, center=True)
          ],
        query = player.playerrecord_set.filter("played =", 1),
        cls = "tablesorter match_stats",
        )

    # render and update
    #--------------------------------------------------------------------#

    player_box = misc.render('player_box.html', locals())
    self.update(player_box, player_key)

    self.response.out.write(player_box)
Exemple #5
0
    def get(self):

        # check for a cached version
        #--------------------------------------------------------------------#

        player_key = db.Key.from_path("Player",
                                      self.request.get("player_key_name"))
        if self.emit(self.response.out, player_key):
            return

        # not cached or evicted from cache; regenerate
        #--------------------------------------------------------------------#

        player = Player.get(player_key)
        if not player:
            return

        # player card
        #--------------------------------------------------------------------#

        banner_text_color = misc.get_contrasting_monochrome(player.team.color)

        attr_table = Table(
            columns=[
                Column("MV", "Movement Allowance", attrgetter("mv")),
                Column("ST", "Strength", attrgetter("st")),
                Column("AG", "Agility", attrgetter("ag")),
                Column("AV", "Armor Value", attrgetter("av")),
            ],
            query=(player, ),
            cls="attr",
        )

        injuries = []
        for injury_key in player.injuries:
            injury = db.get(injury_key)
            if injury.key().name() == "Dead":
                injuries.append("DEAD")
            elif injury.permanent:
                injuries.append("%s (%s)" %
                                (injury.key().name(), injury.effect))
        injuries = ", ".join(x for x in injuries)

        skills = [k.name() for k in player.skills]
        if player.level_up_pending:
            skills.append("<i>Pending Level-Up</i>")
        skills = ", ".join(skills)

        # stat_table
        #--------------------------------------------------------------------#

        def get_left_header(tuple):
            player, which = tuple
            return which.capitalize()

        def getter(stat):
            def getter_closure(tuple):
                player, which = tuple
                try:
                    attr = getattr(player, "%s_%s" % (stat, which))
                    ave_attr = attr if player.played == 0 else attr / float(
                        player.played)
                    return """<div class='tot_stat'>%d</div>
                    <div class='ave_stat'>%.1f</div>""" % (attr, ave_attr)
                except AttributeError:
                    return "-"

            return getter_closure

        stat_table = Table(
            columns=[
                Column(
                    "<span class='link' id='%s-show-averages-toggle'></span>" %
                    player.key(), "", get_left_header),
                Column("TD", "Touchdowns", getter("tds")),
                Column("P", "Pass completions", getter("passes")),
                Column("YP", "Yards passing", getter("pyards")),
                Column("R", "Pass receptions", getter("rec")),
                Column("YR", "Yards rushing", getter("ryards")),
                Column("K", "Kills", getter("kills")),
                Column("C", "Casualties", getter("cas")),
                Column("KO", "Knock outs", getter("ko")),
                Column("S", "Stuns", getter("stun")),
                Column("T", "Tackles", getter("tckl")),
                Column("I", "Interceptions", getter("int")),
            ],
            query=((player, "for"), (player, "against")),
            cls="fancytable stats",
        )

        # match_table
        #--------------------------------------------------------------------#

        def name_getter(record):
            opponent = record.team_record.opponent_record.team
            return "<a rel='player_opponents' href='%s'>%s</a>" % (
                opponent.get_box_href(), opponent.key().name())

        def race_getter(record):
            opponent = record.team_record.opponent_record.team
            return "<img src='%s' />" % opponent.race.get_image_src(thumb=True)

        def date_getter(record):
            return record.get_match().created.date()

        def link_getter(record):
            return """
      <a rel='player_matches' href='%s'>
      <span class='go_to_arrow' title='Go to match page'>&rarr;</span></a>""" % (
                record.get_match().get_box_href())

        match_table = Table(
            columns=[
                Column("Date", "Match date", date_getter),
                Column("Opponent", "Opponent name", name_getter),
                Column(" ", "Race", race_getter, center=True),
                Column("TD", "Touchdowns", attrgetter("tds_for")),
                Column("MVP", "Most Valuable Player Awards",
                       attrgetter("mvps")),
                Column("P", "Pass completions", attrgetter("passes_for")),
                Column("YP", "Yards passing", attrgetter("pyards_for")),
                Column("R", "Pass receptions", attrgetter("rec_for")),
                Column("YR", "Yards rushing", attrgetter("ryards_for")),
                Column("K+", "Kills for", attrgetter("kills_for")),
                Column("C+", "Casualties for", attrgetter("cas_for")),
                Column("KO+", "Knock outs for", attrgetter("ko_for")),
                Column("S+", "Stuns for", attrgetter("stun_for")),
                Column("T+", "Tackles for", attrgetter("tckl_for")),
                Column("I+", "Interceptions for", attrgetter("int_for")),
                Column("K-", "Kills against", attrgetter("kills_against")),
                Column("C-", "Casualties against", attrgetter("cas_against")),
                Column("KO-", "Knock outs against", attrgetter("ko_against")),
                Column("S-", "Stuns against", attrgetter("stun_against")),
                Column("T-", "Tackles against", attrgetter("tckl_against")),
                Column("I-", "Interceptions against",
                       attrgetter("int_against")),
                Column("", "", link_getter, center=True)
            ],
            query=player.playerrecord_set.filter("played =", 1),
            cls="tablesorter match_stats",
        )

        # render and update
        #--------------------------------------------------------------------#

        player_box = misc.render('player_box.html', locals())
        self.update(player_box, player_key)

        self.response.out.write(player_box)
Exemple #6
0
    def get(self):

        # check for a cached version
        # --------------------------------------------------------------------#

        team_key = db.Key.from_path("Team", self.request.get("team_key_name"))
        if self.emit(self.response.out, team_key):
            return

        # not cached or evicted from cache; regenerate
        # --------------------------------------------------------------------#

        team = Team.get(team_key)
        if not team:
            return

        # win/draw/loss bars and banner text color
        # --------------------------------------------------------------------#

        longest_bar_length = max(team.wins, team.draws, team.losses)
        banner_text_color = misc.get_contrasting_monochrome(team.color)

        # player_table
        # --------------------------------------------------------------------#

        def position_getter(player):
            return player.position.key().name()

        def name_getter(player):
            if player.played:
                return "<a rel='team_players' href='%s'>%s</a>" % (player.get_box_href(), player.name)
            else:
                return "<b>" + player.name + "</b>"

        def mng_getter(player):
            if player.missing_next_game:
                return "<img src='images/logos/thumb/logo_neutre_10.png' />"
            else:
                return ""

        player_table = Table(
            columns=[
                Column("#", "Player number", attrgetter("number"), center=True),
                Column("MNG", "Missing next game", mng_getter, center=True),
                Column("Player", "Player name", name_getter),
                Column("Position", "Player position", position_getter, divider=True),
                Column("MV", "Movement allowance", attrgetter("mv")),
                Column("ST", "Strength", attrgetter("st")),
                Column("AG", "Agility", attrgetter("ag")),
                Column("AV", "Armor value", attrgetter("av"), divider=True),
                Column("SPP", "Star player points", attrgetter("spp")),
                Column("Level", "Level", attrgetter("level"), divider=True),
                Column("Pl", "Matches played", attrgetter("played")),
                Column("MVP", "Most Valuable Player awards", attrgetter("mvps")),
                Column("TD", "Touchdowns", attrgetter("tds_for")),
                Column("P", "Pass completions", attrgetter("passes_for")),
                Column("YP", "Yards passing", attrgetter("pyards_for")),
                Column("R", "Pass receptions", attrgetter("rec_for")),
                Column("YR", "Yards rushing", attrgetter("ryards_for")),
                Column("K", "Kills", attrgetter("kills_for")),
                Column("C", "Casualties", attrgetter("cas_for")),
                Column("KO", "Knock outs", attrgetter("ko_for")),
                Column("S", "Stuns", attrgetter("stun_for")),
                Column("T", "Tackles", attrgetter("tckl_for")),
                Column("I", "Interceptions", attrgetter("int_for"), divider=True),
                Column("Value", "Player value", attrgetter("value")),
            ],
            query=team.player_set.filter("retired =", False),
            id="%s-player-table" % team.key(),
            cls="tablesorter",
        )

        # stat_table
        # --------------------------------------------------------------------#

        def get_left_header(tuple):
            team, which = tuple
            return which.capitalize()

        def getter(stat):
            def getter_closure(tuple):
                team, which = tuple
                attr = getattr(team, "%s_%s" % (stat, which))
                return ("<span class='tot_stat'>%d</span>" % attr) + (
                    "<span class='ave_stat'>%.1f</span>" % (attr / float(team.matches))
                )

            return getter_closure

        stat_table = Table(
            columns=[
                Column("<span class='link' id='%s-show-averages-toggle'></span>" % team.key(), "", get_left_header),
                Column("TD", "Touchdowns", getter("tds")),
                Column("P", "Pass completions", getter("passes")),
                Column("YP", "Yards passing", getter("pyards")),
                Column("R", "Pass receptions", getter("rec")),
                Column("YR", "Yards rushing", getter("ryards")),
                Column("K", "Kills", getter("kills")),
                Column("C", "Casualties", getter("cas")),
                Column("KO", "Knock outs", getter("ko")),
                Column("S", "Stuns", getter("stun")),
                Column("T", "Tackles", getter("tckl")),
                Column("I", "Interceptions", getter("int")),
            ],
            query=((team, "for"), (team, "against")),
            cls="fancytable stats",
        )

        # match_tables
        # --------------------------------------------------------------------#

        def name_getter(record):
            if record.team.key() == team.key():
                return team.key().name()
            else:
                return "<a rel='team_opponents' href='%s'>%s</a>" % (
                    record.team.get_box_href(),
                    record.team.key().name(),
                )

        def race_getter(record):
            return "<img src='%s' />" % record.team.race.get_image_src(thumb=True)

        def link_getter(record):
            return """
      <a rel='team_matches' href='%s'>
      <span class="go_to_arrow" title='Go to match page'>&rarr;</span></a>""" % (
                record.get_match().get_box_href()
            )

        def glicko_getter(record):
            return "%4.0f" % record.glicko_r

        match_columns = [
            Column(" ", "Race", race_getter, center=True),
            Column("Team", "Team name", name_getter),
            Column("Rating", "Team rating", glicko_getter),
            Column("TV", "Team value", attrgetter("tv_for")),
            Column("TD", "Touchdowns", attrgetter("tds_for")),
            Column("P", "Pass completions", attrgetter("passes_for")),
            Column("YP", "Yards passing", attrgetter("pyards_for")),
            Column("R", "Pass receptions", attrgetter("rec_for")),
            Column("YR", "Yards rushing", attrgetter("ryards_for")),
            Column("K", "Kills", attrgetter("kills_for")),
            Column("C", "Casualties", attrgetter("cas_for")),
            Column("KO", "Knock outs", attrgetter("ko_for")),
            Column("S", "Stuns", attrgetter("stun_for")),
            Column("T", "Tackles", attrgetter("tckl_for")),
            Column("I", "Interceptions", attrgetter("int_for")),
            Column("", "", link_getter, center=True, rowspan=2),
        ]

        # get matches from match_records and sort in order of most recent
        matches = sorted([record.get_match() for record in team.teamrecord_set], key=lambda m: m.created, reverse=True)

        match_tables = []
        for match in matches:
            # sort with this team's match record first
            match_records = sorted(
                match.get_team_records_query(), key=lambda mr: mr.team.key() == team.key(), reverse=True
            )

            result_map = {1: "WIN!", 0: "DRAW", -1: "LOSS"}

            title = "(%s) <b>%s-%s %s</b> vs. %s" % (
                match.created.date(),
                match_records[0].tds_for,
                match_records[1].tds_for,
                result_map[match_records[0].result],
                match_records[1].team.key().name(),
            )

            if match.disconnect:
                title += " (Disconnect/Forfeit)"

            match_table = Table(columns=match_columns, query=match_records, cls="tablesorter match_stats", title=title)

            match_tables.append((match.get_box_href(), match_table))

        active_member = team.get_active_tournament_membership()
        active_tournament = active_member.parent() if active_member else None

        # render and update
        # --------------------------------------------------------------------#

        team_box = misc.render("team_box.html", locals())
        self.update(team_box, team_key)

        self.response.out.write(team_box)
Exemple #7
0
  def get(self):

    # check for a cached version
    #--------------------------------------------------------------------#

    coach_key = db.Key.from_path("Coach", self.request.get("coach_key_name"))
    if self.emit(self.response.out, coach_key):
      return

    # not cached or evicted from cache; regenerate
    #--------------------------------------------------------------------#

    coach = Coach.get(coach_key)
    if not coach:
      return

    coach_stats = CoachStats.all().ancestor(coach).get()
    # win/draw/loss bars and banner text color
    #--------------------------------------------------------------------#

    longest_bar_length = max(coach_stats.wins, coach_stats.draws, coach_stats.losses)
    banner_text_color = misc.get_contrasting_monochrome(coach.color)

    # team_table
    #--------------------------------------------------------------------#

    def name_getter(team):
      return "<a rel='team' href='%s'>%s</a>" % (
          team.get_box_href(), team.key().name())

    def race_getter(team):
      return "<img title='%s' src='%s' />" % (
          team.race.key().name(), team.race.get_image_src(thumb=True))

    def awp_getter(team):
      return "%0.3f" % team.awp

    def glicko_getter(team):
      return "%4.0f" % team.glicko_r
    
    teams = query = Team.all().filter("coach =", coach).filter("matches >", 0).order("-matches")
    team_table = Table(
          columns = [
            # profile
            Column(" ",         "Race",               race_getter, center=True),
            Column("Team Name", "Team name",          name_getter),
            Column("TV",        "Team value (approximate)",
              attrgetter("tv"), divider=True),

            # record
            Column("Pl",        "Matches played",     attrgetter("matches")),
            Column("W",         "Matches won",        attrgetter("wins")),
            Column("D",         "Matches drawn",      attrgetter("draws")),
            Column("L",         "Matches lost",       attrgetter("losses"),
              divider=True),

            # rankings
            Column("AWP",       "Adjusted win percentage", awp_getter),
            Column("TPts",      "Tournament Points",       attrgetter("tpts")),
            Column("Rating",    "Glicko Rating",           glicko_getter,
              divider=True),

            ## touchdowns
            #Column("TD+",       "Touchdowns for",     attrgetter("tds_for")),
            #Column("TD-",       "Touchdowns against", attrgetter("tds_against")),
            #Column("<span class='over'>TD+</span>",  "Average touchdowns for",
            #  get_ave_getter("tds_for")),
            #Column("<span class='over'>TD-</span>",  "Average touchdowns against",
            #  get_ave_getter("tds_against")),

            ## casualties
            #Column("C+",        "Casualties for",     attrgetter("cas_for")),
            #Column("C-",        "Casualties against", attrgetter("cas_against")),
            #Column("<span class='over'>C+</span>",  "Average casualties for",
            #  get_ave_getter("cas_for")),
            #Column("<span class='over'>C-</span>",  "Average casualties against",
            #  get_ave_getter("cas_against")),
            ],
          query = teams,
          id = "%s-team-table" % coach.key(),
          cls = "tablesorter",
          )


    # coach_stat_table
    #--------------------------------------------------------------------#

    def get_left_header(tuple):
      coach_stats, which = tuple
      return which.capitalize()

    def getter(stat):
      def getter_closure(tuple):
        coach_stats, which = tuple
        attr = getattr(coach_stats, "%s_%s" % (stat, which))
        return (
            ("<span class='tot_stat'>%d</span>" % attr) +
            ("<span class='ave_stat'>%.1f</span>" % (attr / float(coach_stats.matches))))

      return getter_closure

    stat_table = Table(
        columns = [
          Column("<span class='link' id='%s-show-averages-toggle'></span>" %
            coach.key(), "", get_left_header),
          Column("TD", "Touchdowns",       getter("tds")),
          Column("P",  "Pass completions", getter("passes")),
          Column("YP", "Yards passing",    getter("pyards")),
          Column("R",  "Pass receptions",  getter("rec")),
          Column("YR", "Yards rushing",    getter("ryards")),
          Column("K",  "Kills",            getter("kills")),
          Column("C",  "Casualties",       getter("cas")),
          Column("KO", "Knock outs",       getter("ko")),
          Column("S",  "Stuns",            getter("stun")),
          Column("T",  "Tackles",          getter("tckl")),
          Column("I",  "Interceptions",    getter("int")),
          ],
        query = ((coach_stats, "for"), (coach_stats, "against")),
        cls = "fancytable stats",
        )

    # render and update (TODO: move to bottom after implementing bottom code)
    #--------------------------------------------------------------------#

    coach_box = misc.render('coach_box.html', locals())
    self.update(coach_box, coach_key)

    self.response.out.write(coach_box)
Exemple #8
0
    def get(self):

        # check for a cached version
        #--------------------------------------------------------------------#

        team_key = db.Key.from_path("Team", self.request.get("team_key_name"))
        if self.emit(self.response.out, team_key):
            return

        # not cached or evicted from cache; regenerate
        #--------------------------------------------------------------------#

        team = Team.get(team_key)
        if not team:
            return

        # win/draw/loss bars and banner text color
        #--------------------------------------------------------------------#

        longest_bar_length = max(team.wins, team.draws, team.losses)
        banner_text_color = misc.get_contrasting_monochrome(team.color)

        # player_table
        #--------------------------------------------------------------------#

        def position_getter(player):
            return player.position.key().name()

        def name_getter(player):
            if player.played:
                return "<a rel='team_players' href='%s'>%s</a>" % (
                    player.get_box_href(), player.name)
            else:
                return "<b>" + player.name + "</b>"

        def mng_getter(player):
            if player.missing_next_game:
                return "<img src='images/logos/thumb/logo_neutre_10.png' />"
            else:
                return ""

        player_table = Table(
            columns=[
                Column("#", "Player number", attrgetter("number"),
                       center=True),
                Column("MNG", "Missing next game", mng_getter, center=True),
                Column("Player", "Player name", name_getter),
                Column("Position",
                       "Player position",
                       position_getter,
                       divider=True),
                Column("MV", "Movement allowance", attrgetter("mv")),
                Column("ST", "Strength", attrgetter("st")),
                Column("AG", "Agility", attrgetter("ag")),
                Column("AV", "Armor value", attrgetter("av"), divider=True),
                Column("SPP", "Star player points", attrgetter("spp")),
                Column("Level", "Level", attrgetter("level"), divider=True),
                Column("Pl", "Matches played", attrgetter("played")),
                Column("MVP", "Most Valuable Player awards",
                       attrgetter("mvps")),
                Column("TD", "Touchdowns", attrgetter("tds_for")),
                Column("P", "Pass completions", attrgetter("passes_for")),
                Column("YP", "Yards passing", attrgetter("pyards_for")),
                Column("R", "Pass receptions", attrgetter("rec_for")),
                Column("YR", "Yards rushing", attrgetter("ryards_for")),
                Column("K", "Kills", attrgetter("kills_for")),
                Column("C", "Casualties", attrgetter("cas_for")),
                Column("KO", "Knock outs", attrgetter("ko_for")),
                Column("S", "Stuns", attrgetter("stun_for")),
                Column("T", "Tackles", attrgetter("tckl_for")),
                Column("I",
                       "Interceptions",
                       attrgetter("int_for"),
                       divider=True),
                Column("Value", "Player value", attrgetter("value")),
            ],
            query=team.player_set.filter("retired =", False),
            id="%s-player-table" % team.key(),
            cls="tablesorter",
        )

        # stat_table
        #--------------------------------------------------------------------#

        def get_left_header(tuple):
            team, which = tuple
            return which.capitalize()

        def getter(stat):
            def getter_closure(tuple):
                team, which = tuple
                attr = getattr(team, "%s_%s" % (stat, which))
                return (("<span class='tot_stat'>%d</span>" % attr) +
                        ("<span class='ave_stat'>%.1f</span>" %
                         (attr / float(team.matches))))

            return getter_closure

        stat_table = Table(
            columns=[
                Column(
                    "<span class='link' id='%s-show-averages-toggle'></span>" %
                    team.key(), "", get_left_header),
                Column("TD", "Touchdowns", getter("tds")),
                Column("P", "Pass completions", getter("passes")),
                Column("YP", "Yards passing", getter("pyards")),
                Column("R", "Pass receptions", getter("rec")),
                Column("YR", "Yards rushing", getter("ryards")),
                Column("K", "Kills", getter("kills")),
                Column("C", "Casualties", getter("cas")),
                Column("KO", "Knock outs", getter("ko")),
                Column("S", "Stuns", getter("stun")),
                Column("T", "Tackles", getter("tckl")),
                Column("I", "Interceptions", getter("int")),
            ],
            query=((team, "for"), (team, "against")),
            cls="fancytable stats",
        )

        # match_tables
        #--------------------------------------------------------------------#

        def name_getter(record):
            if record.team.key() == team.key():
                return team.key().name()
            else:
                return "<a rel='team_opponents' href='%s'>%s</a>" % (
                    record.team.get_box_href(), record.team.key().name())

        def race_getter(record):
            return "<img src='%s' />" % record.team.race.get_image_src(
                thumb=True)

        def link_getter(record):
            return """
      <a rel='team_matches' href='%s'>
      <span class="go_to_arrow" title='Go to match page'>&rarr;</span></a>""" % (
                record.get_match().get_box_href())

        def glicko_getter(record):
            return "%4.0f" % record.glicko_r

        match_columns = [
            Column(" ", "Race", race_getter, center=True),
            Column("Team", "Team name", name_getter),
            Column("Rating", "Team rating", glicko_getter),
            Column("TV", "Team value", attrgetter("tv_for")),
            Column("TD", "Touchdowns", attrgetter("tds_for")),
            Column("P", "Pass completions", attrgetter("passes_for")),
            Column("YP", "Yards passing", attrgetter("pyards_for")),
            Column("R", "Pass receptions", attrgetter("rec_for")),
            Column("YR", "Yards rushing", attrgetter("ryards_for")),
            Column("K", "Kills", attrgetter("kills_for")),
            Column("C", "Casualties", attrgetter("cas_for")),
            Column("KO", "Knock outs", attrgetter("ko_for")),
            Column("S", "Stuns", attrgetter("stun_for")),
            Column("T", "Tackles", attrgetter("tckl_for")),
            Column("I", "Interceptions", attrgetter("int_for")),
            Column("", "", link_getter, center=True, rowspan=2)
        ]

        # get matches from match_records and sort in order of most recent
        matches = sorted(
            [record.get_match() for record in team.teamrecord_set],
            key=lambda m: m.created,
            reverse=True)

        match_tables = []
        for match in matches:
            # sort with this team's match record first
            match_records = sorted(match.get_team_records_query(),
                                   key=lambda mr: mr.team.key() == team.key(),
                                   reverse=True)

            result_map = {1: "WIN!", 0: "DRAW", -1: "LOSS"}

            title = "(%s) <b>%s-%s %s</b> vs. %s" % (
                match.created.date(), match_records[0].tds_for,
                match_records[1].tds_for, result_map[match_records[0].result],
                match_records[1].team.key().name())

            if match.disconnect:
                title += " (Disconnect/Forfeit)"

            match_table = Table(columns=match_columns,
                                query=match_records,
                                cls="tablesorter match_stats",
                                title=title)

            match_tables.append((match.get_box_href(), match_table))

        active_member = team.get_active_tournament_membership()
        active_tournament = active_member.parent() if active_member else None

        # render and update
        #--------------------------------------------------------------------#

        team_box = misc.render('team_box.html', locals())
        self.update(team_box, team_key)

        self.response.out.write(team_box)
Exemple #9
0
  def get(self):

    # check for a cached version
    #--------------------------------------------------------------------#

    coach_key = db.Key.from_path("Coach", self.request.get("coach_key_name"))
    if self.emit(self.response.out, coach_key):
      return

    # not cached or evicted from cache; regenerate
    #--------------------------------------------------------------------#

    coach = Coach.get(coach_key)
    if not coach:
      return

    coach_stats = CoachStats.all().ancestor(coach).get()
    # win/draw/loss bars and banner text color
    #--------------------------------------------------------------------#

    longest_bar_length = max(coach_stats.wins, coach_stats.draws, coach_stats.losses)
    banner_text_color = misc.get_contrasting_monochrome(coach.color)

    # team_table
    #--------------------------------------------------------------------#

    def name_getter(team):
      return "<a rel='team' href='%s'>%s</a>" % (
          team.get_box_href(), team.key().name())

    def race_getter(team):
      return "<img title='%s' src='%s' />" % (
          team.race.key().name(), team.race.get_image_src(thumb=True))

    def awp_getter(team):
      return "%0.3f" % team.awp

    def glicko_getter(team):
      return "%4.0f" % team.glicko_r
    
    teams = query = Team.all().filter("coach =", coach).filter("matches >", 0).order("-matches")
    team_table = Table(
          columns = [
            # profile
            Column(" ",         "Race",               race_getter, center=True),
            Column("Team Name", "Team name",          name_getter),
            Column("TV",        "Team value (approximate)",
              attrgetter("tv"), divider=True),

            # record
            Column("Pl",        "Matches played",     attrgetter("matches")),
            Column("W",         "Matches won",        attrgetter("wins")),
            Column("D",         "Matches drawn",      attrgetter("draws")),
            Column("L",         "Matches lost",       attrgetter("losses"),
              divider=True),

            # rankings
            Column("AWP",       "Adjusted win percentage", awp_getter),
            Column("TPts",      "Tournament Points",       attrgetter("tpts")),
            Column("Rating",    "Glicko Rating",           glicko_getter,
              divider=True),

            ## touchdowns
            #Column("TD+",       "Touchdowns for",     attrgetter("tds_for")),
            #Column("TD-",       "Touchdowns against", attrgetter("tds_against")),
            #Column("<span class='over'>TD+</span>",  "Average touchdowns for",
            #  get_ave_getter("tds_for")),
            #Column("<span class='over'>TD-</span>",  "Average touchdowns against",
            #  get_ave_getter("tds_against")),

            ## casualties
            #Column("C+",        "Casualties for",     attrgetter("cas_for")),
            #Column("C-",        "Casualties against", attrgetter("cas_against")),
            #Column("<span class='over'>C+</span>",  "Average casualties for",
            #  get_ave_getter("cas_for")),
            #Column("<span class='over'>C-</span>",  "Average casualties against",
            #  get_ave_getter("cas_against")),
            ],
          query = teams,
          id = "%s-team-table" % coach.key(),
          cls = "tablesorter",
          )


    # coach_stat_table
    #--------------------------------------------------------------------#

    def get_left_header(tuple):
      coach_stats, which = tuple
      return which.capitalize()

    def getter(stat):
      def getter_closure(tuple):
        coach_stats, which = tuple
        attr = getattr(coach_stats, "%s_%s" % (stat, which))
        return (
            ("<span class='tot_stat'>%d</span>" % attr) +
            ("<span class='ave_stat'>%.1f</span>" % (attr / float(coach_stats.matches))))

      return getter_closure

    stat_table = Table(
        columns = [
          Column("<span class='link' id='%s-show-averages-toggle'></span>" %
            coach.key(), "", get_left_header),
          Column("TD", "Touchdowns",       getter("tds")),
          Column("P",  "Pass completions", getter("passes")),
          Column("YP", "Yards passing",    getter("pyards")),
          Column("R",  "Pass receptions",  getter("rec")),
          Column("YR", "Yards rushing",    getter("ryards")),
          Column("K",  "Kills",            getter("kills")),
          Column("C",  "Casualties",       getter("cas")),
          Column("KO", "Knock outs",       getter("ko")),
          Column("S",  "Stuns",            getter("stun")),
          Column("T",  "Tackles",          getter("tckl")),
          Column("I",  "Interceptions",    getter("int")),
          ],
        query = ((coach_stats, "for"), (coach_stats, "against")),
        cls = "fancytable stats",
        )

    # match_tables
    #--------------------------------------------------------------------#

    def name_getter(record):
      if record.team.key() == team.key():
        return team.key().name()
      else:
        return "<a rel='team_opponents' href='%s'>%s</a>" % (
            record.team.get_box_href(), record.team.key().name())

    def race_getter(record):
      return "<img src='%s' />" % record.team.race.get_image_src(thumb=True)

    def link_getter(record):
      return """
      <a rel='team_matches' href='%s'>
      <span class="go_to_arrow" title='Go to match page'>&rarr;</span></a>""" % (
          record.get_match().get_box_href())

    def glicko_getter(record):
      return "%4.0f" % record.glicko_r

    match_columns = [
        Column(" ",         "Race",             race_getter,
          center=True),
        Column("Team",      "Team name",        name_getter),
        Column("Rating",    "Team rating",      glicko_getter),
        Column("TV",        "Team value",       attrgetter("tv_for")),
        Column("TD",        "Touchdowns",       attrgetter("tds_for")),
        Column("P",         "Pass completions", attrgetter("passes_for")),
        Column("YP",        "Yards passing",    attrgetter("pyards_for")),
        Column("R",         "Pass receptions",  attrgetter("rec_for")),
        Column("YR",        "Yards rushing",    attrgetter("ryards_for")),
        Column("K",         "Kills",            attrgetter("kills_for")),
        Column("C",         "Casualties",       attrgetter("cas_for")),
        Column("KO",        "Knock outs",       attrgetter("ko_for")),
        Column("S",         "Stuns",            attrgetter("stun_for")),
        Column("T",         "Tackles",          attrgetter("tckl_for")),
        Column("I",         "Interceptions",    attrgetter("int_for")),
        Column("", "", link_getter, center=True, rowspan=2)
        ]

    # get matches from match_records and sort in order of most recent
    result = []
    for team in teams:
      for record in TeamRecord.all().filter("team =", team):
        if record is not None:
          result.append(record)

    matches = sorted([record.get_match() for record in result],key=lambda m: m.created, reverse=True)[:30]

    match_tables = []
    for match in matches:
      # sort with this team's match record first
      match_records = sorted(
          match.get_team_records_query(),
          key=lambda mr: mr.team.coach == coach,
          reverse=True)

      result_map = {
          1  : "WIN!",
          0  : "DRAW",
          -1 : "LOSS"}

      coach_flag = 0
      if match_records[1].team.coach:
        if coach.key() == match_records[1].team.coach.key():
          coach_flag = 1
      title = "(%s) <b>%s-%s %s</b> %s  vs. %s" % (
          match.created.date(),
          match_records[0].tds_for,
          match_records[1].tds_for,
          result_map[match_records[coach_flag].result],
          match_records[0].team.key().name(),
          match_records[1].team.key().name())

      if match.disconnect:
        title += " (Disconnect/Forfeit)"

      match_table = Table(
          columns = match_columns,
          query = match_records,
          cls = "tablesorter match_stats",
          title = title)

      match_tables.append((match.get_box_href(), match_table))

#    active_member = team.get_active_tournament_membership()
#    active_tournament = active_member.parent() if active_member else None

    # render and update (TODO: move to bottom after implementing bottom code)
    #--------------------------------------------------------------------#

    coach_box = misc.render('coach_box.html', locals())
    self.update(coach_box, coach_key)

    self.response.out.write(coach_box)