4917 scouting

by Sam Maier

HTML

<script src="https://rawgit.com/Blitzen/Angular-Chronicle/master/chronicle.js"></script>
<div ng-controller="MyCtrl">
  <input ng-model="event" type="text">
      
  <button ng-click="load()">Reload</button>
      <button ng-click="sortByTeam()">Sort by team</button>
      <button ng-click="sortByValue()">Sort by OPR</button>
      <br/>
      <p>Waterloo: 2015onwa </p>
      <p>North Bay: 2015onnb </p>
    <table>
    <tr ng-repeat="result in results | orderBy: sortBy">
        <td>{{result.teamNumber}}</td>
        <td>{{result.val}}</td>
    </tr>
    <table>

</div>

CSS

table, th , td  {
  border: 1px solid grey;
  border-collapse: collapse;
  padding: 5px;
}

JavaScript

var myApp = angular.module('myApp',['Chronicle']);

myApp.controller('MyCtrl', function($scope, Chronicle) {
    $scope.results = [];
    $scope.sortBy = 'teamNumber';
    $scope.sortByTeam = function() {
        if ($scope.sortBy == 'teamNumber'){
            $scope.sortBy = '-teamNumber';
        }
        else if ($scope.sortBy == '-teamNumber'){
            $scope.sortBy = 'teamNumber';            
        }
        else {
            $scope.sortBy = 'teamNumber';           
        }
    }
    $scope.sortByValue = function() {
        if ($scope.sortBy == 'val'){
            $scope.sortBy = '-val';
        }
        else if ($scope.sortBy == '-val'){
            $scope.sortBy = 'val';            
        }
        else {
            $scope.sortBy = 'val';        
        }
    }
    $scope.event = "2015onnb";
    $scope.load = function loadXMLDoc()
    {
        var xmlhttp;
        xmlhttp=new XMLHttpRequest();
        xmlhttp.onreadystatechange=function(){
            $scope.results = [];
            test =JSON.parse(xmlhttp.responseText);
            angular.forEach(test.oprs, function(value, key) {
                $scope.results.push({teamNumber: parseInt(key), val: parseFloat(value)});
            });
            $scope.$apply();
        }
        xmlhttp.open("GET","http://www.thebluealliance.com/api/v2/event/"+$scope.event+"/stats?X-TBA-App-Id=frc4917:scouting-app:1",true);
        xmlhttp.send();
    }
    $scope.load();
});