/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker\Factory::create(); try { // DB::table('phpbb_forums')->delete(); // DB::table('phpbb_topics')->delete(); // DB::table('phpbb_posts')->delete(); $forums = []; $beatmapCount = App\Models\Beatmapset::count(); if ($beatmapCount > 0) { // Create beatmap threads $f = App\Models\Forum\Forum::create(['forum_name' => 'Beatmap Threads', 'forum_desc' => 'Beatmap thread info for beatmaps', 'forum_type' => 0]); $f2 = $f->subforums()->save(factory(App\Models\Forum\Forum::class, 'child')->make(['parent_id' => 1, 'forum_name' => 'Beatmap Threads', 'forum_desc' => 'Beatmap thread info for beatmaps'])); $bms = App\Models\Beatmapset::all(); foreach ($bms as $set) { $t = $f2->topics()->save(factory(App\Models\Forum\Topic::class)->make(['forum_id' => $f2->forum_id, 'topic_poster' => $set->creator, 'topic_title' => $set->artist . ' - ' . $set->title])); $p = $t->posts()->save(factory(App\Models\Forum\Post::class)->make(['forum_id' => $f2->forum_id, 'poster_id' => $set->user_id, 'post_username' => $set->creator, 'post_subject' => $set->artist . ' - ' . $set->title, 'post_text' => '---------------'])); $t->refreshCache(); $set->thread_id = $t->topic_id; $set->save(); } $f2->refreshCache(); } // Create 3 forums factory(App\Models\Forum\Forum::class, 'parent', 3)->create()->each(function ($f) { for ($i = 0; $i < 4; $i++) { // Subforums for each forum. $f2 = $f->subforums()->save(factory(App\Models\Forum\Forum::class, 'child')->make()); // Topics for each subforum for ($j = 0; $j < 3; $j++) { $t = $f2->topics()->save(factory(App\Models\Forum\Topic::class)->make(['forum_id' => $f2->forum_id])); // Replies to the topic for ($k = 0; $k < 5; $k++) { $p = $t->posts()->save(factory(App\Models\Forum\Post::class)->make(['forum_id' => $f2->forum_id])); } // Refresh topic cache (updates last post times etc) $t->refreshCache(); } // Refresh forum cache $f2->refreshCache(); } }); } catch (\Illuminate\Database\QueryException $e) { echo $e->getMessage() . "\r\n"; } catch (Exception $ex) { echo $ex->getMessage() . "\r\n"; } }
/** * Run the database seeds. * * @return void */ public function run() { // DB::table('osu_scores')->delete(); // DB::table('osu_scores_high')->delete(); // DB::table('osu_scores_taiko')->delete(); // DB::table('osu_scores_taiko_high')->delete(); // DB::table('osu_scores_fruits')->delete(); // DB::table('osu_scores_fruits_high')->delete(); $beatmaps = App\Models\Beatmap::orderByRaw('RAND()')->get(); $beatmapCount = count($beatmaps); if ($beatmapCount === 0) { $this->command->info('Can\'t seed Scores due to having no beatmap data.'); return; } $faker = Faker::create(); $users = App\Models\User::all(); App\Models\Score\Model::unguard(); $allBeatmapsets = App\Models\Beatmapset::all(); $possible_ranks = ['A', 'S', 'B', 'SH', 'XH', 'X']; foreach ($users as $k => $u) { $osuBeatmaps = $beatmaps->where('playmode', 0)->take(20); $taikoBeatmaps = $beatmaps->where('playmode', 1)->take(20); $fruitsBeatmaps = $beatmaps->where('playmode', 2)->take(20); $maniaBeatmaps = $beatmaps->where('playmode', 3)->take(20); //add 20 osu! Standard scores foreach ($osuBeatmaps as $bm) { $bms = $allBeatmapsets->find($bm->beatmapset_id); $maxcombo = rand(1, $bm->countTotal); $possible_mods = [0, 16, 24, 64, 72]; // hr, hd/hr, dt, hd/dt $sc = App\Models\Score\Osu::create(['user_id' => $u->user_id, 'beatmap_id' => $bm->beatmap_id, 'beatmapset_id' => $bm->beatmapset_id, 'score' => rand(50000, 100000000), 'maxcombo' => $maxcombo, 'count300' => round($maxcombo * 0.8), 'count100' => rand(0, round($maxcombo * 0.15)), 'count50' => rand(0, round($maxcombo * 0.05)), 'countgeki' => round($maxcombo * 0.3), 'countmiss' => round($maxcombo * 0.05), 'countkatu' => round($maxcombo * 0.05), 'enabled_mods' => array_rand_val($possible_mods), 'date' => rand(1451606400, time()), 'pass' => $faker->boolean(85), 'rank' => array_rand_val($possible_ranks)]); $sc2 = App\Models\Score\Best\Osu::create(['user_id' => $u->user_id, 'beatmap_id' => $bm->beatmap_id, 'beatmapset_id' => $bm->beatmapset_id, 'score' => rand(50000, 100000000), 'maxcombo' => $maxcombo, 'count300' => round($maxcombo * 0.8), 'count100' => rand(0, round($maxcombo * 0.15)), 'count50' => rand(0, round($maxcombo * 0.05)), 'countgeki' => round($maxcombo * 0.3), 'countmiss' => round($maxcombo * 0.05), 'countkatu' => round($maxcombo * 0.05), 'enabled_mods' => array_rand_val($possible_mods), 'date' => rand(1451606400, time()), 'pp' => $faker->biasedNumberBetween(10, 100) * 1.5 * $bm->difficultyrating, 'rank' => array_rand_val($possible_ranks)]); } //Taiko scores foreach ($taikoBeatmaps as $bm) { $bms = $allBeatmapsets->find($bm->beatmapset_id); $maxcombo = rand(1, $bm->countTotal); $possible_mods = [0, 16, 24, 64, 72]; $sc3 = App\Models\Score\Taiko::create(['user_id' => $u->user_id, 'beatmap_id' => $bm->beatmap_id, 'beatmapset_id' => $bm->beatmapset_id, 'score' => rand(50000, 100000000), 'maxcombo' => $maxcombo, 'count300' => round($maxcombo * 0.8), 'count100' => rand(0, round($maxcombo * 0.15)), 'count50' => rand(0, round($maxcombo * 0.05)), 'countgeki' => round($maxcombo * 0.3), 'countmiss' => round($maxcombo * 0.05), 'countkatu' => round($maxcombo * 0.05), 'enabled_mods' => array_rand_val($possible_mods), 'date' => rand(1451606400, time()), 'pass' => $faker->boolean(85), 'rank' => array_rand_val($possible_ranks)]); $sc4 = App\Models\Score\Best\Taiko::create(['user_id' => $u->user_id, 'beatmap_id' => $bm->beatmap_id, 'beatmapset_id' => $bm->beatmapset_id, 'score' => rand(50000, 100000000), 'maxcombo' => $maxcombo, 'rank' => array_rand_val($possible_ranks), 'count300' => round($maxcombo * 0.8), 'count100' => rand(0, round($maxcombo * 0.15)), 'count50' => rand(0, round($maxcombo * 0.05)), 'countgeki' => round($maxcombo * 0.3), 'countmiss' => round($maxcombo * 0.05), 'countkatu' => round($maxcombo * 0.05), 'enabled_mods' => array_rand_val($possible_mods), 'date' => rand(1451606400, time()), 'pp' => $faker->biasedNumberBetween(10, 100) * 1.3 * $bm->difficultyrating]); } // end taiko //Fruits scores foreach ($fruitsBeatmaps as $bm) { $bms = $allBeatmapsets->find($bm->beatmapset_id); $maxcombo = rand(1, $bm->countTotal); $possible_mods = [0, 16, 24, 64, 72]; $sc5 = App\Models\Score\Fruits::create(['user_id' => $u->user_id, 'beatmap_id' => $bm->beatmap_id, 'beatmapset_id' => $bm->beatmapset_id, 'score' => rand(50000, 100000000), 'maxcombo' => $maxcombo, 'rank' => array_rand_val($possible_ranks), 'count300' => round($maxcombo * 0.8), 'count100' => rand(0, round($maxcombo * 0.15)), 'count50' => rand(0, round($maxcombo * 0.05)), 'countgeki' => round($maxcombo * 0.3), 'countmiss' => round($maxcombo * 0.05), 'countkatu' => round($maxcombo * 0.05), 'enabled_mods' => array_rand_val($possible_mods), 'date' => rand(1451606400, time()), 'pass' => $faker->boolean(85)]); $sc6 = App\Models\Score\Best\Fruits::create(['user_id' => $u->user_id, 'beatmap_id' => $bm->beatmap_id, 'beatmapset_id' => $bm->beatmapset_id, 'score' => rand(50000, 100000000), 'maxcombo' => $maxcombo, 'rank' => array_rand_val($possible_ranks), 'count300' => round($maxcombo * 0.8), 'count100' => rand(0, round($maxcombo * 0.15)), 'count50' => rand(0, round($maxcombo * 0.05)), 'countgeki' => round($maxcombo * 0.3), 'countmiss' => round($maxcombo * 0.05), 'countkatu' => round($maxcombo * 0.05), 'enabled_mods' => array_rand_val($possible_mods), 'date' => rand(1451606400, time()), 'pp' => $faker->biasedNumberBetween(10, 100) * 1.3 * $bm->difficultyrating]); } // end fruits //Mania scores foreach ($maniaBeatmaps as $bm) { $bms = $allBeatmapsets->find($bm->beatmapset_id); $maxcombo = rand(1, $bm->countTotal); $possible_mods = [0, 16, 24, 64, 72]; // hr, hd/hr, dt, hd/dt $sc7 = App\Models\Score\Mania::create(['user_id' => $u->user_id, 'beatmap_id' => $bm->beatmap_id, 'beatmapset_id' => $bm->beatmapset_id, 'score' => rand(50000, 100000000), 'maxcombo' => $maxcombo, 'rank' => array_rand_val($possible_ranks), 'count300' => round($maxcombo * 0.8), 'count100' => rand(0, round($maxcombo * 0.15)), 'count50' => rand(0, round($maxcombo * 0.05)), 'countgeki' => round($maxcombo * 0.3), 'countmiss' => round($maxcombo * 0.05), 'countkatu' => round($maxcombo * 0.05), 'enabled_mods' => array_rand_val($possible_mods), 'date' => rand(1451606400, time()), 'pass' => $faker->boolean(85)]); $sc8 = App\Models\Score\Best\Mania::create(['user_id' => $u->user_id, 'beatmap_id' => $bm->beatmap_id, 'beatmapset_id' => $bm->beatmapset_id, 'score' => rand(50000, 100000000), 'maxcombo' => $maxcombo, 'rank' => array_rand_val($possible_ranks), 'count300' => round($maxcombo * 0.8), 'count100' => rand(0, round($maxcombo * 0.15)), 'count50' => rand(0, round($maxcombo * 0.05)), 'countgeki' => round($maxcombo * 0.3), 'countmiss' => round($maxcombo * 0.05), 'countkatu' => round($maxcombo * 0.05), 'enabled_mods' => array_rand_val($possible_mods), 'date' => rand(1451606400, time()), 'pp' => $faker->biasedNumberBetween(10, 100) * 2 * $bm->difficultyrating]); } // end mania } App\Models\Score\Model::reguard(); }
/** * Run the database seeds. * * @return void */ public function run() { $beatmaps_array = []; $beatmapset_array = []; $overbeatmaps = []; $overbeatmapsets = []; $base_url = 'https://osu.ppy.sh/api/'; $api_key = env('OSU_API_KEY', null); if (empty($api_key)) { $this->command->error('Error: No OSU_API_KEY value set in .env file. Can\'t seed beatmap data!'); return; } $api = '&k=' . $api_key; $users = App\Models\User::orderByRaw('RAND()')->get()->toArray(); if (count($users) < 1) { $users = [['user_id' => 1]]; } try { $beatmaps = json_decode(file_get_contents($base_url . 'get_beatmaps?since=2016-01-01%2000:00:00' . $api)); $last_beatmapset = null; $beatmap_diff_names = []; $beatmapset_versions = 0; $set_playcount = 0; $number_of_beatmaps = count($beatmaps); $i = 0; $first_map = true; $last_map = false; foreach ($beatmaps as $bm) { $make_new_set = false; if ($i === $number_of_beatmaps - 1) { $make_new_set = true; $last_map = true; } // Here we are going to check if the current beatmap belongs to a new set, and make the set if necessary if ($last_beatmapset === $bm->beatmapset_id || $first_map === true) { ++$beatmapset_versions; $beatmap_diff_names[] = $bm->version . '@' . $bm->mode; $set_playcount += $bm->playcount; } else { $make_new_set = true; } if ($make_new_set === true) { if ($last_map === true) { $the_beatmap = $bm; } else { $the_beatmap = $previous_beatmap; } // Create new beatmapset $set = \App\Models\Beatmapset::where('beatmapset_id', $the_beatmap->beatmapset_id)->first(); if ($set) { $set->delete(); $overbeatmapsets[] = $the_beatmap->beatmapset_id; } $beatmap_diff_names = implode(',', $beatmap_diff_names); $set = new \App\Models\Beatmapset(); $set->beatmapset_id = $the_beatmap->beatmapset_id; $set->creator = $the_beatmap->creator; $set->artist = $the_beatmap->artist; $set->title = $the_beatmap->title; $set->displaytitle = $the_beatmap->title; $set->source = $the_beatmap->source; $set->tags = $the_beatmap->tags; $set->bpm = $the_beatmap->bpm; $set->approved = $the_beatmap->approved; $set->approved_date = $the_beatmap->approved_date; $set->genre_id = $the_beatmap->genre_id; $set->language_id = $the_beatmap->language_id; $set->versions_available = $beatmapset_versions; $set->difficulty_names = $beatmap_diff_names; $set->play_count = $set_playcount; $set->favourite_count = $the_beatmap->favourite_count; $set->user_id = array_rand_val($users)['user_id']; $set->submit_date = Carbon::now(); $set->save(); $set->difficulty_names = $beatmap_diff_names; $beatmapset_array[] = $set; $set_playcount = $bm->playcount; $beatmapset_versions = 1; $beatmap_diff_names = [$bm->version . '@' . $bm->mode]; } if ($new_bm = \App\Models\Beatmap::where('beatmap_id', $bm->beatmap_id)->first()) { $new_bm->delete(); $overbeatmaps[] = $new_bm; } $new_bm = new \App\Models\Beatmap(); $new_bm->beatmap_id = $bm->beatmap_id; $new_bm->beatmapset_id = $bm->beatmapset_id; $new_bm->filename = $bm->beatmapset_id . ' ' . $bm->artist . ' - ' . $bm->title . '.osz'; $new_bm->checksum = $bm->file_md5; $new_bm->version = $bm->version; $new_bm->total_length = $bm->total_length; $new_bm->hit_length = $bm->hit_length; $new_bm->countTotal = $bm->max_combo !== null ? $bm->max_combo : 1500; $new_bm->countNormal = round(intval($bm->max_combo) - 0.2 * intval($bm->max_combo)); $new_bm->countSlider = round(intval($bm->max_combo) - 0.8 * intval($bm->max_combo)) - 1; $new_bm->countSpinner = 1; $new_bm->diff_drain = $bm->diff_drain; $new_bm->diff_size = $bm->diff_size; $new_bm->diff_overall = $bm->diff_overall; $new_bm->diff_approach = $bm->diff_approach; $new_bm->playmode = $bm->mode; $new_bm->approved = $bm->approved; $new_bm->difficultyrating = $bm->difficultyrating; $new_bm->playcount = $bm->playcount; $new_bm->passcount = $bm->passcount; $new_bm->user_id = array_rand_val($users)['user_id']; $failtimes = App\Models\BeatmapFailtimes::where('beatmap_id', $new_bm->beatmap_id)->get(); if (!$failtimes->isEmpty()) { foreach ($failtimes as $ft) { $ft->delete(); } } // Generating the beatmap failtimes $new_bm->failtimes()->saveMany([factory(App\Models\BeatmapFailtimes::class, 'fail')->make(), factory(App\Models\BeatmapFailtimes::class, 'retry')->make()]); $new_bm->save(); $beatmaps_array[] = $new_bm; if ($first_map === true) { $first_map = false; } $last_beatmapset = $bm->beatmapset_id; $previous_beatmap = $bm; ++$i; } // end foreach beatmap $this->command->info('Saved ' . strval(count($beatmaps_array)) . ' Beatmaps (Overwritten ' . strval(count($overbeatmaps)) . ').'); $this->command->info('Saved ' . strval(count($beatmapset_array)) . ' Beatmap Sets (Overwritten ' . strval(count($overbeatmapsets)) . ').'); } catch (\Illuminate\Database\QueryException $e) { $this->command->error("DB Error: Unable to save Beatmap Data\r\n" . $e->getMessage()); } catch (Exception $ex) { $this->command->error("Error: Unable to save Beatmap Data\r\n" . $ex->getMessage()); } }
public function run() { // DB::table('osu_events')->delete(); App\Models\Event::unguard(); $beatmapCount = App\Models\Beatmap::count(); if ($beatmapCount === 0) { $this->command->info('Can\'t seed events due to having no beatmap data.'); return; } $faker = Faker::create(); $users = App\Models\User::all(); $generateEventText = function ($bm, $bms, $u, $rank) { switch ($bm->playmode) { case 0: $playmode = 'osu!'; break; case 1: $playmode = 'Taiko'; break; case 2: $playmode = 'Catch the Beat'; break; case 3: $playmode = 'osu!mania'; break; } $rank_letters = ['X', 'S', 'A']; $rank_letter = array_rand_val($rank_letters); $string = "<img src='/images/" . $rank_letter . "_small.png'/> <b><a href='/u/" . $u->user_id . "'>" . $u->username . '</a></b> achieved rank #' . $rank . " on <a href='/b/" . $bm->beatmap_id . "?m=0'>" . $bms->artist . ' - ' . $bms->title . ' [' . $bm->version . ']' . '</a> (' . $playmode . ')'; return $string; }; foreach ($users as $u) { if ($beatmapCount > 0) { $all_beatmaps = App\Models\Beatmap::orderByRaw('RAND()')->get(); for ($c = 0; $c < 4; $c++) { if ($all_beatmaps[$c]) { $bm = $all_beatmaps[$c]; $bms = App\Models\Beatmapset::find($bm->beatmapset_id); if (isset($bms)) { $is_rank_1 = $faker->boolean(20); if ($is_rank_1 === true) { $rank = 1; $epicfactor = 2; } else { $rank = strval(rand(1, 499)); $epicfactor = 1; } $txt = $generateEventText($bm, $bms, $u, $rank); $ev = $u->events()->save(App\Models\Event::create(['user_id' => $u->user_id, 'text' => $txt, 'text_clean' => $txt, 'epicfactor' => $epicfactor, 'beatmap_id' => $bm->beatmap_id, 'beatmapset_id' => $bm->beatmapset_id, 'date' => rand(1451606400, time())])); } } } } // end rank events // Create a random supporter/name change event $string = ''; switch (rand(1, 4)) { case 1: $string = "<b><a href='/u/" . $u->user_id . "'>" . $u->username . '</a></b> has once again chosen to support osu! - thanks for your generosity!'; break; case 2: $string = "<b><a href='/u/" . $u->user_id . "'>" . $u->username . '</a></b> has become an osu! supporter - thanks for your generosity!'; break; case 3: $string = "<b><a href='/u/" . $u->user_id . "'>" . $u->username . '</a></b> has received the gift of osu! supporter!'; break; case 4: $string = "<b><a href='/u/" . $u->user_id . "'>" . $faker->userName . '</a></b> has changed their username to ' . $u->username . '!'; break; } $ev2 = $u->events()->save(App\Models\Event::create(['user_id' => $u->user_id, 'text' => $string, 'text_clean' => $string, 'epicfactor' => 1, 'date' => rand(1451606400, time())])); } // END EVENTS App\Models\Event::reguard(); }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker\Factory::create(); try { // Create appropriate forum permissions $authOptionIds = []; foreach (['f_post', 'f_reply'] as $authOption) { $option = new App\Models\Forum\AuthOption(); $option->auth_option = $authOption; $option->save(); $authOptionIds[] = $option->auth_option_id; } $beatmapCount = App\Models\Beatmapset::count(); if ($beatmapCount > 0) { // Create beatmap threads $f = App\Models\Forum\Forum::create(['forum_name' => 'Beatmap Threads', 'forum_desc' => 'Beatmap thread info for beatmaps', 'forum_type' => 0]); $f2 = $f->subforums()->save(factory(App\Models\Forum\Forum::class, 'child')->make(['parent_id' => 1, 'forum_name' => 'Beatmap Threads', 'forum_desc' => 'Beatmap thread info for beatmaps'])); $bms = App\Models\Beatmapset::all(); foreach ($bms as $set) { $t = $f2->topics()->save(factory(App\Models\Forum\Topic::class)->make(['forum_id' => $f2->forum_id, 'topic_poster' => $set->creator, 'topic_title' => $set->artist . ' - ' . $set->title])); $p = $t->posts()->save(factory(App\Models\Forum\Post::class)->make(['forum_id' => $f2->forum_id, 'poster_id' => $set->user_id, 'post_username' => $set->creator, 'post_subject' => $set->artist . ' - ' . $set->title, 'post_text' => '---------------'])); $t->refreshCache(); $set->thread_id = $t->topic_id; $set->save(); } $f2->refreshCache(); } // Create 3 forums factory(App\Models\Forum\Forum::class, 'parent', 3)->create()->each(function ($f) { for ($i = 0; $i < 4; $i++) { // Subforums for each forum. $f2 = $f->subforums()->save(factory(App\Models\Forum\Forum::class, 'child')->make()); // Topics for each subforum for ($j = 0; $j < 3; $j++) { $t = $f2->topics()->save(factory(App\Models\Forum\Topic::class)->make(['forum_id' => $f2->forum_id])); // Replies to the topic for ($k = 0; $k < 5; $k++) { $p = $t->posts()->save(factory(App\Models\Forum\Post::class)->make(['forum_id' => $f2->forum_id])); } // Refresh topic cache (updates last post times etc) $t->refreshCache(); } // Refresh forum cache $f2->refreshCache(); } }); foreach (App\Models\Forum\Forum::all() as $forum) { foreach ($authOptionIds as $optionId) { $group = new App\Models\Forum\Authorize(); $group->group_id = App\Models\UserGroup::GROUPS['default']; $group->forum_id = $forum->forum_id; $group->auth_option_id = $optionId; $group->auth_setting = 1; $group->save(); } } } catch (\Illuminate\Database\QueryException $e) { echo $e->getMessage() . "\r\n"; } catch (Exception $ex) { echo $ex->getMessage() . "\r\n"; } }