Browse Source

calculate and show which missions are complete

master
Aaron Parecki 7 years ago
parent
commit
fecc297080
No known key found for this signature in database GPG Key ID: 276C2817346D6056
5 changed files with 187 additions and 4 deletions
  1. +22
    -0
      app/Http/Controllers/ScoreboardController.php
  2. +109
    -0
      app/Mission.php
  3. +5
    -3
      public/js/app.js
  4. +3
    -1
      resources/views/layouts/app.blade.php
  5. +48
    -0
      resources/views/scoreboard.blade.php

+ 22
- 0
app/Http/Controllers/ScoreboardController.php View File

@ -0,0 +1,22 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use App\Tweet, App\Team, App\Mission;
class ScoreboardController extends Controller
{
public function index() {
$teams = Team::orderBy('name')->get();
$missions = Mission::orderBy('id')->get();
return view('scoreboard', [
'teams' => $teams,
'missions' => $missions
]);
}
}

+ 109
- 0
app/Mission.php View File

@ -12,4 +12,113 @@ class Mission extends Model
public function tweets() {
return $this->hasMany('App\Tweet');
}
private function unique_transit_lines(Team $team) {
static $cache = [];
if(array_key_exists($team->id, $cache))
return $cache[$team->id];
$tweets = Tweet::where('team_id', $team->id)->where('m1_complete', 1)->get();
$lines = [];
foreach($tweets as $tweet) {
if($tweet->m1_transit_line_id && !in_array($tweet->m1_transit_line_id, $lines)) {
$lines[] = $tweet->m1_transit_line_id;
}
}
$cache[$team->id] = count($lines);
return count($lines);
}
private function unique_transit_centers(Team $team) {
static $cache = [];
if(array_key_exists($team->id, $cache))
return $cache[$team->id];
$tweets = Tweet::where('team_id', $team->id)->where('m2_complete', 1)->get();
$centers = [];
foreach($tweets as $tweet) {
if($tweet->m2_transit_center_id && !in_array($tweet->m2_transit_center_id, $centers)) {
$centers[] = $tweet->m2_transit_center_id;
}
}
$cache[$team->id] = count($centers);
return count($centers);
}
private function unique_documents(Team $team) {
static $cache = [];
if(array_key_exists($team->id, $cache))
return $cache[$team->id];
$tweets = Tweet::where('team_id', $team->id)->whereNotNull('m7_document_id')->get();
$documents = [];
foreach($tweets as $tweet) {
if($tweet->m7_document_id && !in_array($tweet->m7_document_id, $documents)) {
$documents[] = $tweet->m7_document_id;
}
}
$cache[$team->id] = count($documents);
return count($documents);
}
private function num_tweets_for_mission(Team $team, $m) {
static $cache = [3=>[], 4=>[], 5=>[], 6=>[]];
if(array_key_exists($team->id, $cache[$m]))
return $cache[$m][$team->id];
$num = Tweet::where('team_id', $team->id)->where('m'.$m.'_complete', 1)->count();
$cache[$m][$team->id] = $num;
return $num;
}
public function complete(Team $team) {
switch($this->id) {
case 1:
// 5 unique transit lines
return $this->unique_transit_lines($team) >= 5;
case 2:
// 3 unique transit centers
return $this->unique_transit_centers($team) >= 3;
case 3:
case 4:
case 5:
case 6:
return $this->num_tweets_for_mission($team, $this->id) >= 1;
case 7:
return $this->unique_documents($team) >= 3;
}
}
public function progress(Team $team) {
switch($this->id) {
case 1:
return [$this->unique_transit_lines($team), 5];
case 2:
return [$this->unique_transit_lines($team), 3];
case 3:
case 4:
case 5:
case 6:
return [$this->num_tweets_for_mission($team, $this->id), 1];
case 7:
return [$this->unique_documents($team), 3];
}
return [false,false];
}
public function score(Team $team) {
switch($this->id) {
case 1:
break;
case 2:
break;
}
}
}

+ 5
- 3
public/js/app.js View File

@ -47310,25 +47310,27 @@ module.exports = {
switch (this.tweet.mission_id) {
case 1:
score_data['m1_complete'] = 1;
score_data['m1_transit_line_id'] = this.selectedTransitLine;
score_data['m1_non_trimet'] = this.selectedNonTrimetLine;
break;
case 2:
score_data['m2_complete'] = this.selectedTransitCenter ? 1 : 0;
score_data['m2_transit_center_id'] = this.selectedTransitCenter;
score_data['m2_with_other_team'] = this.selectedPhotoHasAnotherTeam ? 1 : 0;
break;
case 3:
score_data['m3_complete'] = true ? 1 : 0;
score_data['m3_complete'] = 1;
break;
case 4:
score_data['m4_complete'] = true ? 1 : 0;
score_data['m4_complete'] = 1;
break;
case 5:
score_data['m5_complete'] = this.selectedM5Singing ? 1 : 0;
score_data['m5_tip'] = this.selectedM5Tipping ? 1 : 0;
break;
case 6:
score_data['m6_complete'] = true ? 1 : 0;
score_data['m6_complete'] = 1;
break;
case 7:
score_data['m7_document_id'] = this.selectedDocument;

+ 3
- 1
resources/views/layouts/app.blade.php View File

@ -36,7 +36,9 @@
<div class="collapse navbar-collapse" id="app-navbar-collapse">
<!-- Left Side Of Navbar -->
<ul class="nav navbar-nav">
<li><a href="{{ route('dashboard') }}">Dashboard</a></li>
@if(!Auth::guest())
<li><a href="{{ route('dashboard') }}">Dashboard</a></li>
@endif
@can('admin')
<li><a href="{{ route('teams') }}">Teams</a></li>
@endcan

+ 48
- 0
resources/views/scoreboard.blade.php View File

@ -0,0 +1,48 @@
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-12">
<table class="table table-bordered">
<thead>
<tr>
<th>Team</th>
@foreach($missions as $mission)
<th>
<h3>{{ $mission->id }}</h3>
{{ $mission->hashtag }}
</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach($teams as $team)
<tr>
<td>
<div class="team">
<span class="team-icon" style="background-color: #{{ $team->color }};"></span>
<span class="team-name">{{ $team->name }}</span>
</div>
<div class="players">
@foreach($team->players as $player)
<a href="https://twitter.com/{{ $player->twitter }}">{{ '@'.$player->twitter }}</a>
@endforeach
</div>
</td>
@foreach($missions as $mission)
<td>
<div>{{ $mission->complete($team) ? 'Complete' : '' }}</div>
<div>{{ $mission->progress($team)[0].'/'.$mission->progress($team)[1] }}</div>
</td>
@endforeach
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
@endsection

Loading…
Cancel
Save