javascript - i have these two api's and I made a table where I showed all the matches being played from 2015 till 2017 in EPL league -
var app = angular.module("myapp",['ngroute','angularutils.directives.dirpagination']); /* * match controller * -------- * --------- * ------- * */ app.controller("allmatchescontroller",['$scope', '$http',function($scope,$http){ var main= this; $scope.orderbyfield = 'name'; $scope.reversesort = false; this.name = []; this.matches = []; //var year = this.year; this.years = [2015,2016,2017]; this.getallmatches = function() { $http({ method: 'get', url: 'https://raw.githubusercontent.com/openfootball/football.json/master/2015-16/en.1.json' }).then(function successcallback(response) { var data = response.data; var rounds = data.rounds; //console.log(data); //console.log(rounds); angular.foreach(rounds, function (match) { main.matches = main.matches.concat(match.matches); main.name = main.name.concat(match.name); }) }); $http({ method: 'get', url: 'https://raw.githubusercontent.com/openfootball/football.json/master/2016-17/en.1.json' }).then(function successcallback(response) { var data = response.data; var rounds = data.rounds; //console.log(data); //console.log(rounds); rounds.foreach(function (match) { main.matches = main.matches.concat(match.matches); main.name = name.concat(match.name); //year = moment(match.date, "yyyy-mm-dd"); }); //console.log(main.matches); }) }; function errorcallback(response){ } this.getallmatches(); }]); /* single match controller----------- * ------------------- * --------------- * ----------- * -------------- * ----------- * -------- * */ app.controller("matchcontroller",[ '$http', '$routeparams' , function($http, $routeparams){ var matchdate = $routeparams.matchdate; var team1 = $routeparams.team1; var team2 = $routeparams.team2; var main = this; console.log($routeparams.matchdate); console.log($routeparams.team1); console.log($routeparams.team2); this.matches = []; this.show = {}; this.getallmatches = function() { $http({ method: 'get', url: 'https://raw.githubusercontent.com/openfootball/football.json/master/2015-16/en.1.json' }).then(function successcallback(response) { var data = response.data; var rounds = data.rounds; //console.log(data); //console.log(rounds); angular.foreach(rounds, function (match) { main.matches = main.matches.concat(match.matches); }) }); $http({ method: 'get', url: 'https://raw.githubusercontent.com/openfootball/football.json/master/2016-17/en.1.json' }).then(function successcallback(response) { var data = response.data; var rounds = data.rounds; //console.log(data); //console.log(rounds); rounds.foreach(function (match) { main.matches = main.matches.concat(match.matches); //year = moment(match.date, "yyyy-mm-dd"); }); console.log(main.matches); angular.foreach(main.matches, function(matched){ if(matched.date === matchdate && matched.team1.name === team1 && matched.team2.name === team2){ main.show.team1 = matched.team1.name; main.show.team2 = matched.team2.name; main.show.score1 = matched.score1; main.show.score2 = matched.score2; main.show.date = matched.date; if(matched.score1>matched.score2) {main.show.winner = matched.team1.name} else if(matched.score1<matched.score2){ main.show.winner = matched.team2.name; } else{ main.show.winner = "none match draw !"; } } }) }) }; function errorcallback(response){ } this.getallmatches(); console.log(main.matches); }]); /* * team stats controller * ------- * -------- * ------ * ------- * */ app.controller("statscontroller",[ '$http', function($http){ var main = this; this.matches = []; this.teams=[]; this.teamstats = {}; this.show = {}; var count = 0; this.getallmatches = function() { $http({ method: 'get', url: 'https://raw.githubusercontent.com/openfootball/football.json/master/2015-16/en.1.json' }).then(function successcallback(response) { var data = response.data; var rounds = data.rounds; //console.log(data); //console.log(rounds); angular.foreach(rounds, function (match) { main.matches = main.matches.concat(match.matches); }) }); $http({ method: 'get', url: 'https://raw.githubusercontent.com/openfootball/football.json/master/2016-17/en.1.json' }).then(function successcallback(response) { var data = response.data; var rounds = data.rounds; //console.log(data); //console.log(rounds); rounds.foreach(function (match) { main.matches = main.matches.concat(match.matches); //year = moment(match.date, "yyyy-mm-dd"); }); //console.log(main.matches); angular.foreach(main.matches, function(match){ if(main.teams.indexof(match.team1.name) === -1) { main.teams.push(match.team1.name); } if(main.teams.indexof(match.team2.name) === -1) { main.teams.push(match.team2.name); } main.teams.foreach(function(team) { console.log(match.team1.name, team); //console.log(team); if(team == match.team1.name){ console.log(team); count++; main.teamstats.team = { teamname : main.teamstats.team, count: count } } }) }); console.log(main.teamstats); //console.log(main.teams); }); }; function errorcallback(response){ } this.getallmatches(); console.log(main.matches); /* main.teams.foreach(function(team) { console.log(match.team1.name, team); angular.foreach(main.matches, function (match) { //console.log(team); if (team === match.team1.name) { console.log(team); count++; main.teamstats.team = { teamname: main.teamstats.team, count: count } } }) });*/ console.log(main.teamstats); }]);
these 2 api's json data coming.
https://raw.githubusercontent.com/openfootball/football.json/master/2015-16/en.1.json
https://raw.githubusercontent.com/openfootball/football.json/master/2016-17/en.1.json
now, want calculate how many matches each team played , how many won ,it lost , on. kind of stuck there. idea should ?
this tried yet, if condition not working supposed check if name of team in teams array matched name in json incremment count 1 instead getting incremented matches whether or not particular team played it. btw angular 1.
Comments
Post a Comment