/**
  * Adds a player into the DB.
  *
  * @param User $user
  * @param str $nickname
  *
  * @return Player
  */
 public function addPlayer(User $user, $nickname)
 {
     $player = new Player();
     $player->user_id = $user->id;
     $player->nickname = $nickname;
     $player->save();
     return $player;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param Request $request
  * @return Response
  */
 public function store(Request $request)
 {
     $player = new Player();
     $player->IMIE = $request->input("IMIE");
     $player->NAZWISKO = $request->input("NAZWISKO");
     $player->POZYCJA_ID_POZYCJA = $request->input("POZYCJA_ID_POZYCJA");
     $player->DRUZYNA_ID_DRUZYNA = $request->input("DRUZYNA_ID_DRUZYNA");
     $player->save();
     return redirect()->route('players.index')->with('message', 'Item created successfully.');
 }
 /**
  * 
  * @param string $playerName
  * @return type
  */
 public function showName($playerName)
 {
     $sorties = $this->sortieService->getForPlayer($playerName);
     try {
         $player = Player::with(['groupedAwards'])->where('playerName', $playerName)->firstOrFail();
     } catch (ModelNotFoundException $exception) {
         // If we can't find that player, but there are sorties available
         // for them, create a new record for them
         $player = new Player();
         $player->playerName = $playerName;
         $player->isActive = true;
         $player->save();
     }
     return view('player.show')->with('player', $player)->with('sorties', $sorties)->with('activity1', $this->generateActivity(1))->with('activity2', $this->generateActivity(2))->with('activity3', $this->generateActivity(3));
 }
 public function add(Request $request)
 {
     $this->validate($request, ['player_name' => 'required|' . (option('allow_chinese_playername') ? 'pname_chinese' : 'playername')]);
     Event::fire(new CheckPlayerExists($request->input('player_name')));
     if (!Player::where('player_name', $request->input('player_name'))->get()->isEmpty()) {
         return json(trans('user.player.add.repeated'), 6);
     }
     if ($this->user->getScore() < Option::get('score_per_player')) {
         return json(trans('user.player.add.lack-score'), 7);
     }
     Event::fire(new PlayerWillBeAdded($request->input('player_name')));
     $player = new Player();
     $player->uid = $this->user->uid;
     $player->player_name = $request->input('player_name');
     $player->preference = "default";
     $player->last_modified = Utils::getTimeFormatted();
     $player->save();
     Event::fire(new PlayerWasAdded($player));
     $this->user->setScore(option('score_per_player'), 'minus');
     return json(trans('user.player.add.success', ['name' => $request->input('player_name')]), 0);
 }
Ejemplo n.º 5
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->startLog();
     $team = Team::find(self::TEAM_ID);
     if ($team == null) {
         $this->error('Team with id: ' . self::TEAM_ID . ' not found');
         exit;
     }
     $html = new Htmldom($team->link);
     $team_table = $html->find('table.team-list', 0);
     if ($team_table == null) {
         $this->error('Team table not found on this page: ' . $team->link);
         exit;
     }
     $player_links = [];
     foreach ($team_table->find('p.player-name a') as $link) {
         if (isset($link->href)) {
             array_push($player_links, $link->href);
         }
     }
     if (count($player_links) < 1) {
         $this->error('No players found');
         exit;
     }
     $this->comment('Found players: ' . count($player_links));
     $bar = $this->output->createProgressBar(count($player_links));
     foreach ($player_links as $link) {
         if (strpos($link, self::DOMAIN) === false) {
             $link = self::DOMAIN . $link;
         }
         $player = new Player();
         $player->team_id = self::TEAM_ID;
         $player->mls_id = $this->parseIdFromUrl($link);
         $player_html = new Htmldom($link);
         if ($player_html == null) {
             continue;
         }
         $player_table = $player_html->find('table.adf-fields-table', 0);
         if ($player_table == null) {
             continue;
         }
         foreach ($player_table->find('tr') as $row) {
             $td1 = $row->find('td', 0);
             $td2 = $row->find('td', 1);
             if ($td1 != null && strpos($td1->innertext, 'Полное имя') !== false) {
                 $player->name = $td2->plaintext;
             }
             if ($td1 != null && strpos($td1->innertext, 'Дата рождения') !== false) {
                 $player->date_of_birth = Carbon::parse($td2->plaintext);
             }
         }
         $check_player = Player::where('mls_id', $player->mls_id)->where('name', $player->name)->where('team_id', $player->team_id)->where('date_of_birth', $player->date_of_birth)->first();
         if ($check_player) {
             $player->id = $check_player->id;
             $player->update();
         } else {
             $player->save();
         }
         $img = $player_html->find('div#etab_player_div div.gray-box img', 0);
         if ($img != null && $img->src != null && strpos($img->src, self::DEFAULT_IMG) === false) {
             $src = $img->src;
             if (strpos($src, self::DOMAIN) === false) {
                 $src = self::DOMAIN . $src;
             }
             copy($src, public_path() . '/img/avatars/players/' . $player->id . '.jpg');
         }
         $bar->advance();
     }
     $bar->finish();
     $this->endLog();
 }
