Ejemplo n.º 1
0
    def get(self):

        user = users.get_current_user()
        if user:
            log_out_url = users.create_logout_url("/")
            coach = Coach.all().filter("user ="******"retired =", False).filter(
                    "coach =", None)
                coach_team_table = get_coach_team_table(coach)
                coach_player_tables = get_coach_player_tables(coach)
                coach_tournament_table = get_coach_tournament_table(coach)

                ofl_admin = misc.is_admin(coach.key().name())

                if ofl_admin:
                    ineligible_teams = [
                        team for team in Team.all().filter("status >", 0)
                        if (team.test_flag(TeamProfile.PRE_LE_FLAG)
                            or team.test_flag(TeamProfile.INCONSISTENT_FLAG))
                    ]

        else:
            log_in_url = users.create_login_url("/")

        races = Race.all()

        self.response.out.write(misc.render('coachs_page.html', locals()))
Ejemplo n.º 2
0
  def get(self):

    user = users.get_current_user()
    if user:
      log_out_url = users.create_logout_url("/")
      coach = Coach.all().filter("user ="******"retired =", False).filter("coach =", None)
        coach_team_table = get_coach_team_table(coach)
        coach_player_tables = get_coach_player_tables(coach)
        coach_tournament_table = get_coach_tournament_table(coach)

        ofl_admin = coach.key().name() in [
            "masher", "Thul", "Isryion", "bob152", "Styxx" , "mardaed"]

        if ofl_admin:
          ineligible_teams = [
              team for team in Team.all().filter("status >", 0)
              if (team.test_flag(TeamProfile.PRE_LE_FLAG) or
                  team.test_flag(TeamProfile.INCONSISTENT_FLAG))]

    else:
      log_in_url = users.create_login_url("/")

    races = Race.all()

    self.response.out.write(
        misc.render('coachs_page.html', locals()))
Ejemplo n.º 3
0
    def get(self):

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

        if self.emit(self.response.out):
            return

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

        matches_data = []
        for match in Match.all().filter("processed =", True).order("-created").fetch(10):
            matches_data.append(MatchData(match, show_href=True))

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

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

        self.response.out.write(recent_matches)
Ejemplo n.º 4
0
    def get(self):

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

        if self.emit(self.response.out):
            return

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

        matches_data = []
        for match in Match.all().filter('processed =',
                                        True).order('-created').fetch(10):
            matches_data.append(MatchData(match, show_href=True))

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

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

        self.response.out.write(recent_matches)
