angular.module("myApp").factory('athletes', ['average', '$http', '$q', function(average, $http, $q) {

  var getAthletes = function () {
    var deferred = $q.defer();
    $http.get('athletes.json').then(function(response) {
      var athletes = response.data;
      angular.forEach(athletes, function(obj){
        obj.time=new Date("1970-01-01T"+obj.time);
        obj.average = average(obj.time);
      });
      deferred.resolve(athletes);
    });
    return deferred.promise;
  };

  return {
    getAthletes: getAthletes
  };
}]);
