def index(server_slug):
  try:
    server = app.config['config'].get_server(server_slug)
  except InvalidServer:
    return redirect(url_for('landing'))
  stats = Results(app.config['config'], server)

  colors = [
      'red',
      'blue',
      'green',
      'orange',
      'pink',
      'brown',
      'purple',
  ]
  data = dict(
      page_title='Stats overview',
      killsperdate=stats.get_kills_for_date_range(),
      topcountries=[
          dict(
              value=players,
              label=country,
              color=colors.pop(),
          )
          for country, players in stats.get_top_countries(len(colors) - 1)],
      show_server_status=server.admin_details is not None,
      server_slug=server_slug
  )
  data.update(more_params(stats, server))
  return render_template('index.html', **data)
def top_players(server_slug, startat):
  try:
    server = app.config['config'].get_server(server_slug)
  except InvalidServer:
    return redirect(url_for('landing'))
  stats = Results(app.config['config'], server)

  if (startat % 20):
    startat = 0

  data = {
      'page_title': 'Top Players',
      'next_url': url_for('top_players', startat=startat + 20, server_slug=server.url_slug),
      'players': stats.get_top_killers(startat),
  }

  data.update(more_params(stats, server))

  if startat >= 20:
    data['prev_url'] = url_for('top_players', startat=startat - 20, server_slug=server.url_slug)
  else:
    data['prev_url'] = False

  num_players = stats.get_num_players()

  if (startat + 20) > num_players:
    data['next_url'] = False

  return render_template('players.html', **data)
def player_search(server_slug):
  try:
    server = app.config['config'].get_server(server_slug)
  except InvalidServer:
    return redirect(url_for('landing'))

  stats = Results(app.config['config'], server)

  try:
    player_name = request.args['player']
  except KeyError:
    return render_template('player_not_found.html', **more_params(stats, server))

  results = stats.player_search(player_name)

  players = []

  for player, kills in results:
    players.append(stats.get_player_fields(player, ['lastcountry', 'lastseen', 'kills']))

  if len(players) == 1:
    return redirect(url_for('player', server_slug=server_slug, name=players[0].name))

  data = {
      'page_title': 'Search results',
      'results': players,
  }

  data.update(more_params(stats, server))

  return render_template('player_search.html', **data)
def weapons(server_slug):
  try:
    server = app.config['config'].get_server(server_slug)
  except InvalidServer:
    return redirect(url_for('landing'))
  stats = Results(app.config['config'], server)

  data = {
      'page_title': 'Weapons',
      'weapons': stats.get_top_weapons(),
  }

  data.update(more_params(stats, server))

  return render_template('weapons.html', **data)
def weapon(server_slug, weapon):
  try:
    server = app.config['config'].get_server(server_slug)
  except InvalidServer:
    return redirect(url_for('landing'))
  stats = Results(app.config['config'], server)

  info = stats.get_weapon_stats(weapon)

  if not info:
    return 'Weapon not found', 404

  data = {
      'page_title': weapon,
      'weapon': info,
  }

  data.update(more_params(stats, server))

  return render_template('weapon.html', **data)
def player(server_slug, name):
  try:
    server = app.config['config'].get_server(server_slug)
  except InvalidServer:
    return redirect(url_for('landing'))
  stats = Results(app.config['config'], server)

  data = dict(
      player=stats.get_player(name),
      top_enemies=stats.get_player_top_enemies(name, 0, 10),
      top_victims=stats.get_player_top_victims(name, 0, 10)
  )

  data.update(more_params(stats, server))

  if not data['player']:
    return render_template('player_not_found.html')

  return render_template('player.html',
                         page_title=data['player'].name,
                         **data
                         )
def latestkills(server_slug, startat):
  try:
    server = app.config['config'].get_server(server_slug)
  except InvalidServer:
    return redirect(url_for('landing'))
  stats = Results(app.config['config'], server)

  if (startat % 20):
    startat = 0

  def kill_decorate(kill):
    info = kill._asdict()
    info['killer_obj'] = stats.get_player_fields(kill.killer, ['lastcountry'])
    info['victim_obj'] = stats.get_player_fields(kill.victim, ['lastcountry'])
    return info

  data = {
      'page_title': 'Latest Kills',
      'next_url': url_for('latestkills', startat=startat + 20, server_slug=server.url_slug),
      'kills': map(kill_decorate, stats.get_last_kills(startat)),
      'fixdate': lambda x: datetime.utcfromtimestamp(int(x))
  }

  data.update(more_params(stats, server))

  if startat >= 20:
    data['prev_url'] = url_for('latestkills', startat=startat - 20, server_slug=server.url_slug)
  else:
    data['prev_url'] = False

  num_kills = stats.get_num_kills()

  if (startat + 20) > num_kills:
    data['next_url'] = False

  return render_template('latestkills.html', **data)
Example #8
0
def index(server_slug):
  try:
    server = app.config['config'].get_server(server_slug)
  except InvalidServer:
    return redirect(url_for('landing'))
  stats = Results(app.config['config'], server)

  raw_kills_per_date = stats.get_kills_for_date_range()
  kills_per_date = OrderedDict(zip(
                               map(
                                   lambda d: str(format_datetime(d.date(), 'yyyy-MM-dd', tzinfo=app.config['config'].timezone)), raw_kills_per_date.keys()),
                               raw_kills_per_date.values()))
  colors = [
      'red',
      'blue',
      'green',
      'orange',
      'pink',
      'brown',
      'purple',
  ]
  data = dict(
      page_title='Stats overview',
      killsperdate=kills_per_date,
      topcountries=[
          dict(
              value=players,
              label=country,
              color=colors.pop(),
          )
          for country, players in stats.get_top_countries(len(colors) - 1)],
      show_server_status=server.admin_details is not None,
      server_slug=server_slug
  )
  data.update(more_params(stats, server))
  return render_template('index.html', **data)
Example #9
0
    def process_resource(self, req, resp, resource, params):
        req.context['do_json'] = req.get_param(
            'json') is not None or req.get_header(
                'Accept') == 'application/json'
        req.context['config'] = self.config

        if not isinstance(resource, ServerBase):
            return

        server_slug = params['server']

        try:
            req.context['server'] = self.config.get_server(server_slug)
        except InvalidServer:
            raise HTTPFound('/')

        req.context['stats'] = Results(self.config, req.context['server'])