Ejemplo n.º 5
0
    def get(self):

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

        if self.emit(self.response.out):
            return

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

        season, week = misc.get_ofl_season_and_week()
        ofl_week = (season - 1) * 16 + week

        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 coach_getter(team):
            if team.coach:
                return "<a rel='coach' href='%s'>%s</a>" % (
                    team.coach.get_box_href(), team.coach.key().name())
            else:
                return "<i>Unknown</i>"

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

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

        def status_getter(team):
            html = []

            matches = team.matches
            if team.pre_wins != None:
                matches += team.pre_wins + team.pre_draws + team.pre_losses

            #if (team.status or matches > ofl_week or not team.coach):
            #  html.append("<span class='red_text'>OFL Ineligible</span>")

            if not team.coach:
                html.append("<span class='orange_text'>(Unclaimed!)</span>")

            elif team.test_flag(models.TeamProfile.INCONSISTENT_FLAG):
                html.append(
                    "<span class='red_text'>(Inconsistent Data!)</span>")

            #  elif team.test_flag(models.TeamProfile.INELIGIBLE_FLAG):
            #    html.append("<span class='orange_text'>(Exceeds Quota)</b>")

            elif team.test_flag(models.TeamProfile.PRE_LE_FLAG):
                html.append(
                    "<span class='yellow_text'>(Incomplete History)</span>")

            # else:
            #  html.append("<span class='orange_text'>(Ahead of OFL Schedule)</b>")

            else:
                html.append("<span class='green_text'>Consistent Data</span>")

            if team.pre_wins != None:
                html.append(
                    "<span class='yellow_text'>(Pre-LE history validated: %sW-%sD-%sL)</span>"
                    % (team.pre_wins, team.pre_draws, team.pre_losses))

            return " ".join(html)

        #def get_ave_getter(attr):
        #  def ave_getter(team):
        #    return "%.1f" % (float(getattr(team, attr)) / team.matches)
        #  return ave_getter

        tables = {}
        #Getting rid of retired table
        #for label in ("active", "retired"):
        #Taking for loop out, and removing an indent from tables line
        label = "active"
        tables[label] = Table(
            columns=[
                # profile
                Column(" ", "Race", race_getter, center=True),
                Column("Team Name", "Team name", name_getter),
                Column("Coach", "Coach", coach_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),
                Column("Status & Eligibility",
                       "OFTL/OFL Status and/or Eligibility", status_getter),
                ## 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 = models.Team.all().filter("retired =", label == "retired").filter(
            #  "matches >", 0).order("-matches"),
            query=models.Team.all().filter("matches >",
                                           0).order("-matches").fetch(50),
            id="team-standings-table",
            cls="tablesorter",
        )

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

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

        self.response.out.write(league_standings)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
  def get(self):

    
    user = users.get_current_user()
    if user:
      log_out_url = users.create_logout_url("/")
      coach = Coach.all().filter("user ="******"<img src='http://www.oldworldfootball.com/%s'/>" % (match.teamAlogo)
          return html

        def logoB_getter(match):
          html = "<img src='http://www.oldworldfootball.com/%s'/>" % (match.teamBlogo)
          return html

        def nameA_getter(prediction):
          match = OFL_Match.get_by_key_name(prediction.key().name())
          html = "%s (%s - %s)" % (match.teamA, match.teamAcoach, match.teamArace)
          return html

        def nameB_getter(prediction):
          match = OFL_Match.get_by_key_name(prediction.key().name())
          html = "%s (%s - %s)" % (match.teamB, match.teamBcoach, match.teamBrace)
          return html

        def key_name_getter(prediction):
          return prediction.key().name()

        def choice_getter(prediction):
          match = OFL_Match.get_by_key_name(prediction.key().name())
          #html = "<img src='./get_wager_pic?keyname=%s&team=A'/>" % (prediction.key().name())
          html = "<img src='http://www.oldworldfootball.com/%s'/>" % (match.teamAlogo)
          if not match.gamePlayed:
            html += "<input type='radio' name='%schoice' value='-1' %s>" % (match.key().name(), prediction.isChecked(-1))
            html += "<input type='radio' name='%schoice' value='0' %s>" % (match.key().name(), prediction.isChecked(0))
            html += "<input type='radio' name='%schoice' value='1' %s>" % (match.key().name(), prediction.isChecked(1))
          else:
            html += "<input type='radio' name='%schoice' value='-1' disabled %s>" % (match.key().name(), prediction.isChecked(-1))
            html += "<input type='radio' name='%schoice' value='0' disabled %s>" % (match.key().name(), prediction.isChecked(0))
            html += "<input type='radio' name='%schoice' value='1' disabled %s>" % (match.key().name(), prediction.isChecked(1))
          html += "<img src='http://www.oldworldfootball.com/%s'/>" % (match.teamBlogo)
          #html += "<img src='./get_wager_pic?keyname=%s&team=B'/>" % (prediction.key().name())
          return html
  

        # Bypassing table.html Django template to create this table
        # Table requires Jquery code for sortable entires and wagers
        # Hidden input tags are also used with form.
        prediction_list = OFL_Prediction.all().filter("season =", season).filter("week =", week).ancestor(coach).filter("gameScored =", False).order("-wager")
        columns = ["Wager", "Away Team", "Prediction", "Home Team"]
        table_html = []
        table_html.append('''
        <table class="ofl_pickem schedule_table">
        <thead>
            <tr>''')
        for column in columns:
          table_html.append('<th style="text-align: center;"> %s </th>' % column)
        table_html.append('''
            </tr>
        </thead>
        <tbody id="sortable">''')
        k = 0        
        for prediction in prediction_list:
          table_html.append('<tr class="row_%s">' % k)
          table_html.append('<input type="hidden" name="row_%s" value="%s">' % (k, prediction.key().name()))
          table_html.append("<input type='hidden' class='row_%s' name='%svalue' value='%s'>" % (k, prediction.key().name(), prediction.wager))
          table_html.append('<td class="row_%s" style="text -align: center;">%s</td>' % (k, prediction.wager))
          table_html.append('<td style="text-align: center;">%s</td>' % nameA_getter(prediction))
          table_html.append('<td style="text-align: center;">%s</td>' % choice_getter(prediction))
          table_html.append('<td style="text-align: center;">%s</td>' % nameB_getter(prediction))
          k += 1
        table_html.append('</tbody>\n</table>')
        table_html = "\n".join(table_html)
        
        played_table = Table(
          columns = [
            # profile
            Column("Points",     "Points Earned",      attrgetter("points")),
            Column("Wager",      "Wager Placed",       attrgetter("wager")),
            Column("Away Team",  "Away Team",          nameA_getter, center=True),
            Column("Prediction", "Your Prediction",    choice_getter, center=True),
            Column("Home Team",  "Home Team",          nameB_getter, center=True),
            ],
          query = OFL_Prediction.all().filter("season =", season).filter("week =", week).ancestor(coach).filter("gameScored =", True).order("-points"),
          id = "played_table",
          cls = "tablesorter",
          )
          
      def logo_getter(standing):
        coach = Coach.get_by_key_name(standing.get_coach_name())
        img = "<img src='%s' />" % coach.get_logo_url() # FIXME: thumb is broken
        return "<div style='background-color: %(color)s'>%(img)s</div>" % {
          'color': coach.color, 'img': img}

      def name_getter(standing):
        coach = Coach.get_by_key_name(standing.get_coach_name())
        return "<a class='leader_link' rel='leader_coach' href='%s'>%s</a>" % (
          coach.get_box_href(),coach.key().name())
      
      leader_table = {}
      query = OFLPickemStats.all().order('-all_time').fetch(10)
      label = "alltime"
      leader_table[label] = Table(
          columns = [
            Column(" ",         "Logo",        logo_getter, center=True),
            Column("Coach Name", "Coach name", name_getter),
            Column("Score",     "Score",       attrgetter("all_time")),
            ],
          query = query,
          cls = "leader_table",
          )
          
      query = OFLPickemSeasonRecord.all().filter("season =", season).order("-points").fetch(10)
      label = "season"
      leader_table[label] = Table(
          columns = [
            Column(" ",         "Logo",        logo_getter, center=True),
            Column("Coach Name", "Coach name", name_getter),
            Column("Score",     "Score",       attrgetter("points")),
            ],
          query = query,
          cls = "leader_table",
          )
          
      query = OFLPickemWeekRecord.all().filter("week =", week).filter("season =", season).order("-points").fetch(10)
      label = "week"
      leader_table[label] = Table(
          columns = [
            Column(" ",         "Logo",        logo_getter, center=True),
            Column("Coach Name", "Coach name", name_getter),
            Column("Score",     "Score",       attrgetter("points")),
            ],
          query = query,
          cls = "leader_table",
          )
          
      query = OFLPickemStats.all().order('-matches').fetch(10)
      label = "alltime_matches"
      leader_table[label] = Table(
          columns = [
            Column(" ",         "Logo",        logo_getter, center=True),
            Column("Coach Name", "Coach name", name_getter),
            Column("Matches",     "Matches Predicted",       attrgetter("matches")),
            ],
          query = query,
          cls = "leader_table",
          )
          
      query = OFLPickemSeasonRecord.all().filter("season =", season).order("-matches").fetch(10)
      label = "season_matches"
      leader_table[label] = Table(
          columns = [
            Column(" ",         "Logo",        logo_getter, center=True),
            Column("Coach Name", "Coach name", name_getter),
            Column("Matches",     "Matches Predicted",       attrgetter("matches")),
            ],
          query = query,
          cls = "leader_table",
          )
          
      query = OFLPickemWeekRecord.all().filter("week =", week).filter("season =", season).order("-matches").fetch(10)
      label = "week_matches"
      leader_table[label] = Table(
          columns = [
            Column(" ",         "Logo",        logo_getter, center=True),
            Column("Coach Name", "Coach name", name_getter),
            Column("Matches",     "Matches Predicted",       attrgetter("matches")),
            ],
          query = query,
          cls = "leader_table",
          )    
          
    else:
      log_in_url = users.create_login_url("/") 

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

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

    self.response.out.write(ofl_pickem_page)
      
    
Ejemplo n.º 8
0
  def get(self):

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

    if self.emit(self.response.out):
      return

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

    season, week = misc.get_ofl_season_and_week()
    ofl_week = (season - 1) * 16 + week

    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 coach_getter(team):
      if team.coach:
        return "<a rel='coach' href='%s'>%s</a>" % (
          team.coach.get_box_href(),team.coach.key().name())
      else:
        return "<i>Unknown</i>"

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

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

    def status_getter(team):
      html = []

      matches = team.matches
      if team.pre_wins != None:
        matches += team.pre_wins + team.pre_draws + team.pre_losses

      #if (team.status or matches > ofl_week or not team.coach):
      #  html.append("<span class='red_text'>OFL Ineligible</span>")

      if not team.coach:
          html.append("<span class='orange_text'>(Unclaimed!)</span>")

      elif team.test_flag(models.TeamProfile.INCONSISTENT_FLAG):
          html.append("<span class='red_text'>(Inconsistent Data!)</span>")

      #  elif team.test_flag(models.TeamProfile.INELIGIBLE_FLAG):
      #    html.append("<span class='orange_text'>(Exceeds Quota)</b>")

      elif team.test_flag(models.TeamProfile.PRE_LE_FLAG):
          html.append("<span class='yellow_text'>(Incomplete History)</span>")

       # else:
       #  html.append("<span class='orange_text'>(Ahead of OFL Schedule)</b>")

      else:
          html.append("<span class='green_text'>Consistent Data</span>")

      if team.pre_wins != None:
          html.append(
              "<span class='yellow_text'>(Pre-LE history validated: %sW-%sD-%sL)</span>"
              % (team.pre_wins, team.pre_draws, team.pre_losses))

      return " ".join(html)


    #def get_ave_getter(attr):
    #  def ave_getter(team):
    #    return "%.1f" % (float(getattr(team, attr)) / team.matches)
    #  return ave_getter

    tables = {}
    #Getting rid of retired table
    #for label in ("active", "retired"):
    #Taking for loop out, and removing an indent from tables line
    label = "active"
    tables[label] = Table(
          columns = [
            # profile
            Column(" ",         "Race",               race_getter, center=True),
            Column("Team Name", "Team name",          name_getter),
            Column("Coach",     "Coach",              coach_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),

            Column("Status & Eligibility",
              "OFTL/OFL Status and/or Eligibility",    status_getter),
            ## 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 = models.Team.all().filter("retired =", label == "retired").filter(
            "matches >", 0).order("-matches"),
          id = "team-standings-table",
          cls = "tablesorter",
          )

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

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

    self.response.out.write(league_standings)
Ejemplo n.º 9
0
  def get(self):

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

    match_key = db.Key(self.request.get("match_key"))
    if self.emit(self.response.out, match_key):
      return

    # not cached or evicted from cache; regenerate
    #--------------------------------------------------------------------#
    match = Match.get(match_key)      
      
    if not match:
      return

    home_record, away_record = match.get_team_records_query().fetch(2)
    match_data = MatchData(match)

    # team_match_table
    #--------------------------------------------------------------------#

    def team_name_getter(record):
      return "<a rel='match_teams' 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 glicko_getter(record):
      return "%4.0f" % record.glicko_r

    team_match_table = Table(
        columns = [
          Column(" ",         "Race",             race_getter,
            center=True),
          Column("Team",      "Team name",        team_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")),
          ],
        query = match.get_team_records_query(),
        cls = "tablesorter team_match_table",
        )

    # player_match_tables
    #--------------------------------------------------------------------#

    def number_getter(record):
      return record.player.number

    def player_name_getter(record):
      return record.player.get_box_anchor("match_players")

    def position_getter(record):
      position = record.player.position
      if position.starplayer:
        return "<b>Star Player</b>"
      else:
        return position.key().name()

    player_records = match.get_player_records_query().filter("played =", 1)
    team_player_records = {}
    for record in player_records:
      team_player_records.setdefault(
          record.team_record.team.key().name(), []).append(record)

    player_match_tables = []
    for team_name, record_set in team_player_records.items():
      table = Table(
          columns = [
            Column("#",         "Player number",         number_getter,
              center=True),
            Column("Player",    "Player name",           player_name_getter),
            Column("Position",  "Player position",       position_getter),
            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")),
            ],
          query = record_set,
          cls = "tablesorter player_match_table",
          )

      player_match_tables.append((team_name, table))

    # injury_table
    #--------------------------------------------------------------------#

    def team_name_getter(record):
      return record.team_record.team.key().name()

    def injury_name_getter(record):
      for injury_key in record.match_injuries:
        injury = Injury.get(injury_key)
        if injury.permanent:
          break
      return injury.key().name()

    def injury_effect_getter(record):
      for injury_key in record.match_injuries:
        injury = Injury.get(injury_key)
        if injury.permanent:
          break
      return injury.effect

    injured_player_records = [r for r in player_records if r.match_injuries]

    if injured_player_records:
      injury_table = Table(
          columns = [
            Column("#",      "Player number", number_getter,
              center=True),
            Column("Team",   "Team name",     team_name_getter),
            Column("Player", "Player name",   player_name_getter),
            Column("Position",    "Player position",    position_getter),
            Column("SPP",    "Star player points", attrgetter("spp")),
            Column("Level",  "Level",              attrgetter("level")),
            Column("Injury", "Injury name",   injury_name_getter),
            Column("Effect", "Injury effect", injury_effect_getter),
            ],
          query = injured_player_records,
          cls = "tablesorter injury_table",
          )
    else: 
      injury_table = None


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

    match_box = misc.render('match_box.html', locals())
    self.update(match_box, match_key)

    self.response.out.write(match_box)
Ejemplo n.º 10
0
  def get(self):

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

    if self.emit(self.response.out):
      return

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

    def name_getter(racestats):
      return racestats.race.key().name()

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

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

    def percent_getter(attr):
      def ave_getter(racestats):
        if (racestats.matches > 0):
          return "%.1f" % (float(getattr(racestats, attr)) * 100 / racestats.matches)
        return 0
      return ave_getter

    def get_ave_getter(attr):
      def ave_getter(racestats):
        if (racestats.matches > 0):
          return "%.1f" % (float(getattr(racestats, attr)) / racestats.matches)
        return 0
      return ave_getter

    tables = {}
    label = "active"
    tables[label] = Table(
          columns = [
            # profile
            Column(" ",         "Logo",                      race_getter, center=True),
            Column("Race",      "Race",                      name_getter, divider=True),
            Column("#Teams",    "Number of Teams",             attrgetter("num_of_teams")),
            Column("Matches",        "Matches played",           attrgetter("matches")),
            Column("Wins",         "Wins",                      attrgetter("wins")),
            Column("Draws",         "Draws",                     attrgetter("draws")),
            Column("Losses",         "Losses",                    attrgetter("losses")),
            Column("AWP",       "Adjusted Win Percentage",   awp_getter),
            Column("Win%",         "Win Percentage",           percent_getter("wins")),
            Column("Draw%",         "Draw Percentage",          percent_getter("draws")),
            Column("Loss%",         "Loss Percentage",          percent_getter("losses")),
            Column("TPts",      "Tournament Points",         attrgetter("tpts"), divider=True),

            ],
          query = models.RaceStats.all().order("-awp"),
          id = "race-standings-table",
          cls = "tablesorter",
          )

    label = "average"
    tables[label] = Table(
          columns = [
            # profile
            Column(" ",         "Logo",                      race_getter, center=True),
            Column("Race",      "Race",                      name_getter, divider=True),
            Column("#Tm",    "Number of Teams",             attrgetter("num_of_teams")),
            Column("AWP",       "Adjusted Win Percentage",   awp_getter, divider=True),
            Column("TD+", "Average Touchdowns",                      get_ave_getter("tds_for")),
            Column("P+",  "Average Pass completions",                get_ave_getter("passes_for")),
            Column("YP+", "Average Yards passing",                   get_ave_getter("pyards_for")),
            Column("R+",  "Average Pass receptions",                 get_ave_getter("rec_for")),
            Column("YR+", "Average Yards rushing",                   get_ave_getter("ryards_for")),
            Column("K+",  "Average Kills",                           get_ave_getter("kills_for")),
            Column("C+",  "Average Casualties",                      get_ave_getter("cas_for")),
            Column("KO+", "Average Knock outs",                      get_ave_getter("ko_for")),
            Column("S+",  "Average Stuns",                           get_ave_getter("stun_for")),
            Column("T+",  "Average Tackles",                         get_ave_getter("tckl_for")),
            Column("I+",  "Average Interceptions",                   get_ave_getter("int_for"), divider=True),
            Column("TD-", "Average Touchdowns",                      get_ave_getter("tds_against")),
            Column("P-",  "Average Pass completions",                get_ave_getter("passes_against")),
            Column("YP-", "Average Yards passing",                   get_ave_getter("pyards_against")),
            Column("R-",  "Average Pass receptions",                 get_ave_getter("rec_against")),
            Column("YR-", "Average Yards rushing",                   get_ave_getter("ryards_against")),
            Column("K-",  "Average Kills",                           get_ave_getter("kills_against")),
            Column("C-",  "Average Casualties",                      get_ave_getter("cas_against")),
            Column("KO-", "Average Knock outs",                      get_ave_getter("ko_against")),
            Column("S-",  "Average Stuns",                           get_ave_getter("stun_against")),
            Column("T-",  "Average Tackles",                         get_ave_getter("tckl_against")),
            Column("I-",  "Average Interceptions",                   get_ave_getter("int_against")),
            ],
          query = models.RaceStats.all().order("-awp"),
          id = "race-average-table",
          cls = "tablesorter",
          )

    label = "stats"
    tables[label] = Table(
          columns = [
            # profile
            Column(" ",         "Logo",                      race_getter, center=True),
            Column("Race",      "Race",                      name_getter, divider=True),
            Column("#Tm",    "Number of Teams",              attrgetter("num_of_teams")),
            Column("AWP",       "Adjusted Win Percentage",   awp_getter, divider=True),
            Column("TD+", "Average Touchdowns",              attrgetter("tds_for")),
            Column("P+",  "Average Pass completions",        attrgetter("passes_for")),
            Column("YP+", "Average Yards passing",           attrgetter("pyards_for")),
            Column("R+",  "Average Pass receptions",         attrgetter("rec_for")),
            Column("YR+", "Average Yards rushing",           attrgetter("ryards_for")),
            Column("K+",  "Average Kills",                   attrgetter("kills_for")),
            Column("C+",  "Average Casualties",              attrgetter("cas_for")),
            Column("KO+", "Average Knock outs",              attrgetter("ko_for")),
            Column("S+",  "Average Stuns",                   attrgetter("stun_for")),
            Column("T+",  "Average Tackles",                 attrgetter("tckl_for")),
            Column("I+",  "Average Interceptions",           attrgetter("int_for"), divider=True),
            Column("TD-", "Average Touchdowns",              attrgetter("tds_against")),
            Column("P-",  "Average Pass completions",        attrgetter("passes_against")),
            Column("YP-", "Average Yards passing",           attrgetter("pyards_against")),
            Column("R-",  "Average Pass receptions",         attrgetter("rec_against")),
            Column("YR-", "Average Yards rushing",           attrgetter("ryards_against")),
            Column("K-",  "Average Kills",                   attrgetter("kills_against")),
            Column("C-",  "Average Casualties",              attrgetter("cas_against")),
            Column("KO-", "Average Knock outs",              attrgetter("ko_against")),
            Column("S-",  "Average Stuns",                   attrgetter("stun_against")),
            Column("T-",  "Average Tackles",                 attrgetter("tckl_against")),
            Column("I-",  "Average Interceptions",           attrgetter("int_against")),
            ],
          query = models.RaceStats.all().order("-awp"),
          id = "race-stats-table",
          cls = "tablesorter",
          )
    # render and update
    #--------------------------------------------------------------------#

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

    self.response.out.write(general_statistics)
Ejemplo n.º 11
0
    def get(self):

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

        match_key = db.Key(self.request.get("match_key"))
        if self.emit(self.response.out, match_key):
            return

        # not cached or evicted from cache; regenerate
        #--------------------------------------------------------------------#
        match = Match.get(match_key)

        if not match:
            return

        home_record, away_record = match.get_team_records_query().fetch(2)
        match_data = MatchData(match)

        # team_match_table
        #--------------------------------------------------------------------#

        def team_name_getter(record):
            return "<a rel='match_teams' 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 glicko_getter(record):
            return "%4.0f" % record.glicko_r

        team_match_table = Table(
            columns=[
                Column(" ", "Race", race_getter, center=True),
                Column("Team", "Team name", team_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")),
            ],
            query=match.get_team_records_query(),
            cls="tablesorter team_match_table",
        )

        # player_match_tables
        #--------------------------------------------------------------------#

        def number_getter(record):
            return record.player.number

        def player_name_getter(record):
            return record.player.get_box_anchor("match_players")

        def position_getter(record):
            position = record.player.position
            if position.starplayer:
                return "<b>Star Player</b>"
            else:
                return position.key().name()

        player_records = match.get_player_records_query().filter("played =", 1)
        team_player_records = {}
        for record in player_records:
            team_player_records.setdefault(
                record.team_record.team.key().name(), []).append(record)

        player_match_tables = []
        for team_name, record_set in team_player_records.items():
            table = Table(
                columns=[
                    Column("#", "Player number", number_getter, center=True),
                    Column("Player", "Player name", player_name_getter),
                    Column("Position", "Player position", position_getter),
                    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")),
                ],
                query=record_set,
                cls="tablesorter player_match_table",
            )

            player_match_tables.append((team_name, table))

        # injury_table
        #--------------------------------------------------------------------#

        def team_name_getter(record):
            return record.team_record.team.key().name()

        def injury_name_getter(record):
            for injury_key in record.match_injuries:
                injury = Injury.get(injury_key)
                if injury.permanent:
                    break
            return injury.key().name()

        def injury_effect_getter(record):
            for injury_key in record.match_injuries:
                injury = Injury.get(injury_key)
                if injury.permanent:
                    break
            return injury.effect

        injured_player_records = [
            r for r in player_records if r.match_injuries
        ]

        if injured_player_records:
            injury_table = Table(
                columns=[
                    Column("#", "Player number", number_getter, center=True),
                    Column("Team", "Team name", team_name_getter),
                    Column("Player", "Player name", player_name_getter),
                    Column("Position", "Player position", position_getter),
                    Column("SPP", "Star player points", attrgetter("spp")),
                    Column("Level", "Level", attrgetter("level")),
                    Column("Injury", "Injury name", injury_name_getter),
                    Column("Effect", "Injury effect", injury_effect_getter),
                ],
                query=injured_player_records,
                cls="tablesorter injury_table",
            )
        else:
            injury_table = None

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

        match_box = misc.render('match_box.html', locals())
        self.update(match_box, match_key)

        self.response.out.write(match_box)
Ejemplo n.º 12
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)
Ejemplo n.º 13
0
  def get(self):

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

    if self.emit(self.response.out):
      return

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

    def logo_getter(standing):
      team = standing.team
      img = "<img src='%s' />" % team.get_logo_url() # FIXME: thumb is broken
      return "<div style='background-color: %(color)s'>%(img)s</div>" % {
          'color': team.color, 'img': img}

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

    leader_info = []
    for leader in TeamLeader.all().order('display_order'):
      query = TeamLeaderStanding.all().ancestor(leader).order('-score').fetch(10)

      leader_table = Table(
          columns = [
            Column(" ",         "Logo",      logo_getter, center=True),
            Column("Team Name", "Team name", name_getter),
            Column("Score",     "Score",     attrgetter("score")),
            ],
          query = query,
          cls = "leader_table",
          )

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

      def getter(stat):
        def getter_closure(tuple):
          subquery, which = tuple
          html = []
          for i, standing in enumerate(subquery):
            attr = getattr(standing.team, "%s_%s" % (stat, which))
            html.append("<span class='leader_info leader_info_%s'>%s</span>" % (i+1, attr))
          return "\n".join(html)

        return getter_closure

      def played_getter(tuple):
        subquery, which = tuple
        html = []
        for i, standing in enumerate(subquery):
          attr = getattr(standing.team, "matches")
          html.append("<span class='leader_info leader_info_%s'>%s</span>" % (i+1, attr))
        return "\n".join(html)

      leader_stats_table = Table(
          columns = [
            Column("",   "",                 get_left_header),
            Column("Pl", "Matches played",   played_getter),
            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("T",  "Tackles",          getter("tckl")),
            Column("I",  "Interceptions",    getter("int")),
            ],
          query = ((query, "for"), (query, "against")),
          cls = "fancytable leader_stats_table",
          )

      teams = [s.team for s in query]
      team_names = ["%s<i style='font-weight: normal'>, %s</i>" % (
        s.team.key().name(), s.team.coach.key().name() if s.team.coach else "Unknown")
        for s in query]

      leader_info.append((
        leader, leader_table, leader_stats_table, teams, team_names))

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

    self.response.out.write(team_leaders)
Ejemplo n.º 14
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)
Ejemplo n.º 15
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)
Ejemplo n.º 16
0
    def get(self):

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

        if self.emit(self.response.out):
            return

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

        def logo_getter(standing):
            coach = standing.coach_stats.parent()
            img = "<img src='%s' />" % coach.get_logo_url(
            )  # FIXME: thumb is broken
            return "<div style='background-color: %(color)s'>%(img)s</div>" % {
                'color': coach.color,
                'img': img
            }

        def name_getter(standing):
            coach = standing.coach_stats.parent()
            return "<a class='leader_link' rel='leader_coach' href='%s'>%s</a>" % (
                coach.get_box_href(), coach.key().name())

        leader_info = []
        for leader in CoachLeader.all().order('display_order'):
            query = CoachLeaderStanding.all().ancestor(leader).order(
                '-score').fetch(10)

            leader_table = Table(
                columns=[
                    Column(" ", "Logo", logo_getter, center=True),
                    Column("Coach Name", "Coach name", name_getter),
                    Column("Score", "Score", attrgetter("score")),
                ],
                query=query,
                cls="leader_table",
            )

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

            def getter(stat):
                def getter_closure(tuple):
                    subquery, which = tuple
                    html = []
                    for i, standing in enumerate(subquery):
                        attr = getattr(standing.coach_stats,
                                       "%s_%s" % (stat, which))
                        html.append(
                            "<span class='leader_info leader_info_%s'>%s</span>"
                            % (i + 1, attr))
                    return "\n".join(html)

                return getter_closure

            def played_getter(tuple):
                subquery, which = tuple
                html = []
                for i, standing in enumerate(subquery):
                    attr = getattr(standing.coach_stats, "matches")
                    html.append(
                        "<span class='leader_info leader_info_%s'>%s</span>" %
                        (i + 1, attr))
                return "\n".join(html)

            leader_stats_table = Table(
                columns=[
                    Column("", "", get_left_header),
                    Column("Pl", "Matches played", played_getter),
                    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("T", "Tackles", getter("tckl")),
                    Column("I", "Interceptions", getter("int")),
                ],
                query=((query, "for"), (query, "against")),
                cls="fancytable leader_stats_table",
            )

            teams = [s.coach_stats for s in query]
            team_names = [
                "%s<i style='font-weight: normal'>, %s - %s - %s</i>" %
                (s.coach_stats.parent().key().name()
                 if s.coach_stats.parent() else "Unknown", s.coach_stats.wins,
                 s.coach_stats.draws, s.coach_stats.losses) for s in query
            ]

            leader_info.append(
                (leader, leader_table, leader_stats_table, teams, team_names))

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

        self.response.out.write(coach_leaders)
Ejemplo n.º 17
0
    def get(self):

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

        if self.emit(self.response.out):
            return

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

        def name_getter(racestats):
            return racestats.race.key().name()

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

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

        def percent_getter(attr):
            def ave_getter(racestats):
                if (racestats.matches > 0):
                    return "%.1f" % (float(getattr(racestats, attr)) * 100 /
                                     racestats.matches)
                return 0

            return ave_getter

        def get_ave_getter(attr):
            def ave_getter(racestats):
                if (racestats.matches > 0):
                    return "%.1f" % (float(getattr(racestats, attr)) /
                                     racestats.matches)
                return 0

            return ave_getter

        tables = {}
        label = "active"
        tables[label] = Table(
            columns=[
                # profile
                Column(" ", "Logo", race_getter, center=True),
                Column("Race", "Race", name_getter, divider=True),
                Column("#Teams", "Number of Teams",
                       attrgetter("num_of_teams")),
                Column("Matches", "Matches played", attrgetter("matches")),
                Column("Wins", "Wins", attrgetter("wins")),
                Column("Draws", "Draws", attrgetter("draws")),
                Column("Losses", "Losses", attrgetter("losses")),
                Column("AWP", "Adjusted Win Percentage", awp_getter),
                Column("Win%", "Win Percentage", percent_getter("wins")),
                Column("Draw%", "Draw Percentage", percent_getter("draws")),
                Column("Loss%", "Loss Percentage", percent_getter("losses")),
                Column("TPts",
                       "Tournament Points",
                       attrgetter("tpts"),
                       divider=True),
            ],
            query=models.RaceStats.all().order("-awp"),
            id="race-standings-table",
            cls="tablesorter",
        )

        label = "average"
        tables[label] = Table(
            columns=[
                # profile
                Column(" ", "Logo", race_getter, center=True),
                Column("Race", "Race", name_getter, divider=True),
                Column("#Tm", "Number of Teams", attrgetter("num_of_teams")),
                Column("AWP",
                       "Adjusted Win Percentage",
                       awp_getter,
                       divider=True),
                Column("TD+", "Average Touchdowns", get_ave_getter("tds_for")),
                Column("P+", "Average Pass completions",
                       get_ave_getter("passes_for")),
                Column("YP+", "Average Yards passing",
                       get_ave_getter("pyards_for")),
                Column("R+", "Average Pass receptions",
                       get_ave_getter("rec_for")),
                Column("YR+", "Average Yards rushing",
                       get_ave_getter("ryards_for")),
                Column("K+", "Average Kills", get_ave_getter("kills_for")),
                Column("C+", "Average Casualties", get_ave_getter("cas_for")),
                Column("KO+", "Average Knock outs", get_ave_getter("ko_for")),
                Column("S+", "Average Stuns", get_ave_getter("stun_for")),
                Column("T+", "Average Tackles", get_ave_getter("tckl_for")),
                Column("I+",
                       "Average Interceptions",
                       get_ave_getter("int_for"),
                       divider=True),
                Column("TD-", "Average Touchdowns",
                       get_ave_getter("tds_against")),
                Column("P-", "Average Pass completions",
                       get_ave_getter("passes_against")),
                Column("YP-", "Average Yards passing",
                       get_ave_getter("pyards_against")),
                Column("R-", "Average Pass receptions",
                       get_ave_getter("rec_against")),
                Column("YR-", "Average Yards rushing",
                       get_ave_getter("ryards_against")),
                Column("K-", "Average Kills", get_ave_getter("kills_against")),
                Column("C-", "Average Casualties",
                       get_ave_getter("cas_against")),
                Column("KO-", "Average Knock outs",
                       get_ave_getter("ko_against")),
                Column("S-", "Average Stuns", get_ave_getter("stun_against")),
                Column("T-", "Average Tackles",
                       get_ave_getter("tckl_against")),
                Column("I-", "Average Interceptions",
                       get_ave_getter("int_against")),
            ],
            query=models.RaceStats.all().order("-awp"),
            id="race-average-table",
            cls="tablesorter",
        )

        label = "stats"
        tables[label] = Table(
            columns=[
                # profile
                Column(" ", "Logo", race_getter, center=True),
                Column("Race", "Race", name_getter, divider=True),
                Column("#Tm", "Number of Teams", attrgetter("num_of_teams")),
                Column("AWP",
                       "Adjusted Win Percentage",
                       awp_getter,
                       divider=True),
                Column("TD+", "Average Touchdowns", attrgetter("tds_for")),
                Column("P+", "Average Pass completions",
                       attrgetter("passes_for")),
                Column("YP+", "Average Yards passing",
                       attrgetter("pyards_for")),
                Column("R+", "Average Pass receptions", attrgetter("rec_for")),
                Column("YR+", "Average Yards rushing",
                       attrgetter("ryards_for")),
                Column("K+", "Average Kills", attrgetter("kills_for")),
                Column("C+", "Average Casualties", attrgetter("cas_for")),
                Column("KO+", "Average Knock outs", attrgetter("ko_for")),
                Column("S+", "Average Stuns", attrgetter("stun_for")),
                Column("T+", "Average Tackles", attrgetter("tckl_for")),
                Column("I+",
                       "Average Interceptions",
                       attrgetter("int_for"),
                       divider=True),
                Column("TD-", "Average Touchdowns", attrgetter("tds_against")),
                Column("P-", "Average Pass completions",
                       attrgetter("passes_against")),
                Column("YP-", "Average Yards passing",
                       attrgetter("pyards_against")),
                Column("R-", "Average Pass receptions",
                       attrgetter("rec_against")),
                Column("YR-", "Average Yards rushing",
                       attrgetter("ryards_against")),
                Column("K-", "Average Kills", attrgetter("kills_against")),
                Column("C-", "Average Casualties", attrgetter("cas_against")),
                Column("KO-", "Average Knock outs", attrgetter("ko_against")),
                Column("S-", "Average Stuns", attrgetter("stun_against")),
                Column("T-", "Average Tackles", attrgetter("tckl_against")),
                Column("I-", "Average Interceptions",
                       attrgetter("int_against")),
            ],
            query=models.RaceStats.all().order("-awp"),
            id="race-stats-table",
            cls="tablesorter",
        )
        # render and update
        #--------------------------------------------------------------------#

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

        self.response.out.write(general_statistics)
Ejemplo n.º 18
0
    def get(self):

        user = users.get_current_user()
        if user:
            log_out_url = users.create_logout_url("/")
            coach = Coach.all().filter("user ="******"<img src='http://www.oldworldfootball.com/%s'/>" % (
                        match.teamAlogo)
                    return html

                def logoB_getter(match):
                    html = "<img src='http://www.oldworldfootball.com/%s'/>" % (
                        match.teamBlogo)
                    return html

                def nameA_getter(prediction):
                    match = OFL_Match.get_by_key_name(prediction.key().name())
                    html = "%s (%s - %s)" % (match.teamA, match.teamAcoach,
                                             match.teamArace)
                    return html

                def nameB_getter(prediction):
                    match = OFL_Match.get_by_key_name(prediction.key().name())
                    html = "%s (%s - %s)" % (match.teamB, match.teamBcoach,
                                             match.teamBrace)
                    return html

                def key_name_getter(prediction):
                    return prediction.key().name()

                def choice_getter(prediction):
                    match = OFL_Match.get_by_key_name(prediction.key().name())
                    #html = "<img src='./get_wager_pic?keyname=%s&team=A'/>" % (prediction.key().name())
                    html = "<img src='http://www.oldworldfootball.com/%s'/>" % (
                        match.teamAlogo)
                    if not match.gamePlayed:
                        html += "<input type='radio' name='%schoice' value='-1' %s>" % (
                            match.key().name(), prediction.isChecked(-1))
                        html += "<input type='radio' name='%schoice' value='0' %s>" % (
                            match.key().name(), prediction.isChecked(0))
                        html += "<input type='radio' name='%schoice' value='1' %s>" % (
                            match.key().name(), prediction.isChecked(1))
                    else:
                        html += "<input type='radio' name='%schoice' value='-1' disabled %s>" % (
                            match.key().name(), prediction.isChecked(-1))
                        html += "<input type='radio' name='%schoice' value='0' disabled %s>" % (
                            match.key().name(), prediction.isChecked(0))
                        html += "<input type='radio' name='%schoice' value='1' disabled %s>" % (
                            match.key().name(), prediction.isChecked(1))
                    html += "<img src='http://www.oldworldfootball.com/%s'/>" % (
                        match.teamBlogo)
                    #html += "<img src='./get_wager_pic?keyname=%s&team=B'/>" % (prediction.key().name())
                    return html

                # Bypassing table.html Django template to create this table
                # Table requires Jquery code for sortable entires and wagers
                # Hidden input tags are also used with form.
                prediction_list = OFL_Prediction.all().filter(
                    "season =",
                    season).filter("week =", week).ancestor(coach).filter(
                        "gameScored =", False).order("-wager")
                columns = ["Wager", "Away Team", "Prediction", "Home Team"]
                table_html = []
                table_html.append('''
        <table class="ofl_pickem schedule_table">
        <thead>
            <tr>''')
                for column in columns:
                    table_html.append(
                        '<th style="text-align: center;"> %s </th>' % column)
                table_html.append('''
            </tr>
        </thead>
        <tbody id="sortable">''')
                k = 0
                for prediction in prediction_list:
                    table_html.append('<tr class="row_%s">' % k)
                    table_html.append(
                        '<input type="hidden" name="row_%s" value="%s">' %
                        (k, prediction.key().name()))
                    table_html.append(
                        "<input type='hidden' class='row_%s' name='%svalue' value='%s'>"
                        % (k, prediction.key().name(), prediction.wager))
                    table_html.append(
                        '<td class="row_%s" style="text -align: center;">%s</td>'
                        % (k, prediction.wager))
                    table_html.append(
                        '<td style="text-align: center;">%s</td>' %
                        nameA_getter(prediction))
                    table_html.append(
                        '<td style="text-align: center;">%s</td>' %
                        choice_getter(prediction))
                    table_html.append(
                        '<td style="text-align: center;">%s</td>' %
                        nameB_getter(prediction))
                    k += 1
                table_html.append('</tbody>\n</table>')
                table_html = "\n".join(table_html)

                played_table = Table(
                    columns=[
                        # profile
                        Column("Points", "Points Earned",
                               attrgetter("points")),
                        Column("Wager", "Wager Placed", attrgetter("wager")),
                        Column("Away Team",
                               "Away Team",
                               nameA_getter,
                               center=True),
                        Column("Prediction",
                               "Your Prediction",
                               choice_getter,
                               center=True),
                        Column("Home Team",
                               "Home Team",
                               nameB_getter,
                               center=True),
                    ],
                    query=OFL_Prediction.all().filter(
                        "season =",
                        season).filter("week =", week).ancestor(coach).filter(
                            "gameScored =", True).order("-points"),
                    id="played_table",
                    cls="tablesorter",
                )

            def logo_getter(standing):
                coach = Coach.get_by_key_name(standing.get_coach_name())
                img = "<img src='%s' />" % coach.get_logo_url(
                )  # FIXME: thumb is broken
                return "<div style='background-color: %(color)s'>%(img)s</div>" % {
                    'color': coach.color,
                    'img': img
                }

            def name_getter(standing):
                coach = Coach.get_by_key_name(standing.get_coach_name())
                return "<a class='leader_link' rel='leader_coach' href='%s'>%s</a>" % (
                    coach.get_box_href(), coach.key().name())

            leader_table = {}
            query = OFLPickemStats.all().order('-all_time').fetch(10)
            label = "alltime"
            leader_table[label] = Table(
                columns=[
                    Column(" ", "Logo", logo_getter, center=True),
                    Column("Coach Name", "Coach name", name_getter),
                    Column("Score", "Score", attrgetter("all_time")),
                ],
                query=query,
                cls="leader_table",
            )

            query = OFLPickemSeasonRecord.all().filter(
                "season =", season).order("-points").fetch(10)
            label = "season"
            leader_table[label] = Table(
                columns=[
                    Column(" ", "Logo", logo_getter, center=True),
                    Column("Coach Name", "Coach name", name_getter),
                    Column("Score", "Score", attrgetter("points")),
                ],
                query=query,
                cls="leader_table",
            )

            query = OFLPickemWeekRecord.all().filter("week =", week).filter(
                "season =", season).order("-points").fetch(10)
            label = "week"
            leader_table[label] = Table(
                columns=[
                    Column(" ", "Logo", logo_getter, center=True),
                    Column("Coach Name", "Coach name", name_getter),
                    Column("Score", "Score", attrgetter("points")),
                ],
                query=query,
                cls="leader_table",
            )

            query = OFLPickemStats.all().order('-matches').fetch(10)
            label = "alltime_matches"
            leader_table[label] = Table(
                columns=[
                    Column(" ", "Logo", logo_getter, center=True),
                    Column("Coach Name", "Coach name", name_getter),
                    Column("Matches", "Matches Predicted",
                           attrgetter("matches")),
                ],
                query=query,
                cls="leader_table",
            )

            query = OFLPickemSeasonRecord.all().filter(
                "season =", season).order("-matches").fetch(10)
            label = "season_matches"
            leader_table[label] = Table(
                columns=[
                    Column(" ", "Logo", logo_getter, center=True),
                    Column("Coach Name", "Coach name", name_getter),
                    Column("Matches", "Matches Predicted",
                           attrgetter("matches")),
                ],
                query=query,
                cls="leader_table",
            )

            query = OFLPickemWeekRecord.all().filter("week =", week).filter(
                "season =", season).order("-matches").fetch(10)
            label = "week_matches"
            leader_table[label] = Table(
                columns=[
                    Column(" ", "Logo", logo_getter, center=True),
                    Column("Coach Name", "Coach name", name_getter),
                    Column("Matches", "Matches Predicted",
                           attrgetter("matches")),
                ],
                query=query,
                cls="leader_table",
            )

        else:
            log_in_url = users.create_login_url("/")

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

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

        self.response.out.write(ofl_pickem_page)
Ejemplo n.º 19
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)
Ejemplo n.º 20
0
    def get(self):

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

        tournament = Tournament.get_by_key_name(
            self.request.get("tournament_key_name"))

        if tournament.started:
            if self.emit(self.response.out, tournament.key()):
                return

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

        teams = [
            m.team for m in TournamentMembership.all().ancestor(tournament)
        ]

        races_allowed = []
        for race_key in tournament.races_allowed:
            races_allowed.append(Race.get(race_key))

        if not tournament.started:
            user = users.get_current_user()
            coach = None
            if user:
                coach = Coach.all().filter("user ="******":")]

            # pixel settings
            width_unit = 530 / round
            match_width = 200

            # compute data for each match_up
            match_up_data = []
            for match_up, child in match_ups:
                round, seed = [
                    int(x) for x in match_up.key().name().split(":")
                ]
                position_left = round * width_unit

                team_data = []
                for i, mm in enumerate(
                        match_up.tournamentmatchupmembership_set.order(
                            "__key__")):

                    data = {}
                    data["name"] = "_" * 25
                    data["seed"] = ""
                    data["score"] = ""

                    if mm.membership:
                        team = mm.membership.team
                        if team.matches:
                            data[
                                "name"] = "<a rel='tournament_teams' href='%s'>%s</a>" % (
                                    team.get_box_href(), team.key().name())
                        else:
                            data["name"] = "<b title='%s'>%s</b>" % (
                                team.coach.key().name(), team.key().name())
                        data["seed"] = mm.membership.seed + 1

                        if match_up.match:
                            team_record = match_up.match.get_team_records_query(
                            ).filter("team =", mm.membership.team.key()).get()
                            score = str(team_record.tds_for)
                            if (match_up.winner.key() == mm.membership.key()
                                    and
                                (team_record.tds_for == team_record.tds_against
                                 or match_up.match.disconnect)):
                                score += "*"

                            data["score"] = "<b>%s</b>" % score

                        elif match_up.winner:
                            # if there was a winner but no match then it was a forfeit
                            if match_up.winner.key() == mm.membership.key():
                                data["score"] = "&nbsp;"
                            else:
                                data["score"] = "<b><i>F</i></b>"

                    team_data.append(data)

                if child == 0:
                    arrow_class = "down_arrow"
                elif child == 1:
                    arrow_class = "up_arrow"
                else:
                    arrow_class = None

                match_data = match_up.match

                end_this_match = width_unit * round + match_width
                mid_next_match = width_unit * (round + 1) + match_width / 2
                arrow_width = mid_next_match - end_this_match

                match_up_data.append((round, team_data, position_left,
                                      arrow_width, arrow_class, match_data))

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

        tournament_box = misc.render('tournament_box.html', locals())
        if tournament.started:
            self.update(tournament_box, tournament.key())

        self.response.out.write(tournament_box)
