public static function nextLaunch($substatistic, $dynamicString)
 {
     if ($dynamicString === 'nextLaunchSummary') {
         return Cache::remember('stats:description:nextLaunch:summary', 60, function () {
             return Mission::future(1)->first()->summary;
         });
     }
 }
 public function compose($view)
 {
     $nearby = Cache::remember('nearbyMissions', 60, function () {
         $nearby['past'] = Mission::past()->take(3)->get();
         $nearby['future'] = Mission::future()->take(3)->get();
         return $nearby;
     });
     $view->with('nearbyMissions', ['past' => $nearby['past'], 'future' => $nearby['future']]);
 }
Exemplo n.º 3
0
 public function getFullTitleAttribute()
 {
     // Dynamically set the next launch title
     if ($this->type == 'Next Launch') {
         return 'Next Launch - ' . Mission::future(1)->first()->name;
     }
     // Otherwise simply concatenate the name to the type if not a duplicate
     if ($this->type === $this->name || is_null($this->name)) {
         return $this->type;
     } else {
         return $this->type . ' - ' . $this->name;
     }
 }
 /**
  * GET, /missions/future. Shows all future missions in a list.
  *
  * @return \Illuminate\View\View
  */
 public function allFutureMissions()
 {
     JavaScript::put(['missions' => Mission::future()->with(['vehicle', 'destination'])->get()->map(function ($mission) {
         $transformedMission = $mission->toArray();
         if ($mission->launch_specificity >= LaunchSpecificity::Day) {
             $transformedMission['launch_date_time'] = $mission->present()->launchDateTime();
         }
         $transformedMission['generic_vehicle'] = $mission->vehicle->generic_vehicle;
         $transformedMission['generic_vehicle_count'] = ordinal($mission->generic_vehicle_count);
         $transformedMission['launch_of_year'] = ordinal($mission->launch_of_year);
         $transformedMission['launch_site'] = $mission->launchSite->full_location;
         $transformedMission['featured_image_url'] = $mission->present()->featuredImageUrl();
         $transformedMission['launch_probability'] = $mission->present()->launchProbability();
         return $transformedMission;
     })]);
     return view('missions.future');
 }
 /**
  * GET (HTTP). Home.
  *
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
  */
 public function home()
 {
     if (Auth::isSubscriber()) {
         // Fetch data
         $objects['latest'] = Object::authedVisibility()->inMissionControl()->orderBy('created_at', 'desc')->take(10)->get();
         $objects['hot'] = Object::authedVisibility()->inMissionControl()->selectRaw('objects.*, LOG10(greatest(1, count(comments.object_id)) + greatest(1, count(favorites.object_id))) / TIMESTAMPDIFF(HOUR, objects.actioned_at, NOW()) as score')->leftJoin('comments', 'comments.object_id', '=', 'objects.object_id')->leftJoin('favorites', 'favorites.object_id', '=', 'objects.object_id')->groupBy('objects.object_id')->orderBy(DB::raw('score'))->take(10)->get();
         $objects['discussions'] = Object::authedVisibility()->inMissionControl()->where('type', MissionControlType::Text)->join('comments', 'comments.object_id', '=', 'objects.object_id')->orderBy('comments.created_at')->select('objects.*')->take(10)->get();
         $objects['mission'] = Object::authedVisibility()->inMissionControl()->whereHas('Mission', function ($q) {
             $q->future()->take(1);
         })->take(10)->get();
         $objects['random'] = Object::authedVisibility()->inMissionControl()->orderByRaw("RAND()")->take(10)->get();
         // Leaderboards
         $leaderboards['week'] = User::join('awards', 'awards.user_id', '=', 'users.user_id')->selectRaw('users.user_id, users.username, sum(awards.value) as totalDeltaV')->where('awards.created_at', '>=', Carbon::now()->subWeek())->groupBy('users.user_id')->take(10)->get();
         $leaderboards['month'] = User::join('awards', 'awards.user_id', '=', 'users.user_id')->selectRaw('users.user_id, users.username, sum(awards.value) as totalDeltaV')->where('awards.created_at', '>=', Carbon::now()->subMonth())->groupBy('users.user_id')->take(10)->get();
         $leaderboards['year'] = User::join('awards', 'awards.user_id', '=', 'users.user_id')->selectRaw('users.user_id, users.username, sum(awards.value) as totalDeltaV')->where('awards.created_at', '>=', Carbon::now()->subYear())->groupBy('users.user_id')->take(10)->get();
         $leaderboards['alltime'] = User::join('awards', 'awards.user_id', '=', 'users.user_id')->selectRaw('users.user_id, users.username, sum(awards.value) as totalDeltaV')->groupBy('users.user_id')->take(10)->get();
         // Comments
         $comments = Comment::with(['object' => function ($query) {
             $query->select('object_id', 'title');
         }])->with(['user' => function ($query) {
             $query->select('user_id', 'username');
         }])->orderBy('created_at', 'DESC')->take(10)->get();
         // Favorites
         $favorites = Favorite::with(['object' => function ($query) {
             $query->select('object_id', 'title');
         }])->with(['user' => function ($query) {
             $query->select('user_id', 'username');
         }])->orderBy('created_at', 'DESC')->take(10)->get();
         // Downloads
         $downloads = Download::with(['object' => function ($query) {
             $query->select('object_id', 'title');
         }])->with(['user' => function ($query) {
             $query->select('user_id', 'username');
         }])->orderBy('created_at', 'DESC')->take(10)->get();
         return view('missionControl.home', ['upcomingMission' => Mission::future()->first(), 'leaderboards' => $leaderboards, 'objects' => $objects, 'comments' => $comments, 'favorites' => $favorites, 'downloads' => $downloads]);
     } else {
         return redirect()->action('MissionControl\\MissionControlController@about');
     }
 }
 /**
  * Create a SpaceXStats Live event. Set all the necessary Redis parameters, render a Reddit Thread template,
  * publish it, then broadcast a LiveStartedEvent to notify websocket listeners.
  *
  * @return mixed
  */
 public function create()
 {
     // Turn on SpaceXStats Live
     Redis::set('live:active', true);
     // Set the streams available
     Redis::hmset('live:streams', ['spacex' => json_encode(Input::get('streams.spacex')), 'spacexClean' => json_encode(Input::get('streams.spacexClean')), 'nasa' => json_encode(Input::get('streams.nasa'))]);
     // Set the countdown
     Redis::hmset('live:countdown', ['to' => Input::get('countdown.to'), 'isPaused' => false]);
     // Set the details
     Redis::set('live:title', Input::get('title'));
     Redis::hmset('live:description', ['raw' => Input::get('description.raw'), 'markdown' => Parsedown::instance()->parse(Input::get('description.raw'))]);
     Redis::set('live:isForLaunch', Input::get('isForLaunch'));
     Redis::set('live:resources', json_encode(Input::get('resources')));
     Redis::set('live:sections', json_encode(Input::get('sections')));
     Redis::set('live:status', 'Upcoming');
     // Set the Reddit parameters
     Redis::hmset('live:reddit', ['title' => Input::get('reddit.title')]);
     // Create the canned responses
     Redis::hmset('live:cannedResponses', ['holdAbort' => 'HOLD HOLD HOLD. The countdown has been aborted.', 'terminalCount' => 'Terminal count has now begun. From this point forward, any scrubs will result in a recycle to T-10 minutes.', 'inProgress' => 'Liftoff of ' . Mission::future()->first()->name . '!', 'maxQ' => 'MaxQ, at this point in flight, the vehicle is flying through maximum aerodynamic pressure.', 'MECO' => "MECO! The vehicle's first stage engines have shutdown in preparation for stage separation.", 'stageSep' => 'Stage separation confirmed.', 'mVacIgnition' => "Falcon's upper stage Merlin Vacuum engine has ignited for the ride to orbit.", 'SECO' => 'SECO! Falcon is now in orbit!', 'missionSuccess' => 'Success! SpaceX has completed another successful mission!', 'missionFailure' => 'We appear to have had a failure. We will bring more information to you as it is made available.']);
     // Render the Reddit thread template
     $templatedOutput = view('templates.livethreadcontents')->with(array())->render();
     // Create the Reddit thread (create a service for this)
     $reddit = new Reddit(Config::get('services.reddit.username'), Config::get('services.reddit.password'), Config::get('services.reddit.id'), Config::get('services.reddit.secret'));
     $reddit->setUserAgent('/u/ElongatedMuskrat by /u/EchoLogic. Runs various /r/SpaceX-related tasks.');
     // Create a post
     $subreddit = App::environment('production') ? 'spacex' : 'echocss';
     $response = $reddit->subreddit($subreddit)->submit(['kind' => 'self', 'sendreplies' => true, 'text' => $templatedOutput, 'title' => Input::get('reddit.title')]);
     Redis::hmset('live:reddit', ['thing' => $response->data->name]);
     // Broadcast event to turn on spacexstats live
     event(new LiveStartedEvent(['active' => true, 'streams' => ['spacex' => Input::get('streams.spacex'), 'spacexClean' => Input::get('streams.spacexClean'), 'nasa' => Input::get('streams.nasa')], 'countdown' => ['to' => Input::get('countdown.to'), 'isPaused' => false], 'title' => Input::get('title'), 'reddit' => ['title' => Input::get('reddit.title'), 'thing' => $response->data->name], 'description' => Redis::hgetall('live:description'), 'isForLaunch' => Input::get('isForLaunch'), 'resources' => Input::get('resources'), 'sections' => Input::get('sections'), 'status' => 'Upcoming', 'cannedResponses' => Redis::hgetall('live:cannedResponses')]));
     // Respond
     return response()->json(null, 204);
 }
Exemplo n.º 7
0
 /**
  *  Checks if the current mission is the next to launch.
  *
  * @return bool     Is the launch next or not?
  */
 public function isNextToLaunch()
 {
     return $this->mission_id === Mission::future()->first()->mission_id;
 }
 public function __construct()
 {
     $this->now = Carbon::now();
     $this->lastRun = $this->now->subMinute();
     $this->nextMission = Mission::future()->first();
 }
 /**
  * @return mixed
  */
 public static function nextLaunch()
 {
     return Cache::remember('stats:nextLaunch', 60, function () {
         return Mission::future(1)->first()->toArray();
     });
 }