<commit_before><?php

  require_once("config.php");

  $ALLIANCE = 469;
  $HORDE = 67;

  // query conditions

  $today_condition = "DAY(date) = DAY(NOW())";
  $last7_condition = "DATEDIFF(NOW(), date) < 7";
  $month_condition = "MONTH(date) = MONTH(NOW())";

  if (isset($_GET['level']) && $_GET['level'] < 9 && $_GET['level'] > 0)
  {
    $level_condition = "level = " . $_GET['level'];
    $level = $_GET['level'];
  }
  else
  {
    $level_condition = "";
    $level = "all";
  }

  function getPlayerName($guid)
  {
    global $db;

    $query = sprintf("SELECT name FROM characters WHERE guid = %d;", $guid);
    $row = $db->query($query)->fetch_array();

    return $row['name'];
  }

  function getFactionScores($time_cond, $level_cond)
  {
    global $db, $ALLIANCE, $HORDE;

    $score[2];

    if ($time_cond != "")
      $time_cond = "AND " . $time_cond;

    if ($level_cond != "")
      $level_cond = "AND " . $level_cond;

    $query = sprintf("SELECT COUNT(*) FROM pvpstats_faction WHERE faction = %d %s %s UNION SELECT COUNT(*) FROM pvpstats_faction WHERE faction = %d %s %s;",
                     $ALLIANCE, $time_cond, $level_cond, $HORDE, $time_cond, $level_cond);

    $result = $db->query($query);

    $row = $result->fetch_row();
    $score[0] = $row[0];

    $row = $result->fetch_row();

    if ($row != null)
      $score[1] = $row[0];
    else
      $score[1] = 0;

    return $score;
  }

  // just for testing

  $alliance_today = 2;
  $horde_today = 1;

  $alliance_last7 = 8;
  $horde_last7 = 9;

  $alliance_month = 32;
  $horde_month = 26;

  $alliance_overall = 64;
  $horde_overall = 64;
<commit_msg>function getPlayersScores and order<commit_after><?php

  require_once("config.php");


  // query variables

  $ALLIANCE = 469;
  $HORDE = 67;
  $limit = "LIMIT 0,20";
  $players_group_and_order = "GROUP BY character_guid ORDER BY count(character_guid) DESC";


  // query conditions

  $today_condition = "DAY(date) = DAY(NOW())";
  $last7_condition = "DATEDIFF(NOW(), date) < 7";
  $month_condition = "MONTH(date) = MONTH(NOW())";

  if (isset($_GET['level']) && $_GET['level'] < 9 && $_GET['level'] > 0)
  {
    $level_condition = "level = " . $_GET['level'];
    $level = $_GET['level'];
  }
  else
  {
    $level_condition = "";
    $level = "all";
  }


  // query functions

  function getPlayerName($guid)
  {
    global $db;

    $query = sprintf("SELECT name FROM characters WHERE guid = %d;", $guid);
    $row = $db->query($query)->fetch_array();

    return $row['name'];
  }

  function getFactionScores($time_cond, $level_cond)
  {
    global $db, $ALLIANCE, $HORDE;

    $score[2];

    if ($time_cond != "")
      $time_cond = "AND " . $time_cond;

    if ($level_cond != "")
      $level_cond = "AND " . $level_cond;

    $query = sprintf("SELECT COUNT(*) FROM pvpstats_faction WHERE faction = %d %s %s UNION SELECT COUNT(*) FROM pvpstats_faction WHERE faction = %d %s %s;",
                     $ALLIANCE, $time_cond, $level_cond, $HORDE, $time_cond, $level_cond);

    $result = $db->query($query);

    $row = $result->fetch_row();
    $score[0] = $row[0];

    $row = $result->fetch_row();

    if ($row != null)
      $score[1] = $row[0];
    else
      $score[1] = 0;

    return $score;
  }

  function getPlayersScores($time_cond, $level_cond)
  {
    global $db, $limit, $players_group_and_order;


    if ($time_cond == "" && $level_cond == "")
      $where = "";
    else
      $where = "WHERE";

    if ($time_cond != "" && $level_cond != "")
      $level_cond = "AND " . $level_cond;

    $query = sprintf("SELECT character_guid, count(character_guid) FROM pvpstats_players %s %s %s %s %s",
                     $where,
                     $time_cond,
                     $level_cond,
                     $players_group_and_order,
                     $limit);

    return $query;
  }


  // just for testing

  $alliance_today = 2;
  $horde_today = 1;

  $alliance_last7 = 8;
  $horde_last7 = 9;

  $alliance_month = 32;
  $horde_month = 26;

  $alliance_overall = 64;
  $horde_overall = 64;

{'fraction_non_alphanumeric': 0.17716535433070865, 'fraction_numerical': 0.015501968503937008, 'mean_word_length': 2.7778810408921935, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '438433', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1471, 'n_words': 318}