View Single Post
  #1   Spotlight this post!  
Unread 11-04-2008, 17:51
SamC SamC is offline
.
AKA: Sam Couch
FRC #0103 (Cybersonics)
Team Role: Programmer
 
Join Date: Mar 2006
Rookie Year: 2006
Location: Philadelphia, PA
Posts: 583
SamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond repute
[TBA]: Team Scoring Data Function

Here is the completed function I have been working on. It asks for 4 parameters.
  • $teamnumber: Any FIRST assigned team number.
  • $year: Any year TheBlueAlliance has data for (2006-present currently).
  • $highscore: Any number you'd like. (explained below)
  • $average: Set to TRUE or FALSE DEFAULT = TRUE(averaged score based on match score and total matches played, or just total points scored for the team's alliance in matches they've played in.)

This function serves two purposes. Basically it outputs an array of data ("score" and "bigmatches").
"Score" is (like said above) Averaged score over the year, or total points scored.
"bigmatches" takes the number set as $highscore and looks at all matches the team has played in. If the teams alliance in each match has a score higher than $highscore the counter goes up 1.

Here's the code:
PHP Code:
function getScoreData($teamnumber$year$highscore$average true)
  {
      
$competitions = array();
      
$matches = array();
      
$post_comps = array();
      
$attendance = array();
      
$bigmatches 0;
      
$event_weeks = array("Pre-Ship""Week 1""Week 2""Week 3""Week 4""Week 5""Week 6");
      
$score 0;
      
$events make_array(get_events(null$yearnull));
      foreach (
$events as $event) {
          if (
in_array($event["week"], $event_weeks)) {
              
$attendance make_array(get_attendance($event["eventid"], $teamnumber));
              if (
count($attendance) > 0) {
                  
$competitions[] = $event["eventid"];
              }
          } else {
              
$post_comps[] = $event["eventid"];
          }
      }
      foreach (
$competitions as $compID) {
          
$matches[] = make_array(get_matches($teamnumber$compID));
      }
      
$record make_array(get_official_record($teamnumbernull$year));
      foreach (
$matches as $match) {
          foreach (
$match as $match) {
              
$matchid $match["matchid"];
              if (
$match["red1"] == $teamnumber || $match["red2"] == $teamnumber || $match["red3"] == $teamnumber) {
                  
$alliance "red";
              } else {
                  
$alliance "blue";
              }
              if (
$alliance == "red") {
                  
$score += $match["redscore"];
                      if(
$match["redscore"] >= $highscore){
                        
$bigmatches++;
                    }
              } else {
                  
$score += $match["bluescore"];
                      if(
$match["bluescore"] >= $highscore){
                        
$bigmatches++;
                    }
              }
          }
      }
      if (
$average) {
          
$average_score round($score $record[0]["sum"], 0);
      } else {
          
$average_score $score;
      }
      
$data = array('score' => $average_score'bigmatches' => $bigmatches);
      return 
$data;
  } 
Here is an example of hows this would work.
PHP Code:
$var getScoreData(330200750); 
echo 
'Average score is:'.$var["score"].'<br />';
echo 
'Matches Over 50 points:'.$var["bigmatches"].'<br />'
Would return,
Average score is: 72
Matches Over 50 points: 22

I will be setting up a live test version on our website sometime soon. Feel free to use it in your own TBA applications.

Thanks to everyone who helped me find those pesky bugs, and help solve them too
Reply With Quote