public function run() { $faker = faker::create(); $students = student::all()->lists('id'); $course = ['physics', 'math', 'english', 'data structure', 'A.I']; foreach (range(1, 30) as $index) { course::create(array('student_id' => $faker->randomElement($students), 'course_name' => $faker->randomElement($course), 'created_at' => $faker->dateTimeBetween('now', '+14 days'))); } }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { //return view('test'); $students = student::all(); return view('students.index', compact('students')); }
public function makeTeams(Request $request) { //delete all from teams and teamMembers DB::table('teams')->truncate(); DB::table('teamMembers')->truncate(); //put all students into array $students = \App\student::all(); $comp = array(); $sosh = array(); $donkeyKong = array(); foreach ($students as $student) { $student->skill = 4 * $student->fourHundreds + 3 * $student->threeHundreds + 2 * $student->twoHundreds; if ($student->teamStyle == "competitive") { array_push($comp, $student); } elseif ($student->teamStyle == "social") { array_push($sosh, $student); } else { array_push($donkeyKong, $student); } } $id = 1; //sort arrays by skill $comp = collect($comp)->sortBy('skill'); $sosh = collect($sosh)->sortBy('skill'); $donkeyKong = collect($donkeyKong)->sortBy('skill'); $teams = $this->algorithm($comp, intval($request->max), intval($request->min)); for ($i = 1; $i < count($teams); $i = $i + 1) { $c = 0; $j = 0; $p = 0; foreach ($teams[$i] as $student) { $c = $c + intval($student->c); $j = $j + intval($student->java); $p = $p + intval($student->python); } DB::table('teams')->insert(array('name' => "Team " . $id, 'c' => $c, 'java' => $j, 'python' => $p, 'type' => 'Competitive')); foreach ($teams[$i] as $student) { DB::table('teamMembers')->insert(array('studentId' => $student->id, 'teamId' => $id)); } $id = $id + 1; } foreach ($teams[0] as $student) { DB::table('teamMembers')->insert(array('studentId' => $student->id, 'teamId' => 0)); } $teams = $this->algorithm($sosh, $request->max, $request->min); for ($i = 1; $i < count($teams); $i = $i + 1) { $c = 0; $j = 0; $p = 0; foreach ($teams[$i] as $student) { $c = $c + intval($student->c); $j = $j + intval($student->java); $p = $p + intval($student->python); } DB::table('teams')->insert(array('name' => "Team " . $id, 'c' => $c, 'java' => $j, 'python' => $p, 'type' => 'Social')); foreach ($teams[$i] as $student) { DB::table('teamMembers')->insert(array('studentId' => $student->id, 'teamId' => $id)); } $id = $id + 1; } foreach ($teams[0] as $student) { DB::table('teamMembers')->insert(array('studentId' => $student->id, 'teamId' => 0)); } $teams = $this->algorithm($donkeyKong, $request->max, $request->min); for ($i = 1; $i < count($teams); $i = $i + 1) { $c = 0; $j = 0; $p = 0; foreach ($teams[$i] as $student) { $c = $c + intval($student->c); $j = $j + intval($student->java); $p = $p + intval($student->python); } DB::table('teams')->insert(array('name' => "Team " . $id, 'c' => $c, 'java' => $j, 'python' => $p, 'type' => "Don't Care")); foreach ($teams[$i] as $student) { DB::table('teamMembers')->insert(array('studentId' => $student->id, 'teamId' => $id)); } $id = $id + 1; } foreach ($teams[0] as $student) { DB::table('teamMembers')->insert(array('studentId' => $student->id, 'teamId' => 0)); } return Redirect::back(); }