|
@ -2,6 +2,7 @@ |
|
|
namespace App; |
|
|
namespace App; |
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
|
|
|
use Log, DB; |
|
|
|
|
|
|
|
|
class Mission extends Model |
|
|
class Mission extends Model |
|
|
{ |
|
|
{ |
|
@ -32,21 +33,24 @@ class Mission extends Model |
|
|
return 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]; |
|
|
|
|
|
|
|
|
private function unique_transit_centers(Team $team, $with_another_team=false) { |
|
|
|
|
|
static $cache = ['with'=>[], 'without'=>[]]; |
|
|
|
|
|
if(array_key_exists($team->id, $cache[$with_another_team?'with':'without'])) |
|
|
|
|
|
return $cache[$with_another_team?'with':'without'][$team->id]; |
|
|
|
|
|
|
|
|
$tweets = Tweet::where('team_id', $team->id)->where('m2_complete', 1)->get(); |
|
|
|
|
|
$centers = []; |
|
|
|
|
|
|
|
|
$query = Tweet::where('team_id', $team->id)->where('m2_complete', 1); |
|
|
|
|
|
if($with_another_team) |
|
|
|
|
|
$query = $query->where('m2_with_other_team', 1); |
|
|
|
|
|
$tweets = $query->get(); |
|
|
|
|
|
|
|
|
|
|
|
$centers = []; |
|
|
foreach($tweets as $tweet) { |
|
|
foreach($tweets as $tweet) { |
|
|
if($tweet->m2_transit_center_id && !in_array($tweet->m2_transit_center_id, $centers)) { |
|
|
if($tweet->m2_transit_center_id && !in_array($tweet->m2_transit_center_id, $centers)) { |
|
|
$centers[] = $tweet->m2_transit_center_id; |
|
|
$centers[] = $tweet->m2_transit_center_id; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$cache[$team->id] = count($centers); |
|
|
|
|
|
|
|
|
$cache[$with_another_team?'with':'without'][$team->id] = count($centers); |
|
|
return count($centers); |
|
|
return count($centers); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -119,9 +123,9 @@ class Mission extends Model |
|
|
if($this->complete($team)) { |
|
|
if($this->complete($team)) { |
|
|
$score = 50; |
|
|
$score = 50; |
|
|
// 20 bonus for each line that is not trimet
|
|
|
// 20 bonus for each line that is not trimet
|
|
|
$tweet = Tweet::where('team_id', $team->id)->where('m1_complete', 1)->whereNotNull('m1_non_trimet')->get(); |
|
|
|
|
|
|
|
|
$tweets = Tweet::where('team_id', $team->id)->where('m1_complete', 1)->whereNotNull('m1_non_trimet')->get(); |
|
|
$lines = []; |
|
|
$lines = []; |
|
|
foreach($tweet as $tweet) { |
|
|
|
|
|
|
|
|
foreach($tweets as $tweet) { |
|
|
if(!in_array($tweet->m1_non_trimet, $lines)) { |
|
|
if(!in_array($tweet->m1_non_trimet, $lines)) { |
|
|
$lines[] = $tweet->m1_non_trimet; |
|
|
$lines[] = $tweet->m1_non_trimet; |
|
|
} |
|
|
} |
|
@ -136,12 +140,45 @@ class Mission extends Model |
|
|
// No points unless they hit 3 transit centers
|
|
|
// No points unless they hit 3 transit centers
|
|
|
if($this->complete($team)) { |
|
|
if($this->complete($team)) { |
|
|
$score = 50; |
|
|
$score = 50; |
|
|
// 20 bonus points for any TC with another team
|
|
|
|
|
|
|
|
|
// If they have more than 3 unique transit centers,
|
|
|
|
|
|
// then award bonus points for any beyond the third with another team
|
|
|
|
|
|
$unique_transit_centers = $this->unique_transit_centers($team); |
|
|
|
|
|
if($unique_transit_centers > 3) { |
|
|
|
|
|
// Take the total number of transit centers and subtract 3
|
|
|
|
|
|
$total_possible_bonus = $unique_transit_centers - 3; |
|
|
|
|
|
// Find the number of unique transit centers with another team
|
|
|
|
|
|
$unique_with_another_team = $this->unique_transit_centers($team, true); |
|
|
|
|
|
// Use the smaller of the two numbers as the bonus
|
|
|
|
|
|
$score += 20 * min($total_possible_bonus, $unique_with_another_team); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// ?? Increasing bonus points for additional transit centers
|
|
|
|
|
|
|
|
|
// Increasing bonus points for additional transit centers
|
|
|
|
|
|
if($unique_transit_centers >= 4) { |
|
|
|
|
|
$score += 10; |
|
|
|
|
|
} |
|
|
|
|
|
if($unique_transit_centers >= 5) { |
|
|
|
|
|
$score += 20; |
|
|
|
|
|
} |
|
|
|
|
|
if($unique_transit_centers >= 6) { |
|
|
|
|
|
$score += 30; |
|
|
|
|
|
} |
|
|
|
|
|
if($unique_transit_centers >= 7) { |
|
|
|
|
|
$score += (50 * ($unique_transit_centers - 6)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Triple points for each? transit center that no other team goes to
|
|
|
|
|
|
|
|
|
// Triple points for each transit center that no other team goes to
|
|
|
|
|
|
$this_team_tcs = Tweet::where('team_id', $team->id)->where('m2_complete', 1) |
|
|
|
|
|
->distinct()->pluck('m2_transit_center_id')->toArray(); |
|
|
|
|
|
$other_visited_tcs = Tweet::where('team_id', '!=', $team->id)->where('m2_complete', 1) |
|
|
|
|
|
->distinct()->pluck('m2_transit_center_id')->toArray(); |
|
|
|
|
|
$distinct_tcs = array_diff($this_team_tcs, $other_visited_tcs); |
|
|
|
|
|
|
|
|
|
|
|
Log::info('Team '.$team->name.' visited '.count($distinct_tcs).' TCs that no other team visited, doubling their score'); |
|
|
|
|
|
if(count($distinct_tcs) > 0) { |
|
|
|
|
|
$score *= 2; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $score; |
|
|
} else { |
|
|
} else { |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|