<commit_before><?php

namespace App\Console\Commands;

use App\AcademyBasicExamEmail;
use App\AcademyExamAssignment;
use App\Classes\VATUSAMoodle;
use App\Http\Middleware\PrivateCORS;
use App\Mail\AcademyExamSubmitted;
use App\User;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;

class SendAcademyRatingExamEmails extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'moodle:sendexamemails';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Checks for final exam attempts and sends emails.';

    private $moodle;

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
        $this->moodle = new VATUSAMoodle();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     * @throws \Exception
     */
    public function handle()
    {
        foreach (AcademyExamAssignment::all() as $assignment) {
            $student = $assignment->student;
            $studentName = $student->name;
            $instructor = $assignment->instructor;
            $quizId = $assignment->quiz_id;
            $attemptEmailsSent = $assignment->attempt_emails_sent ? explode(',', $assignment->attempt_emails_sent) : [];

            if ($assignment->created_at->diffInDays(Carbon::now()) > 30) {
                log_action($assignment->student->cid,
                    "Academy exam course enrollment expired - $assignment->course_name - greater than 30 days");
                $assignment->delete();
                continue;
            }

            //Check for attempts
            $attempts = $this->moodle->getQuizAttempts($quizId, null, $assignment->moodle_uid);
            foreach ($attempts as $attempt) {
                if (in_array($attempt['attempt'], $attemptEmailsSent) || !in_array($attempt['quiz'], [
                        config('exams.S2.id'),
                        config('exams.S3.id'),
                        config('exams.C1.id')
                    ]) || $attempt['state'] !== "finished") {
                    continue;
                }

                $attemptNum = $attempt['attempt'];
                $attemptId = $attempt['id'];
                if ($attempt['quiz'] == config('exams.S2.id')) {
                    $passingGrade = config('exams.S2.passingPercent');
                    $testName = "S2 Rating (TWR) Controller";
                } elseif ($attempt['quiz'] == config('exams.S3.id')) {
                    $passingGrade = config('exams.S3.passingPercent');
                    $testName = "S3 Rating (APP/DEP) Controller";
                } else {
                    $passingGrade = config('exams.C1.passingPercent');
                    $testName = "C1 Rating (CTR) Controller";
                }
                $grade = $attempt['grade'];
                $passed = $grade >= $passingGrade;

                $result = compact('testName', 'studentName', 'attemptNum', 'grade',
                    'passed', 'passingGrade', 'attemptId');

                $mail = Mail::to($student)->cc($instructor);
                //if ($attemptNum == 3 && !$passed) {
                $mail->bcc(['<EMAIL>', '<EMAIL>', '<EMAIL>']);
                //}
                $mail->queue(new AcademyExamSubmitted($result));

                if ($passed) {
                    $assignment->delete();
                } else {
                    $attemptEmailsSent[] = $attemptNum;
                    $assignment->attempt_emails_sent = implode(',', $attemptEmailsSent);
                    $assignment->save();<commit_msg>Remove USA12 from rating exam emails<commit_after><?php

namespace App\Console\Commands;

use App\AcademyBasicExamEmail;
use App\AcademyExamAssignment;
use App\Classes\VATUSAMoodle;
use App\Http\Middleware\PrivateCORS;
use App\Mail\AcademyExamSubmitted;
use App\User;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;

class SendAcademyRatingExamEmails extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'moodle:sendexamemails';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Checks for final exam attempts and sends emails.';

    private $moodle;

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
        $this->moodle = new VATUSAMoodle();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     * @throws \Exception
     */
    public function handle()
    {
        foreach (AcademyExamAssignment::all() as $assignment) {
            $student = $assignment->student;
            $studentName = $student->name;
            $instructor = $assignment->instructor;
            $quizId = $assignment->quiz_id;
            $attemptEmailsSent = $assignment->attempt_emails_sent ? explode(',', $assignment->attempt_emails_sent) : [];

            if ($assignment->created_at->diffInDays(Carbon::now()) > 30) {
                log_action($assignment->student->cid,
                    "Academy exam course enrollment expired - $assignment->course_name - greater than 30 days");
                $assignment->delete();
                continue;
            }

            //Check for attempts
            $attempts = $this->moodle->getQuizAttempts($quizId, null, $assignment->moodle_uid);
            foreach ($attempts as $attempt) {
                if (in_array($attempt['attempt'], $attemptEmailsSent) || !in_array($attempt['quiz'], [
                        config('exams.S2.id'),
                        config('exams.S3.id'),
                        config('exams.C1.id')
                    ]) || $attempt['state'] !== "finished") {
                    continue;
                }

                $attemptNum = $attempt['attempt'];
                $attemptId = $attempt['id'];
                if ($attempt['quiz'] == config('exams.S2.id')) {
                    $passingGrade = config('exams.S2.passingPercent');
                    $testName = "S2 Rating (TWR) Controller";
                } elseif ($attempt['quiz'] == config('exams.S3.id')) {
                    $passingGrade = config('exams.S3.passingPercent');
                    $testName = "S3 Rating (APP/DEP) Controller";
                } else {
                    $passingGrade = config('exams.C1.passingPercent');
                    $testName = "C1 Rating (CTR) Controller";
                }
                $grade = $attempt['grade'];
                $passed = $grade >= $passingGrade;

                $result = compact('testName', 'studentName', 'attemptNum', 'grade',
                    'passed', 'passingGrade', 'attemptId');

                $mail = Mail::to($student)->cc($instructor);
                //if ($attemptNum == 3 && !$passed) {
                $mail->bcc(['<EMAIL>', '<EMAIL>']);
                //}
                $mail->queue(new AcademyExamSubmitted($result));

                if ($passed) {
                    $assignment->delete();
                } else {
                    $attemptEmailsSent[] = $attemptNum;
                    $assignment->attempt_emails_sent = implode(',', $attemptEmailsSent);
                    $assignment->save();
{'fraction_non_alphanumeric': 0.13696282625889797, 'fraction_numerical': 0.004481940416556815, 'mean_word_length': 1.8214949795462998, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 56, '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': '6266400', 'n_tokens_mistral': 2252, 'n_tokens_neox': 2071, 'n_words': 407}