<commit_before><?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Validator;
use Carbon\Carbon;

use App\Student;
use App\User;
use App\Instructor;

class StudentController extends Controller
{
    
    /**
	 * Display list of students
	 * 
	 *  @return Response
     */

    public function index()
    {
    	$students = Student::with('hours')->with('payments')->get();
    	//dd($students);
    	return view('admin.student.index', ['students' => $students]);
    }

    public function show($id)
    {
        //$student = Student::findOrFail($id);
        $student = Student::whereId($id)->with('hours.drive','payments')->first();
        $status = 'active';
        $studentCanDrive = $student->hours->sum('count')+$student->hours_start < $student->hours_count;
        if ($status != 'active' || !$studentCanDrive) {
            $studentCanDrive = $instructor = false;
            return view('admin.student.show', compact('student', 'instructors', 'studentCanDrive'));
        }
        $payed = $student->payments->sum('amount');
        $drivesPerWeek = collect([200,500,1000]);
        $student->dpwCount = $drivesPerWeek->filter( function ($item, $key) use ($payed) {
            return $item <= $payed;
        })->count();
        $studentCanDriveGtThisWeek = $student->hours->keyBy('drive.date')->sortByDesc('drive.date')->filter( function ($hour, $key) {
                return $key > Carbon::parse('last year 0:00');//change to last week
        });
        for ($i=0; $i < 4; $i++) { 
            $tmp[$i] = $studentCanDriveGtThisWeek->filter( function ($item, $key) use ($i){
                $week = Carbon::parse('this week 0:00')->addWeeks($i);
                return $key > $week && $key < $week->addWeeks(1);
            });
            $studentCanDriveGtThisWeek = $studentCanDriveGtThisWeek->diff($tmp[$i])->keyBy('drive.date');
            $tmp[$i] = $tmp[$i]->count();
        }
        $studentCanDrive = $tmp;

        $instructors = Instructor::with(['drives' => function ($query){ $query->where('date', '>', date('Y-m-d', strtotime('tomorrow'))); }])->get()->keyBy('id');
        foreach ($instructors as $key => $instructor) {
            $sorted = $instructor->drives->keyBy('date');
            for ($i=0; $i < 4; $i++) { 
                $drivesTW[$i] = $sorted->filter( function ($item, $key) use ($i){
                    $week = Carbon::parse('this week 0:00')->addWeeks($i);
                    return $key > $week && $key < $week->addWeeks(1);
                });
                $sorted = $sorted->diff($drivesTW[$i])->keyBy('date');
            }
            $instructor->drives = collect($drivesTW);
        }
        return view('admin.student.show', compact('student', 'instructors', 'studentCanDrive'));
    }

    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name'          => 'required|max:255',
            'email'         => 'required|email|max:255|unique:users,id',
            'password'      => '<PASSWORD>',
            'hours_count'   => 'required|numeric|min:1|max:128',
            'hours_count'   => 'required|numeric|min:0|max:128',
            'cost'          => 'required|numeric|min:30|max:5000',
        ]);
    }

    public function create()
    {
        return view('admin.student.create');
    }


    public function store(Request $request)<commit_msg>validator second hours_count > hours_start<commit_after><?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Validator;
use Carbon\Carbon;

use App\Student;
use App\User;
use App\Instructor;

class StudentController extends Controller
{
    
    /**
	 * Display list of students
	 * 
	 *  @return Response
     */

    public function index()
    {
    	$students = Student::with('hours')->with('payments')->get();
    	//dd($students);
    	return view('admin.student.index', ['students' => $students]);
    }

    public function show($id)
    {
        //$student = Student::findOrFail($id);
        $student = Student::whereId($id)->with('hours.drive','payments')->first();
        $status = 'active';
        $studentCanDrive = $student->hours->sum('count')+$student->hours_start < $student->hours_count;
        if ($status != 'active' || !$studentCanDrive) {
            $studentCanDrive = $instructor = false;
            return view('admin.student.show', compact('student', 'instructors', 'studentCanDrive'));
        }
        $payed = $student->payments->sum('amount');
        $drivesPerWeek = collect([200,500,1000]);
        $student->dpwCount = $drivesPerWeek->filter( function ($item, $key) use ($payed) {
            return $item <= $payed;
        })->count();
        $studentCanDriveGtThisWeek = $student->hours->keyBy('drive.date')->sortByDesc('drive.date')->filter( function ($hour, $key) {
                return $key > Carbon::parse('last year 0:00');//change to last week
        });
        for ($i=0; $i < 4; $i++) { 
            $tmp[$i] = $studentCanDriveGtThisWeek->filter( function ($item, $key) use ($i){
                $week = Carbon::parse('this week 0:00')->addWeeks($i);
                return $key > $week && $key < $week->addWeeks(1);
            });
            $studentCanDriveGtThisWeek = $studentCanDriveGtThisWeek->diff($tmp[$i])->keyBy('drive.date');
            $tmp[$i] = $tmp[$i]->count();
        }
        $studentCanDrive = $tmp;

        $instructors = Instructor::with(['drives' => function ($query){ $query->where('date', '>', date('Y-m-d', strtotime('tomorrow'))); }])->get()->keyBy('id');
        foreach ($instructors as $key => $instructor) {
            $sorted = $instructor->drives->keyBy('date');
            for ($i=0; $i < 4; $i++) { 
                $drivesTW[$i] = $sorted->filter( function ($item, $key) use ($i){
                    $week = Carbon::parse('this week 0:00')->addWeeks($i);
                    return $key > $week && $key < $week->addWeeks(1);
                });
                $sorted = $sorted->diff($drivesTW[$i])->keyBy('date');
            }
            $instructor->drives = collect($drivesTW);
        }
        return view('admin.student.show', compact('student', 'instructors', 'studentCanDrive'));
    }

    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name'          => 'required|max:255',
            'email'         => 'required|email|max:255|unique:users,id',
            'password'      => '<PASSWORD>',
            'hours_count'   => 'required|numeric|min:1|max:128',
            'hours_start'   => 'required|numeric|min:0|max:128',
            'cost'          => 'required|numeric|min:30|max:5000',
        ]);
    }

    public function create()
    {
        return view('admin.student.create');
    }


    public function store(Request $request)
{'fraction_non_alphanumeric': 0.1857491739692573, 'fraction_numerical': 0.0129291768424077, 'mean_word_length': 2.514386673397274, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 100, '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': '2360437', 'n_tokens_mistral': 2259, 'n_tokens_neox': 2110, 'n_words': 382}