Ejemplo n.º 6
0
 public function run()
 {
     $there_is_more = RawDatum::select('id')->whereNull('processed_utc')->first();
     if ($there_is_more) {
         $raw_data = RawDatum::whereNull('processed_utc')->take(4000)->get();
         foreach ($raw_data as $raw_datum) {
             $batter = Player::where('mlb_id', $raw_datum->batter_id)->first();
             if (!$batter) {
                 $batter = new Player();
                 $batter->mlb_id = $raw_datum->batter_id;
                 $batter->name = $raw_datum->batter;
             }
             $batter->batter_hand = $raw_datum->batter_hand;
             $batter->timestamp_utc = time();
             $batter->save();
             $pitcher = Player::where('mlb_id', $raw_datum->pitcher_id)->first();
             if (!$pitcher) {
                 $pitcher = new Player();
                 $pitcher->mlb_id = $raw_datum->pitcher_id;
                 $pitcher->name = $raw_datum->pitcher;
             }
             $pitcher->pitcher_hand = $raw_datum->pitcher_hand;
             $pitcher->timestamp_utc = time();
             $pitcher->save();
             $catcher = Player::where('mlb_id', $raw_datum->catcher_id)->first();
             if (!$catcher) {
                 $catcher = new Player();
                 $catcher->mlb_id = $raw_datum->catcher_id;
                 $catcher->name = $raw_datum->catcher;
             }
             $catcher->timestamp_utc = time();
             $catcher->save();
             $pitch_result = PitchResult::where('slug', $raw_datum->pitch_result)->first();
             if (!$pitch_result) {
                 $pitch_result = new PitchResult();
                 $pitch_result->slug = $raw_datum->pitch_result;
                 $pitch_result->timestamp_utc = time();
                 $pitch_result->save();
             }
             $pitch_type = PitchType::where('slug', $raw_datum->pitch_type)->first();
             if (!$pitch_type) {
                 $pitch_type = new PitchType();
                 $pitch_type->slug = $raw_datum->pitch_type;
                 $pitch_type->timestamp_utc = time();
                 $pitch_type->save();
             }
             $plate_appearance_result = PlateAppearanceResult::where('slug', $raw_datum->pa_result)->first();
             if (!$plate_appearance_result) {
                 $plate_appearance_result = new PlateAppearanceResult();
                 $plate_appearance_result->slug = $raw_datum->pa_result;
                 $plate_appearance_result->timestamp_utc = time();
                 $plate_appearance_result->save();
             }
             $batted_ball_type = BattedBallType::where('slug', $raw_datum->batted_ball_type)->first();
             if (!$batted_ball_type) {
                 $batted_ball_type = new BattedBallType();
                 $batted_ball_type->slug = $raw_datum->batted_ball_type;
                 $batted_ball_type->timestamp_utc = time();
                 $batted_ball_type->save();
             }
             $pitch = Pitch::where('raw_data_id', $raw_datum->id)->first();
             if (!$pitch) {
                 $pitch = new Pitch();
                 $pitch->raw_data_id = $raw_datum->id;
             }
             $pitch->season_year = $raw_datum->season_year;
             $pitch->game_string = $raw_datum->game_string;
             $pitch->game_date = $raw_datum->game_date;
             $pitch->game_type = $raw_datum->game_type;
             $pitch->visitor = $raw_datum->visitor;
             $pitch->home = $raw_datum->home;
             $pitch->visiting_team_final_runs = $raw_datum->visiting_team_final_runs;
             $pitch->home_team_final_runs = $raw_datum->home_team_final_runs;
             $pitch->inning = $raw_datum->inning;
             $pitch->side = $raw_datum->side;
             if ($batter->id == 0 || $pitcher->id == 0) {
                 dd(array('raw_data' => $raw_datum, 'batter' => $batter, 'pitcher' => $pitcher));
             }
             $pitch->batter_id = $batter->id;
             $pitch->pitcher_id = $pitcher->id;
             $pitch->inning = $raw_datum->inning;
             $pitch->catcher_id = $catcher->id;
             $pitch->times_faced = $raw_datum->times_faced;
             $pitch->batter_pos = $raw_datum->batter_pos;
             $position = Position::where('abbr', $raw_datum->batter_pos)->first();
             if ($position) {
                 $player_position = PlayerPosition::where('player_id', $batter->id)->where('position_id', $position->id)->first();
                 if (!$player_position) {
                     $player_position = new PlayerPosition();
                     $player_position->player_id = $batter->id;
                     $player_position->position_id = $position->id;
                     $player_position->save();
                 }
             }
             $pitch->balls = $raw_datum->balls;
             $pitch->strikes = $raw_datum->strikes;
             $pitch->outs = $raw_datum->outs;
             $pitch->man_on_first = $raw_datum->man_on_first == "TRUE";
             $pitch->man_on_second = $raw_datum->man_on_second == "TRUE";
             $pitch->man_on_third = $raw_datum->man_on_third == "TRUE";
             $pitch->end_man_on_first = $raw_datum->end_man_on_first == "TRUE";
             $pitch->end_man_on_second = $raw_datum->end_man_on_second == "TRUE";
             $pitch->end_man_on_third = $raw_datum->end_man_on_third == "TRUE";
             $pitch->visiting_team_current_runs = $raw_datum->visiting_team_current_runs;
             $pitch->home_team_current_runs = $raw_datum->home_team_current_runs;
             $pitch->pitch_result_id = $pitch_result->id;
             $pitch->pitch_type_id = $pitch_type->id;
             $pitch->release_velocity = $raw_datum->release_velocity;
             $pitch->spin_rate = $raw_datum->spin_rate;
             $pitch->spin_direction = $raw_datum->spin_direction;
             $pitch->px = $raw_datum->px;
             $pitch->pz = $raw_datum->pz;
             $pitch->szt = $raw_datum->szt;
             $pitch->szb = $raw_datum->szb;
             $pitch->x0 = $raw_datum->x0;
             $pitch->y0 = $raw_datum->y0;
             $pitch->z0 = $raw_datum->z0;
             $pitch->vx0 = $raw_datum->vx0;
             $pitch->vy0 = $raw_datum->vy0;
             $pitch->vz0 = $raw_datum->vz0;
             $pitch->ax = $raw_datum->ax;
             $pitch->ay = $raw_datum->ay;
             $pitch->az = $raw_datum->az;
             $pitch->pa_result_id = $plate_appearance_result->id;
             $pitch->runs_home = $raw_datum->runsHome;
             $pitch->batted_ball_type_id = $batted_ball_type->id;
             $pitch->batted_ball_angle = $raw_datum->batted_ball_angle;
             $pitch->batted_ball_distance = $raw_datum->batted_ball_distance;
             $pitch->atbat_desc = $raw_datum->atbat_desc;
             $pitch->timestamp_utc = time();
             if (!$pitch->save()) {
                 dd($raw_datum);
             }
             if ($raw_datum->id % 1000 == 0) {
                 echo "Processed record number " . $raw_datum->id . "\n\r";
             }
             $raw_datum->processed_utc = time();
             $raw_datum->save();
         }
     }
 }