Ejemplo n.º 21
0
    def get(self):

        user = users.get_current_user()
        if user:
            log_out_url = users.create_logout_url("/")
            coach = Coach.all().filter("user ="******"schedule").split("-")

                if not season or not week:
                    season, week = misc.get_ofl_season_and_week()
                    season += 3
                else:
                    season = int(season)
                    week = int(week)

                parser = OFLScheduleParser()
                ofl_info = urlfetch.fetch(
                    "http://www.shalkith.com/bloodbowl/processSchedule.php?s=%s&w=%s"
                    % (season, week))
                parser.feed(ofl_info.content)
                update_schedule_entries(coach, season, week, parser.data)
                sort_wagers(coach, season, week)

                def logoA_getter(match):
                    html = "<img src='http://www.shalkith.com/bloodbowl/%s'/>" % (
                        match.teamAlogo)
                    return html

                def logoB_getter(match):
                    html = "<img src='http://www.shalkith.com/bloodbowl/%s'/>" % (
                        match.teamBlogo)
                    return html

                def nameA_getter(prediction):
                    match = OFL_Match.get_by_key_name(prediction.key().name())
                    html = "%s (%s)" % (match.teamA, match.teamAcoach)
                    return html

                def nameB_getter(prediction):
                    match = OFL_Match.get_by_key_name(prediction.key().name())
                    html = "%s (%s)" % (match.teamB, match.teamBcoach)
                    return html

                def key_name_getter(prediction):
                    return prediction.key().name()

                def choice_getter(prediction):
                    match = OFL_Match.get_by_key_name(prediction.key().name())
                    html = "<img src='http://www.shalkith.com/bloodbowl/%s'/>" % (
                        match.teamAlogo)
                    if not match.gamePlayed:
                        html += "<input type='radio' name='%schoice' value='-1' %s>" % (
                            match.key().name(), prediction.isChecked(-1))
                        html += "<input type='radio' name='%schoice' value='0' %s>" % (
                            match.key().name(), prediction.isChecked(0))
                        html += "<input type='radio' name='%schoice' value='1' %s>" % (
                            match.key().name(), prediction.isChecked(1))
                    else:
                        html += "<input type='radio' name='%schoice' value='-1' disabled %s>" % (
                            match.key().name(), prediction.isChecked(-1))
                        html += "<input type='radio' name='%schoice' value='0' disabled %s>" % (
                            match.key().name(), prediction.isChecked(0))
                        html += "<input type='radio' name='%schoice' value='1' disabled %s>" % (
                            match.key().name(), prediction.isChecked(1))
                    html += "<img src='http://www.shalkith.com/bloodbowl/%s'/>" % (
                        match.teamBlogo)
                    return html

                # Bypassing table.html Django template to create this table
                # Table requires Jquery code for sortable entires and wagers
                # Hidden input tags are also used with form.
                prediction_list = OFL_Prediction.all().filter(
                    "season =",
                    season).filter("week =", week).ancestor(coach).filter(
                        "gameScored =", False).order("-wager")
                columns = ["Wager", "Away Team", "Prediction", "Home Team"]
                table_html = []
                table_html.append('''
        <table class="ofl_pickem schedule_table">
        <thead>
            <tr>''')
                for column in columns:
                    table_html.append(
                        '<th style="text-align: center;"> %s </th>' % column)
                table_html.append('''
            </tr>
        </thead>
        <tbody id="sortable">''')
                k = 0
                for prediction in prediction_list:
                    table_html.append('<tr class="row_%s">' % k)
                    table_html.append(
                        '<input type="hidden" name="row_%s" value="%s">' %
                        (k, prediction.key().name()))
                    table_html.append(
                        "<input type='hidden' class='row_%s' name='%svalue' value='%s'>"
                        % (k, prediction.key().name(), prediction.wager))
                    table_html.append(
                        '<td class="row_%s" style="text -align: center;">%s</td>'
                        % (k, prediction.wager))
                    table_html.append(
                        '<td style="text-align: center;">%s</td>' %
                        nameA_getter(prediction))
                    table_html.append(
                        '<td style="text-align: center;">%s</td>' %
                        choice_getter(prediction))
                    table_html.append(
                        '<td style="text-align: center;">%s</td>' %
                        nameB_getter(prediction))
                    k += 1
                table_html.append('</tbody>\n</table>')
                table_html = "\n".join(table_html)

                played_table = Table(
                    columns=[
                        # profile
                        Column("Points", "Points Earned",
                               attrgetter("points")),
                        Column("Wager", "Wager Placed", attrgetter("wager")),
                        Column("Away Team",
                               "Away Team",
                               nameA_getter,
                               center=True),
                        Column("Prediction",
                               "Your Prediction",
                               choice_getter,
                               center=True),
                        Column("Home Team",
                               "Home Team",
                               nameB_getter,
                               center=True),
                    ],
                    query=OFL_Prediction.all().filter(
                        "season =",
                        season).filter("week =", week).ancestor(coach).filter(
                            "gameScored =", True).order("-points"),
                    id="played_table",
                    cls="tablesorter",
                )

        else:
            log_in_url = users.create_login_url("/")

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

        ofl_pickem_page = misc.render('ofl_pickem_box.html', locals())
        self.update(ofl_pickem_page)

        self.response.out.write(ofl_pickem_page)
