<commit_before><?php

use App\Entities\Contest;
use App\Entities\Solution;
use App\Entities\User;
use App\Services\ContestService;
use Carbon\Carbon;

if (!function_exists('can_attend')) {
    function can_attend($contest) {
        /** @var User $user */
        $user = auth()->user();
        if (!$user) {
            return false;
        }
        if ($user->hasRole('admin')) {
            return true;
        }
        return $contest->users()
                       ->wherePivot('user_id', '=', $user->id)
                       ->get()
                       ->count();
    }
}

if (!function_exists('show_ratio')) {
    function show_ratio($top, $down)
    {
        $result = 0;
        if ($down > 0) {
            $result = 100.0 * $top / $down;
        }

        return sprintf('%2.2f%%', $result);
    }
}

if (!function_exists('display_penalize_time')) {
    function display_penalize_time($seconds)
    {
        $hour        = $seconds / (Carbon::SECONDS_PER_MINUTE * Carbon::MINUTES_PER_HOUR);
        $minute      = $seconds % Carbon::SECONDS_PER_MINUTE;
        $leftSeconds = $seconds % Carbon::SECONDS_PER_MINUTE;

        return sprintf('%d:%02d:%02d', $hour, $minute, $leftSeconds);
    }
}

if (!function_exists('show_order')) {
    function show_order($order)
    {
        return chr($order + ord('A'));
    }
}

if (!function_exists('show_problem_id')) {
    /**
     * @param Solution $solution
     *
     * @return int|string
     */
    function show_problem_id($solution)
    {
        if ($solution->contest_id) {
            return show_order($solution->order);
        }

        return $solution->problem_id;
    }
}

if(!function_exists('opening_contest')) {
    function opening_contest()
    {
        return (new ContestService())->openingContest();
    }
}

if (!function_exists('original_order')) {
    function original_order($order)
    {
        return ord($order) - ord('A');
    }
}

if (!function_exists('!show_status')) {
    function show_status($status)
    {
        if (array_key_exists($status, Solution::$status)) {
            return Solution::$status[$status];
        }

        return 'not found!';
    }
}<commit_msg>refactor(helper): code refactor<commit_after><?php

use App\Entities\Solution;
use App\Entities\User;
use App\Services\ContestService;
use Carbon\Carbon;

if (!function_exists('can_attend')) {
    function can_attend($contest)
    {
        /** @var User $user */
        $user = auth()->user();
        if (!$user) {
            return false;
        }
        if ($user->hasRole('admin')) {
            return true;
        }

        return $contest->users()->wherePivot('user_id', '=', $user->id)->get()->count();
    }
}

if (!function_exists('show_ratio')) {
    function show_ratio($top, $down)
    {
        $result = 0;
        if ($down > 0) {
            $result = 100.0 * $top / $down;
        }

        return sprintf('%2.2f%%', $result);
    }
}

if (!function_exists('display_penalize_time')) {
    function display_penalize_time($seconds)
    {
        $hour        = $seconds / (Carbon::SECONDS_PER_MINUTE * Carbon::MINUTES_PER_HOUR);
        $minute      = $seconds % Carbon::SECONDS_PER_MINUTE;
        $leftSeconds = $seconds % Carbon::SECONDS_PER_MINUTE;

        return sprintf('%d:%02d:%02d', $hour, $minute, $leftSeconds);
    }
}

if (!function_exists('show_order')) {
    function show_order($order)
    {
        return chr($order + ord('A'));
    }
}

if (!function_exists('show_problem_id')) {
    /**
     * @param Solution $solution
     *
     * @return int|string
     */
    function show_problem_id($solution)
    {
        if ($solution->contest_id) {
            return show_order($solution->order);
        }

        return $solution->problem_id;
    }
}

if (!function_exists('opening_contest')) {
    function opening_contest()
    {
        return (new ContestService())->openingContest();
    }
}

if (!function_exists('original_order')) {
    function original_order($order)
    {
        return ord($order) - ord('A');
    }
}

if (!function_exists('!show_status')) {
    function show_status($status)
    {
        if (array_key_exists($status, Solution::$status)) {
            return Solution::$status[$status];
        }

        return 'not found!';
    }
}
{'fraction_non_alphanumeric': 0.16037296037296037, 'fraction_numerical': 0.005594405594405594, 'mean_word_length': 2.360219263899765, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '3478592', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1367, 'n_words': 232}