From 706a4b28a0a029ce19a543ad313d364a5eb4434f Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Mon, 3 Jul 2017 21:08:16 -0700 Subject: [PATCH] finish scoring rules! --- app/Mission.php | 61 ++++++++++++++++++++++------ resources/views/scoreboard.blade.php | 10 +++-- 2 files changed, 56 insertions(+), 15 deletions(-) diff --git a/app/Mission.php b/app/Mission.php index 876e021..6e29f46 100644 --- a/app/Mission.php +++ b/app/Mission.php @@ -2,6 +2,7 @@ namespace App; use Illuminate\Database\Eloquent\Model; +use Log, DB; class Mission extends Model { @@ -32,21 +33,24 @@ class Mission extends Model 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) { 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); + $cache[$with_another_team?'with':'without'][$team->id] = count($centers); return count($centers); } @@ -119,9 +123,9 @@ class Mission extends Model if($this->complete($team)) { $score = 50; // 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 = []; - foreach($tweet as $tweet) { + foreach($tweets as $tweet) { if(!in_array($tweet->m1_non_trimet, $lines)) { $lines[] = $tweet->m1_non_trimet; } @@ -136,12 +140,45 @@ class Mission extends Model // No points unless they hit 3 transit centers if($this->complete($team)) { $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 { return 0; } diff --git a/resources/views/scoreboard.blade.php b/resources/views/scoreboard.blade.php index 6191de8..4821b16 100644 --- a/resources/views/scoreboard.blade.php +++ b/resources/views/scoreboard.blade.php @@ -34,9 +34,13 @@ @foreach($missions as $mission) -
{{ $mission->score($team) }}
-
{{ $mission->complete($team) ? 'Complete' : '' }}
-
{{ $mission->progress($team)[0].'/'.$mission->progress($team)[1] }}
+ @if(Auth::guest()) +
{{ $mission->complete($team) ? 'Complete' : '' }}
+ @else +
{{ $mission->score($team) }}
+
{{ $mission->complete($team) ? 'Complete' : '' }}
+
{{ $mission->progress($team)[0].'/'.$mission->progress($team)[1] }}
+ @endif @endforeach