<commit_before>#!/usr/bin/php -q
<?php
require_once('../../functions.php');
require_once('../../../global_functions.php');
require_once('../../../connections/parameters.php');

try {
    $db = new dbWrapper_v3($hostname_gds_cron, $username_gds_cron, $password_gds_cron, $database_gds_cron, true);

    $memcache = new Memcache;
    $memcache->connect("localhost", 11211); # You might need to set "localhost" to "127.0.0.1"

    if ($db) {
        $steamID = new SteamID();
        $steamWebAPI = new steam_webapi($api_key1);

        //Mini Game Leaderboard
        {
            try {
                $time_start1 = time();
                echo '<h2>Mini Game Leaderboard</h2>';

                $db->q("DROP TABLE IF EXISTS `cron_hs_temp`;");

                $leaderboards = $db->q(
                    'SELECT
                        DISTINCT sh.`minigameID`,
                        sh.`leaderboard`,
                        shm.`minigameName`,
                        shm.`minigameActive`,
                        shm.`minigameObjective`
                    FROM `stat_highscore` sh
                    JOIN `stat_highscore_minigames` shm ON sh.`minigameID` = shm.`minigameID`;'
                );

                if (!empty($leaderboards)) {
                    $sqlResult = $db->q(
                        "CREATE TABLE IF NOT EXISTS `cron_hs_temp` (
                          `minigameID` varchar(255) NOT NULL,
                          `leaderboard` varchar(255) NOT NULL,
                          `user_id32` bigint(255) NOT NULL,
                          `highscore_value` bigint(255) NOT NULL,
                          `date_recorded` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
                          INDEX `id_hs_lb` (`minigameID`, `leaderboard`, `date_recorded`),
                          INDEX `highscore_value` (`highscore_value`),
                          INDEX `date_recorded` (`date_recorded`)
                        ) ENGINE=InnoDB DEFAULT CHARSET=latin1;"
                    );

                    foreach ($leaderboards as $key => $value) {
                        $minigameID = $value['minigameID'];
                        $leaderboard = $value['leaderboard'];
                        $mgName = $value['minigameName'];

                        $mgObjective = !empty($value['minigameObjective']) && $value['minigameObjective'] == 'min'
                            ? 'ASC'
                            : 'DESC';

                        $sqlResult = $db->q(
                            "INSERT INTO `cron_hs_temp`
                            SELECT
                              `minigameID`,
                              `leaderboard`,
                              `user_id32`,
                              `highscore_value`,
                              `date_recorded`
                            FROM `stat_highscore`
                            WHERE `minigameID` = ? AND `leaderboard` = ?
                            GROUP BY `minigameID`, `leaderboard`, `user_id32`
                            ORDER BY `minigameID`, `leaderboard`, `highscore_value` $mgObjective
                            LIMIT 0,20;",
                            'ss',
                            array($minigameID, $leaderboard)
                        );

                        echo $sqlResult
                            ? "[SUCCESS] Gathered High Scores for: $mgName [$leaderboard]!<br />"
                            : "[FAILURE] Gathered High Scores for: $mgName [$leaderboard]!<br />";
                    }

                    $sqlResult = $db->q(
                        'SELECT * FROM `cron_hs_temp`;'
                    );

                    if (!empty($sqlResult)) {
                        $db->q(
                            "CREATE TABLE IF NOT EXISTS `cron_hs` (
                              `minigameID` varchar(255) NOT NULL,
                              `leaderboard` varchar(255) NOT NULL,
                              `user_id32` bigint(255) NOT NULL,
                              `highscore_value` bigint(255) NOT NULL,
                              `date_recorded` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
                              INDEX `id_hs_lb` (`minigameID`, `leaderboard`, `highscore_value`),
                              INDEX `highscore_value` (`highscore_value`),
                              INDEX `date_recorded` (`date_recorded`)
                            ) ENGINE=InnoDB DEFAULT CHARSET=latin1;"
                        );
<commit_msg>Add user_name to highscore cronjob<commit_after>#!/usr/bin/php -q
<?php
require_once('../../functions.php');
require_once('../../../global_functions.php');
require_once('../../../connections/parameters.php');

try {
    $db = new dbWrapper_v3($hostname_gds_cron, $username_gds_cron, $password_gds_cron, $database_gds_cron, true);

    $memcache = new Memcache;
    $memcache->connect("localhost", 11211); # You might need to set "localhost" to "127.0.0.1"

    if ($db) {
        $steamID = new SteamID();
        $steamWebAPI = new steam_webapi($api_key1);

        //Mini Game Leaderboard
        {
            try {
                $time_start1 = time();
                echo '<h2>Mini Game Leaderboard</h2>';

                $db->q("DROP TABLE IF EXISTS `cron_hs_temp`;");

                $leaderboards = $db->q(
                    'SELECT
                        DISTINCT sh.`minigameID`,
                        sh.`leaderboard`,
                        shm.`minigameName`,
                        shm.`minigameActive`,
                        shm.`minigameObjective`
                    FROM `stat_highscore` sh
                    JOIN `stat_highscore_minigames` shm ON sh.`minigameID` = shm.`minigameID`;'
                );

                if (!empty($leaderboards)) {
                    $sqlResult = $db->q(
                        "CREATE TABLE IF NOT EXISTS `cron_hs_temp` (
                          `minigameID` varchar(255) NOT NULL,
                          `leaderboard` varchar(255) NOT NULL,
                          `user_name` varchar(100) NOT NULL,
                          `user_id32` bigint(255) NOT NULL,
                          `highscore_value` bigint(255) NOT NULL,
                          `date_recorded` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
                          INDEX `id_hs_lb` (`minigameID`, `leaderboard`, `date_recorded`),
                          INDEX `highscore_value` (`highscore_value`),
                          INDEX `date_recorded` (`date_recorded`)
                        ) ENGINE=InnoDB DEFAULT CHARSET=latin1;"
                    );

                    foreach ($leaderboards as $key => $value) {
                        $minigameID = $value['minigameID'];
                        $leaderboard = $value['leaderboard'];
                        $mgName = $value['minigameName'];

                        $mgObjective = !empty($value['minigameObjective']) && $value['minigameObjective'] == 'min'
                            ? 'ASC'
                            : 'DESC';

                        $sqlResult = $db->q(
                            "INSERT INTO `cron_hs_temp`
                            SELECT
                              `minigameID`,
                              `leaderboard`,
                              `user_name`,
                              `user_id32`,
                              `highscore_value`,
                              `date_recorded`
                            FROM `stat_highscore`
                            WHERE `minigameID` = ? AND `leaderboard` = ?
                            GROUP BY `minigameID`, `leaderboard`, `user_id32`
                            ORDER BY `minigameID`, `leaderboard`, `highscore_value` $mgObjective
                            LIMIT 0,20;",
                            'ss',
                            array($minigameID, $leaderboard)
                        );

                        echo $sqlResult
                            ? "[SUCCESS] Gathered High Scores for: $mgName [$leaderboard]!<br />"
                            : "[FAILURE] Gathered High Scores for: $mgName [$leaderboard]!<br />";
                    }

                    $sqlResult = $db->q(
                        'SELECT * FROM `cron_hs_temp`;'
                    );

                    if (!empty($sqlResult)) {
                        $db->q(
                            "CREATE TABLE IF NOT EXISTS `cron_hs` (
                              `minigameID` varchar(255) NOT NULL,
                              `leaderboard` varchar(255) NOT NULL,
                              `user_name` varchar(100) NOT NULL,
                              `user_id32` bigint(255) NOT NULL,
                              `highscore_value` bigint(255) NOT NULL,
                              `date_recorded` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
                              INDEX `id_hs_lb` (`minigameID`, `leaderboard`, `highscore_value`),
                              INDEX `highscore_value` (`highscore_value`),
                              INDEX `date_recorded` (`date_recorded`)
                            ) ENGINE=InnoDB DEFAULT CHARSET=latin1;"
                        );

{'fraction_non_alphanumeric': 0.10907712305025996, 'fraction_numerical': 0.018197573656845753, 'mean_word_length': 1.1166895919303073, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '4602529', 'n_tokens_mistral': 2662, 'n_tokens_neox': 2354, 'n_words': 477}