Ejemplo n.º 22
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)
Ejemplo n.º 23
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)
Ejemplo n.º 24
0
  def get(self):

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

    if self.emit(self.response.out):
      return

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

    user = users.get_current_user()
    coach = None
    if user:
      coach = Coach.all().filter("user ="******"<img src='get_trophy?size=thumb&tournament_key=%s' />" % tournament.key()
      return ""

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

    def date_getter(tournament):
      return tournament.created.date()

    def organizer_getter(tournament):
      return tournament.owner.key().name()

    def enrollment_getter(tournament):
      return "%s/%s" % (
        TournamentMembership.all().ancestor(tournament).count(),
        tournament.max_enrollment)

    def final_enrollment_getter(tournament):
      return TournamentMembership.all().ancestor(tournament).count()

    def winner_getter(tournament):
      return "<a rel='winners' href='%s'>%s</a> (%s)" % (
          tournament.winning_team.get_box_href(),
          tournament.winning_team.key().name(),
          tournament.winning_team.coach.key().name())

    def tv_getter(tournament):
      if tournament.min_tv and tournament.max_tv:
        return "%s - %s" % (tournament.min_tv, tournament.max_tv)
      elif tournament.min_tv:
        return "&ge; %s" % tournament.min_tv
      elif tournament.max_tv:
        return "&le; %s" % tournament.max_tv
      else:
        return "Any"

    def ma_getter(tournament):
      if tournament.min_ma != None and tournament.max_ma != None:
        return "%s - %s" % (tournament.min_ma, tournament.max_ma)
      elif tournament.min_ma != None:
        return "&ge; %s" % tournament.min_ma
      elif tournament.max_ma != None:
        return "&le; %s" % tournament.max_ma
      else:
        return "Any"
      
    def races_getter(tournament):
      if tournament.races_allowed:
        return "Restricted"
      else:
        return "Any"

    tournaments = {}
    for tournament in Tournament.all():
      if tournament.winning_team:
        tournaments.setdefault("Completed", []).append(tournament)
      elif tournament.started:
        tournaments.setdefault("In Progress", []).append(tournament)
      else:
        tournaments.setdefault("Open", []).append(tournament)

    tables = [
        ("Open", Table(
          columns = [
            Column("",           "Trophy Image",    trophy_getter,
              center=True),
            Column("Name",       "Tournament name",      name_getter),
            Column("Created",    "Creation date",        date_getter),
            Column("Organizer",  "Tournament organizer", organizer_getter),
            Column("Enrolled",   "Enrollment count",     enrollment_getter),
            Column("TV",         "TV range",             tv_getter),
            Column("Matches Played", "Matches played range", ma_getter),
            Column("Races",      "Races allowed",        races_getter),
            Column("Seed By",    "Teams are seeded by",  attrgetter("seed_by")),
            ],
          query = tournaments.get("Open", []),
          cls = "tablesorter tournaments_table",
          )),

        ("In Progress", Table(
          columns = [
            Column("",           "Trophy Image",    trophy_getter,
              center=True),
            Column("Name",       "Tournament name",      name_getter),
            Column("Created",    "Creation date",        date_getter),
            Column("Organizer",  "Tournament organizer", organizer_getter),
            Column("Enrolled",   "Final enrollment count",     final_enrollment_getter),
            Column("TV",         "TV range",             tv_getter),
            Column("Races",      "Races allowed",        races_getter),
            ],
          query = tournaments.get("In Progress", []),
          cls = "tablesorter tournaments_table",
          )),

        ("Completed", Table(
          columns = [
            Column("",           "Trophy Image",    trophy_getter,
              center=True),
            Column("Name",       "Tournament name",      name_getter),
            Column("Created",    "Creation date",        date_getter),
            Column("Organizer",  "Tournament organizer", organizer_getter),
            Column("Winner",     "Tournament winner",    winner_getter),
            Column("Enrolled",   "Final enrollment count",     final_enrollment_getter),
            Column("TV",         "TV range",             tv_getter),
            Column("Races",      "Races allowed",        races_getter),
            ],
          query = tournaments.get("Completed", []),
          cls = "tablesorter tournaments_table",
          ))]

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

    tournaments = misc.render('tournaments.html', locals())
    self.update(tournaments)
    self.response.out.write(tournaments)
Ejemplo n.º 25
0
  def get(self):

    user = users.get_current_user()
    if user:
      log_out_url = users.create_logout_url("/")
      coach = Coach.all().filter("user ="******"schedule").split("-")

        if not season or not week:
          season, week = misc.get_ofl_season_and_week()
          season += 3
        else:
          season = int(season)
          week = int(week)

        parser = OFLScheduleParser()
        ofl_info = urlfetch.fetch("http://www.shalkith.com/bloodbowl/processSchedule.php?s=%s&w=%s" % (season, week))
        parser.feed(ofl_info.content)
        update_schedule_entries(coach, season, week, parser.data)
        sort_wagers(coach, season, week)

        def logoA_getter(match):
          html = "<img src='http://www.shalkith.com/bloodbowl/%s'/>" % (match.teamAlogo)
          return html

        def logoB_getter(match):
          html = "<img src='http://www.shalkith.com/bloodbowl/%s'/>" % (match.teamBlogo)
          return html

        def nameA_getter(prediction):
          match = OFL_Match.get_by_key_name(prediction.key().name())
          html = "%s (%s)" % (match.teamA, match.teamAcoach)
          return html

        def nameB_getter(prediction):
          match = OFL_Match.get_by_key_name(prediction.key().name())
          html = "%s (%s)" % (match.teamB, match.teamBcoach)
          return html

        def key_name_getter(prediction):
          return prediction.key().name()

        def choice_getter(prediction):
          match = OFL_Match.get_by_key_name(prediction.key().name())
          html = "<img src='http://www.shalkith.com/bloodbowl/%s'/>" % (match.teamAlogo)
          if not match.gamePlayed:
            html += "<input type='radio' name='%schoice' value='-1' %s>" % (match.key().name(), prediction.isChecked(-1))
            html += "<input type='radio' name='%schoice' value='0' %s>" % (match.key().name(), prediction.isChecked(0))
            html += "<input type='radio' name='%schoice' value='1' %s>" % (match.key().name(), prediction.isChecked(1))
          else:
            html += "<input type='radio' name='%schoice' value='-1' disabled %s>" % (match.key().name(), prediction.isChecked(-1))
            html += "<input type='radio' name='%schoice' value='0' disabled %s>" % (match.key().name(), prediction.isChecked(0))
            html += "<input type='radio' name='%schoice' value='1' disabled %s>" % (match.key().name(), prediction.isChecked(1))
          html += "<img src='http://www.shalkith.com/bloodbowl/%s'/>" % (match.teamBlogo)
          return html
  

        # Bypassing table.html Django template to create this table
        # Table requires Jquery code for sortable entires and wagers
        # Hidden input tags are also used with form.
        prediction_list = OFL_Prediction.all().filter("season =", season).filter("week =", week).ancestor(coach).filter("gameScored =", False).order("-wager")
        columns = ["Wager", "Away Team", "Prediction", "Home Team"]
        table_html = []
        table_html.append('''
        <table class="ofl_pickem schedule_table">
        <thead>
            <tr>''')
        for column in columns:
          table_html.append('<th style="text-align: center;"> %s </th>' % column)
        table_html.append('''
            </tr>
        </thead>
        <tbody id="sortable">''')
        k = 0        
        for prediction in prediction_list:
          table_html.append('<tr class="row_%s">' % k)
          table_html.append('<input type="hidden" name="row_%s" value="%s">' % (k, prediction.key().name()))
          table_html.append("<input type='hidden' class='row_%s' name='%svalue' value='%s'>" % (k, prediction.key().name(), prediction.wager))
          table_html.append('<td class="row_%s" style="text -align: center;">%s</td>' % (k, prediction.wager))
          table_html.append('<td style="text-align: center;">%s</td>' % nameA_getter(prediction))
          table_html.append('<td style="text-align: center;">%s</td>' % choice_getter(prediction))
          table_html.append('<td style="text-align: center;">%s</td>' % nameB_getter(prediction))
          k += 1
        table_html.append('</tbody>\n</table>')
        table_html = "\n".join(table_html)
        
        played_table = Table(
          columns = [
            # profile
            Column("Points",     "Points Earned",      attrgetter("points")),
            Column("Wager",      "Wager Placed",       attrgetter("wager")),
            Column("Away Team",  "Away Team",          nameA_getter, center=True),
            Column("Prediction", "Your Prediction",    choice_getter, center=True),
            Column("Home Team",  "Home Team",          nameB_getter, center=True),
            ],
          query = OFL_Prediction.all().filter("season =", season).filter("week =", week).ancestor(coach).filter("gameScored =", True).order("-points"),
          id = "played_table",
          cls = "tablesorter",
          )
        
        
        
    else:
      log_in_url = users.create_login_url("/") 

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

    ofl_pickem_page = misc.render('ofl_pickem_box.html', locals())
    self.update(ofl_pickem_page)

    self.response.out.write(ofl_pickem_page)