angular.module("gameReport", ['mixpanelAPI', 'ngSanitize','errorStatusCheck', 'reportSettings','ngCsv']) .filter('directionality', function() { return function(items, metricDirectionality) { if (metricDirectionality == 'positive') { return items; } if (metricDirectionality == 'negative') { return items.slice().reverse(); } }; }) .directive('gameReport', function() { return { restrict: 'E', replace: true, scope: { slId: '=', game: '=', apiEndpoint: '=', metricSetDefinitionName: '=', metricSetDefinitions: '=', playerInfo: '=', isPlayerViewable: '&', goToPlayerCard: '&' }, templateUrl: 'views/gameReport.html', controller: function ($scope, $timeout, $http, $sce, mixpanelAPI,errorStatusCheck,$filter) { $scope.blurMe = function ($event) { $event.target.blur(); } $scope.decorateDetailsWithReportContext = function (detailsObject) { detailsObject.reportType = "pregame"; detailsObject.dataScope = $scope.gameScope; if ($scope.gameScope == 'since') { detailsObject.sinceDate = $scope.displayDate; } detailsObject.activeMetricsGroup = $scope.activeGroup; detailsObject.manpowerSituation = $scope.manpowerSituation; detailsObject.periodType = $scope.periodType; detailsObject.granularity = $scope.granularity; return detailsObject; } $scope.decoracteDetailsWithRankingContext = function (detailsObject) { detailsObject.rankinggrouping = $scope.ranking.grouping.name; detailsObject.rankingmetric = $scope.ranking.metric.definition; detailsObject.rankingprimaryPosition = $scope.ranking.primaryPosition.name; if ($scope.ranking.grouping.name == 'team') { detailsObject.highlightTeamId = $scope.ranking.highlightTarget.id; detailsObject.highlightTeamLocation = $scope.ranking.highlightTarget.location; detailsObject.highlightTeamName = $scope.ranking.highlightTarget.name; detailsObject.highlightTeamShorthand = $scope.ranking.highlightTarget.shorthand; } else if ($scope.ranking.grouping.name == 'player') { detailsObject.highlightPlayerId = $scope.ranking.highlightTarget.playerid; detailsObject.highlightPlayerFullname = $scope.ranking.highlightTarget.playerfirstname + " " + $scope.ranking.highlightTarget.playerlastname; detailsObject.highlightPlayerPosition = $scope.ranking.highlightTarget.playerposition; detailsObject.highlightPlayerPrimaryPosition = $scope.ranking.highlightTarget.playerprimaryposition; detailsObject.highlightPlayerJerseynum = $scope.ranking.highlightTarget.playerjerseynumber; } return detailsObject; } $scope.openGameReport = function(reportScope) { $scope.$apply(); $scope.metricSetDefinition = $scope.metricSetDefinitions[$scope.metricSetDefinitionName]; if (typeof $scope.game.metrics === "undefined") { $scope.game.metrics = {}; } if (typeof $scope.game.metrics[$scope.metricSetDefinitionName] === "undefined") { $scope.game.metrics[$scope.metricSetDefinitionName] = { preseason: { per20: { all: {}, evenStrength: {}, powerPlay: {}, shortHanded: {} }, Game: { all: {}, evenStrength: {}, powerPlay: {}, shortHanded: {} }, total:{ all: {}, evenStrength: {}, powerPlay: {}, shortHanded: {} } }, season: { per20: { all: {}, evenStrength: {}, powerPlay: {}, shortHanded: {} }, Game: { all: {}, evenStrength: {}, powerPlay: {}, shortHanded: {} }, total:{ all: {}, evenStrength: {}, powerPlay: {}, shortHanded: {} } }, last10games: { per20: { all: {}, evenStrength: {}, powerPlay: {}, shortHanded: {} }, Game: { all: {}, evenStrength: {}, powerPlay: {}, shortHanded: {} }, total:{ all: {}, evenStrength: {}, powerPlay: {}, shortHanded: {} } }, game: { per20: { all: {}, evenStrength: {}, powerPlay: {}, shortHanded: {} }, Game: { all: {}, evenStrength: {}, powerPlay: {}, shortHanded: {} },total:{ all: {}, evenStrength: {}, powerPlay: {}, shortHanded: {} } }, gameraw: { per20: { all: {}, evenStrength: {}, powerPlay: {}, shortHanded: {} }, Game: { all: {}, evenStrength: {}, powerPlay: {}, shortHanded: {} }, total:{ all: {}, evenStrength: {}, powerPlay: {}, shortHanded: {} } }, previousgame: { per20: { all: {}, evenStrength: {}, powerPlay: {}, shortHanded: {} }, Game: { all: {}, evenStrength: {}, powerPlay: {}, shortHanded: {} }, total:{ all: {}, evenStrength: {}, powerPlay: {}, shortHanded: {} } }, since:{ per20: { all: {}, evenStrength: {}, powerPlay: {}, shortHanded: {} }, Game: { all: {}, evenStrength: {}, powerPlay: {}, shortHanded: {} }, total:{ all: {}, evenStrength: {}, powerPlay: {}, shortHanded: {} } } }; } $scope.showLeagueRanking = false; $scope.showPreviousGameOpponents = false; $scope.sinceDate; $scope.displayDate=null; $scope.fetchingData = false; $scope.fetchRequestId = 0; $scope.metricsMenuReady = false; $scope.olddate; $scope.editMode = {editorMouseOverSummary : [false, false, false], on : [false, false, false]}; $scope.editMode.editedMarkdown = []; $scope.manpowerSituation = 'all'; $scope.periodType = 'all'; $scope.granularity = 'Game'; $scope.previousGames = null; $scope.currentData = null; $scope.headerCsv=[] $scope.baseMetricListCsv=null; var teamMetricsCalculatorCsv=function(tempBaseMetrics,teamMetricsType,teamType){ var countCsv=5; var playerMetricCsvObject={}; if(teamMetricsType=='overall'){ playerMetricCsvObject[0]='All'; playerMetricCsvObject[2]='All Players'; } else { if (teamMetricsType=='F'){ playerMetricCsvObject[2]='All Forwards'; } if (teamMetricsType=='D'){ playerMetricCsvObject[2]='All Defensemen'; } playerMetricCsvObject[0]=teamMetricsType; } playerMetricCsvObject[1]='-'; playerMetricCsvObject[3]='-'; playerMetricCsvObject[4]=teamType.shorthand; Object.keys(tempBaseMetrics).forEach(function(allplayers) { playerMetricCsvObject[countCsv]=$filter('formatMetricValue')($scope.getTeamMetricValue(tempBaseMetrics[allplayers], teamType.id ,teamMetricsType),$scope.metricTypeForFormat(tempBaseMetrics[allplayers])); countCsv++; }); return playerMetricCsvObject } sortingOfPlayers=function(playerArray){ playerArray.sort(function(a, b) { var lastname1= a[2].split(' ')[1].toLowerCase(); var lastname2=b[2].split(' ')[1].toLowerCase(); return lastname1.localeCompare(lastname2) || 0; }); } $scope.getArray = function() { resultArray=[]; alphabet = 'abcdefghijklmnopqrstuvwxyz'.split(''); var headers=$scope.setBaseMetricForCsv($scope.activeGroup); var tempBaseMetrics=$scope.baseMetricListCsv; var playerdata=$scope.currentData.players; $scope.game.visitors.id $scope.game.home.id var gameScopeCsv=($scope.gameScope==='since' ) ? $scope.gameScope +'-'+ $scope.displayDate : $scope.gameScope; playerMetricCsvObject={}; playerMetricCsvObject[0]='date: ' + $scope.game.date; playerMetricCsvObject[1]='visitors: ' + $scope.game.visitors.shorthand; playerMetricCsvObject[2]='home: ' + $scope.game.home.shorthand; playerMetricCsvObject[3]='scope: ' + gameScopeCsv; playerMetricCsvObject[4]='manpower situation: ' + $scope.manpowerSituation; playerMetricCsvObject[5]='periods : ' + $scope.periodType; playerMetricCsvObject[6]='averaging : ' + $scope.granularity; resultArray.push(playerMetricCsvObject); resultArray.push(headers); resultArray.push(teamMetricsCalculatorCsv(tempBaseMetrics,'overall',$scope.game.visitors )); resultArray.push(teamMetricsCalculatorCsv(tempBaseMetrics,'overall',$scope.game.home )); resultArray.push(teamMetricsCalculatorCsv(tempBaseMetrics,'F',$scope.game.visitors)); resultArray.push(teamMetricsCalculatorCsv(tempBaseMetrics,'F',$scope.game.home )); resultArray.push(teamMetricsCalculatorCsv(tempBaseMetrics,'D',$scope.game.visitors )); resultArray.push(teamMetricsCalculatorCsv(tempBaseMetrics,'D',$scope.game.home)); tempPositionObjectHome={'D':[],'F':[],'G':[]}; tempPositionObjectVisistors={'D':[],'F':[],'G':[]}; Object.keys(playerdata).forEach(function(key1) { var countCsv=5; var playerMetricCsvObject={}; playerMetricCsvObject[0]=playerdata[key1].playerprimaryposition; playerMetricCsvObject[1]=playerdata[key1].playerjerseynumber; playerMetricCsvObject[2]=playerdata[key1].playerfirstname + " "+ playerdata[key1].playerlastname; if (!isNaN(playerdata[key1].secondsplayed)){ headers[3]='Minutes'; // var minuteValue = Math.floor(playerdata[key1].secondsplayed / 60) + "."; var minuteValue= (playerdata[key1].secondsplayed /60).toFixed(3); playerMetricCsvObject[3]=minuteValue } else if (playerdata[key1].gamesplayed){ headers[3]='Games'; playerMetricCsvObject[3]=playerdata[key1].gamesplayed; } playerMetricCsvObject[4]=playerdata[key1].teamshorthand; Object.keys(tempBaseMetrics).forEach(function(key2) { //var tempValue=$scope.getPlayerMetricValue(tempBaseMetrics[key2], playerdata[key1]); var tempValue=$filter('formatMetricValue')($scope.getPlayerMetricValue(tempBaseMetrics[key2], playerdata[key1]), $scope.metricTypeForFormat(tempBaseMetrics[key2])); playerMetricCsvObject[countCsv]=isNaN(tempValue) ? tempValue:tempValue; countCsv++; }); if(playerdata[key1].teamshorthand==$scope.game.home.shorthand){ tempPositionObjectHome[playerdata[key1].playerprimaryposition].push(playerMetricCsvObject); } if(playerdata[key1].teamshorthand==$scope.game.visitors.shorthand){ tempPositionObjectVisistors[playerdata[key1].playerprimaryposition].push(playerMetricCsvObject); } }); sortingOfPlayers(tempPositionObjectVisistors['D']); sortingOfPlayers(tempPositionObjectVisistors['F']); sortingOfPlayers(tempPositionObjectVisistors['G']); sortingOfPlayers(tempPositionObjectHome['D']); sortingOfPlayers(tempPositionObjectHome['F']); sortingOfPlayers(tempPositionObjectHome['G']); resultArray.push.apply(resultArray,tempPositionObjectVisistors['D']); resultArray.push.apply(resultArray,tempPositionObjectVisistors['F']); resultArray.push.apply(resultArray,tempPositionObjectVisistors['G']); resultArray.push.apply(resultArray,tempPositionObjectHome['D']); resultArray.push.apply(resultArray,tempPositionObjectHome['F']); resultArray.push.apply(resultArray,tempPositionObjectHome['G']); mixpanelAPI.send('exportCsv', mixpanelAPI.decorateDetailsWithGameInfo( $scope.decorateDetailsWithReportContext({}), $scope.game )); $scope.fileNameExportCsv = $scope.game.date + $scope.game.visitors.shorthand +'vs'+ $scope.game.home.shorthand +'-'+ $scope.activeGroup +'.csv'; return resultArray; } $scope.getHeaderCsv=function(){ return $scope.headerCsv; } $scope.getGameNotes(); $scope.setGameScope(reportScope); if (reportScope == 'season') { $http.get($scope.apiEndpoint + 'games/' + $scope.game.id + '/previousgames') .success(function (data) { $scope.previousGames = data; }) .error(function (data,status) { var message='Could not get previous games for game ' + $scope.game.id; errorStatusCheck.checkErrorStatus(data,status,message); }); } }; $scope.$on('openPregameReport', function(e) { $scope.openGameReport('season'); }); $scope.$on('openPostgameReport', function(e) { $scope.openGameReport('game'); }); $scope.$on('openInGameReport', function(e) { $scope.openGameReport('gameraw'); }); $scope.getTeamMetricValue = function (metric, teamId, teamScope) { var returnValue = '-'; var baseSet = $scope.currentData.teams[teamId]; if (metric.type != 'noncumulativeduration' || $scope.granularity != 'Game') { if (metric.scope == 'opposingteam') { baseSet = $scope.currentData.opposingteams[teamId]; } if (teamScope == 'overall') { baseSet = baseSet.overall; } else if (metric.scope != 'team') { baseSet = baseSet.primarypositions[teamScope]; } if (typeof baseSet[metric.definition] !== 'undefined') { returnValue = baseSet[metric.definition]; } } return returnValue; } $scope.getPlayerMetricValue = function (metric, playerdata) { var returnValue = '-'; if (metric.scope != 'opposingteam' && metric.scope != 'team') { returnValue = playerdata[metric.definition]; } return returnValue; } $scope.getGameNotes = function () { $scope.gameNotes = null; $http.get($scope.apiEndpoint + 'games/' + $scope.game.id + '/notes') .success(function (data) { if (typeof data.notes !== 'undefined' && ((typeof data.notes.pregame1 !== 'undefined' && data.notes.pregame1 !== '') || (typeof data.notes.pregame2 !== 'undefined' && data.notes.pregame2 !== '') || (typeof data.notes.pregame3 !== 'undefined' && data.notes.pregame3 !== '')) ) { $scope.gameNotes = []; if (typeof data.notes.pregame1 !== 'undefined') { $scope.gameNotes.push(data.notes.pregame1); } else { $scope.gameNotes.push(""); } if (typeof data.notes.pregame2 !== 'undefined') { $scope.gameNotes.push(data.notes.pregame2); } else { $scope.gameNotes.push(""); } if (typeof data.notes.pregame3 !== 'undefined') { $scope.gameNotes.push(data.notes.pregame3); } else { $scope.gameNotes.push(""); } $scope.gameNotesHtml = [$sce.trustAsHtml(markdown.toHTML($scope.gameNotes[0])), $sce.trustAsHtml(markdown.toHTML($scope.gameNotes[1])), $sce.trustAsHtml(markdown.toHTML($scope.gameNotes[2]))]; $scope.setActiveGroup('summary'); } else { $scope.setActiveGroup($scope.metricSetDefinition.metricGroups[0].class); } $scope.metricsMenuReady = true; }) .error(function () { alert('Could not get summary statistics for game ' + $scope.game.id); $scope.metricsMenuReady = true; $scope.setActiveGroup($scope.metricSetDefinition.metricGroups[0].class); }); } Calendar.setup({ dateField : 'date', dateFormat: '%Y-%m-%d', triggerElement : 'calendarButton', selectHandler:function(date){ $scope.displayDate = date.date.print(this.dateFormat); if ($scope.olddate!=$scope.displayDate&&$scope.game.date >$scope.displayDate) { $scope.sinceDate = date.date; $scope.currentData = null; $scope.fetchingData = true; $scope.fetchRequestId++; $scope.game.metrics[$scope.metricSetDefinitionName]['since'][$scope.granularity][$scope.manpowerSituation][$scope.periodType] = undefined; $scope.olddate= $scope.displayDate; $scope.setGameScope('since'); } } }); $scope.showDate=function(){ if($scope.gameScope=='since'){ return true; } }; $scope.setGameScope = function (gameScope) { $scope.gameScope = gameScope; if (gameScope=='previousgame' || gameScope=='game' || gameScope=='gameraw'){ $scope.setGranularity('total') if(gameScope=='game' || gameScope=='gameraw'){ $scope.postGameScope='total'; } } if($scope.gameScope!='since'){ $scope.olddate=null; $scope.sinceDate=null; } if (typeof $scope.game.metrics[$scope.metricSetDefinitionName][gameScope][$scope.granularity][$scope.manpowerSituation][$scope.periodType] === "undefined") { $scope.currentData = null; $scope.fetchingData = true; $scope.fetchRequestId++; var myRequestId = $scope.fetchRequestId; $http.get($scope.apiEndpoint + 'games/' + $scope.game.id + '/metricsets/' + $scope.metricSetDefinitionName + '/' + $scope.gameScope + '/' + $scope.manpowerSituation + '/' + $scope.periodType + '/' + $scope.granularity + '?sinceDate='+ $scope.displayDate) .success(function (data,config) { if ($scope.fetchRequestId == myRequestId) { $scope.game.metrics[$scope.metricSetDefinitionName][gameScope][$scope.granularity][$scope.manpowerSituation][$scope.periodType] = data; $scope.currentData = $scope.game.metrics[$scope.metricSetDefinitionName][gameScope][$scope.granularity][$scope.manpowerSituation][$scope.periodType]; $scope.fetchingData = false; $scope.fetchRequestId = 0; } }) .error(function (data,status) { var message='Could not get ' + gameScope + ' report metrics for game ' + $scope.game.id; errorStatusCheck.checkErrorStatus(data,status,message); if ($scope.fetchRequestId == myRequestId) { $scope.fetchingData = false; $scope.fetchRequestId = 0; } }); } else { $scope.currentData = $scope.game.metrics[$scope.metricSetDefinitionName][gameScope][$scope.granularity][$scope.manpowerSituation][$scope.periodType]; } if (gameScope == 'previousgame') { $scope.showPreviousGameOpponents = true; } else { $scope.showPreviousGameOpponents = false; } mixpanelAPI.send('setGameScope', mixpanelAPI.decorateDetailsWithGameInfo( $scope.decorateDetailsWithReportContext({}), $scope.game )); } $scope.setManpowerSituation = function (manpowerSituation) { $scope.manpowerSituation = manpowerSituation; if (typeof $scope.game.metrics[$scope.metricSetDefinitionName][$scope.gameScope][$scope.granularity][manpowerSituation][$scope.periodType] === "undefined") { $scope.currentData = null; $scope.fetchingData = true; $scope.fetchRequestId++; var myRequestId = $scope.fetchRequestId; $http.get($scope.apiEndpoint + 'games/' + $scope.game.id + '/metricsets/' + $scope.metricSetDefinitionName + '/' + $scope.gameScope + '/' + $scope.manpowerSituation + '/' + $scope.periodType + '/' + $scope.granularity + '?sinceDate='+ $scope.displayDate) .success(function (data) { if ($scope.fetchRequestId == myRequestId) { $scope.game.metrics[$scope.metricSetDefinitionName][$scope.gameScope][$scope.granularity][manpowerSituation][$scope.periodType] = data; $scope.currentData = $scope.game.metrics[$scope.metricSetDefinitionName][$scope.gameScope][$scope.granularity][manpowerSituation][$scope.periodType]; $scope.fetchingData = false; $scope.fetchRequestId = 0; } }) .error(function (data,status) { if ($scope.fetchRequestId == myRequestId) { $scope.fetchingData = false; $scope.fetchRequestId = 0; } var message='Could not get ' + manpowerSituation + ' report metrics for game ' + $scope.game.id; errorStatusCheck.checkErrorStatus(data,status,message); }); } else { $scope.currentData = $scope.game.metrics[$scope.metricSetDefinitionName][$scope.gameScope][$scope.granularity][manpowerSituation][$scope.periodType]; } mixpanelAPI.send('setManpowerSituation', mixpanelAPI.decorateDetailsWithGameInfo( $scope.decorateDetailsWithReportContext({}), $scope.game )); } $scope.setPeriodType = function (periodType) { $scope.periodType = periodType; if (typeof $scope.game.metrics[$scope.metricSetDefinitionName][$scope.gameScope][$scope.granularity][$scope.manpowerSituation][periodType] === "undefined") { $scope.currentData = null; $scope.fetchingData = true; $scope.fetchRequestId++; var myRequestId = $scope.fetchRequestId; $http.get($scope.apiEndpoint + 'games/' + $scope.game.id + '/metricsets/' + $scope.metricSetDefinitionName + '/' + $scope.gameScope + '/' + $scope.manpowerSituation + '/' + $scope.periodType + '/' + $scope.granularity + '?sinceDate='+ $scope.displayDate) .success(function (data) { if ($scope.fetchRequestId == myRequestId) { $scope.game.metrics[$scope.metricSetDefinitionName][$scope.gameScope][$scope.granularity][$scope.manpowerSituation][periodType] = data; $scope.currentData = $scope.game.metrics[$scope.metricSetDefinitionName][$scope.gameScope][$scope.granularity][$scope.manpowerSituation][periodType]; $scope.fetchingData = false; $scope.fetchRequestId = 0; } }) .error(function (data,status) { if ($scope.fetchRequestId == myRequestId) { $scope.fetchingData = false; $scope.fetchRequestId = 0; } var message ='Could not get ' + periodType + ' report metrics for game ' + $scope.game.id; errorStatusCheck.checkErrorStatus(data,status,message); }); } else { $scope.currentData = $scope.game.metrics[$scope.metricSetDefinitionName][$scope.gameScope][$scope.granularity][$scope.manpowerSituation][periodType]; } mixpanelAPI.send('setPeriodType', mixpanelAPI.decorateDetailsWithGameInfo( $scope.decorateDetailsWithReportContext({}), $scope.game)); } $scope.setGranularity = function (granularity) { $scope.granularity = granularity; if (typeof $scope.game.metrics[$scope.metricSetDefinitionName][$scope.gameScope][granularity][$scope.manpowerSituation][$scope.periodType] === "undefined") { $scope.currentData = null; $scope.fetchingData = true; $scope.fetchRequestId++; var myRequestId = $scope.fetchRequestId; $http.get($scope.apiEndpoint + 'games/' + $scope.game.id + '/metricsets/' + $scope.metricSetDefinitionName + '/' + $scope.gameScope + '/' + $scope.manpowerSituation + '/' + $scope.periodType + '/' + $scope.granularity + '?sinceDate='+ $scope.displayDate) .success(function (data) { if ($scope.fetchRequestId == myRequestId) { $scope.game.metrics[$scope.metricSetDefinitionName][$scope.gameScope][granularity][$scope.manpowerSituation][$scope.periodType] = data; $scope.currentData = $scope.game.metrics[$scope.metricSetDefinitionName][$scope.gameScope][granularity][$scope.manpowerSituation][$scope.periodType]; $scope.fetchingData = false; $scope.fetchRequestId = 0; } }) .error(function (data,status) { if ($scope.fetchRequestId == myRequestId) { $scope.fetchingData = false; $scope.fetchRequestId = 0; } var message='Could not get ' + granularity + ' report metrics for game ' + $scope.game.id; errorStatusCheck.checkErrorStatus(data,status,message); }); } else { $scope.currentData = $scope.game.metrics[$scope.metricSetDefinitionName][$scope.gameScope][granularity][$scope.manpowerSituation][$scope.periodType]; } mixpanelAPI.send('setGranularity', mixpanelAPI.decorateDetailsWithGameInfo( $scope.decorateDetailsWithReportContext({}), $scope.game )); } $scope.setBaseMetricForCsv=function(groupLabel){ $scope.headerCsv=['Position','Jersey','Name','Games','Team']; var groupArray=$scope.metricSetDefinition.metricGroups; for(i=0;i additionalLevels) { additionalLevels = currentCount; } } baseMetricLevelCount += additionalLevels; } return baseMetricLevelCount; } $scope.getMetricLevelsIndexes = function (group) { var baseMetricLevelCount = $scope.getSubMetricLevelCount(group); var metricLevels = []; for (var i=0 ; i 0) { $scope.getLevelMetricsInternal(level - levelsdiff + 1, metricArray, group.metricGroups[i]); } } } return metricArray; } $scope.getBaseMetricsList = function (group, metricsList) { if (typeof metricsList === "undefined") { var metricsList = []; } if (typeof group.metrics !== 'undefined') { for (var i=0; i= index) { if ((currentOffset - 1) > index) { isLast = false; } break; } } } return isLast; } $scope.isHeaderLastColumn = function (group, subgroup, level) { var isLast = true; if (level >= $scope.getSubMetricLevelCount(group) - 1) { metrics = $scope.getBaseMetricsList(group); for (var i=0; i 30))) { // if the time difference is more than 30 days, filter out players that do not have enough time on ice if (($scope.displayDate == null || ($scope.displayDate != null && Math.floor((Date.parse($scope.game.date) - Date.parse($scope.displayDate)) / (1000*60*60*24)) > 30)) && ($scope.granularity == 'per20' || $scope.granularity == 'Game')) { var mins = $scope.rankingsMins[$scope.granularity][$scope.manpowerSituation]; if (typeof mins[$scope.game.league.name] != 'undefined') { var min = mins[$scope.game.league.name]; } else { var min = mins.default; } if (($scope.granularity == 'per20' && playerEntry['secondsplayed'] < min) || ($scope.granularity == 'Game' && playerEntry['gamesplayed'] < min) ) { returnFlag = false; } } } return returnFlag; } } $scope.openLeagueRanking = function (metric, grouping, highlightTarget, primaryPosition) { if (((metric.scope != 'opposingteam' && metric.scope != 'team' ) || grouping == 'team') && (metric.type != 'noncumulativeduration' || grouping == 'player' || $scope.granularity != 'Game')) { if (metric.scope == 'opposingteam' && grouping == 'team') { grouping = 'opposingteam'; } $scope.ranking = { metric : metric, grouping : {name: grouping, label : grouping == 'team' ? 'Team' : grouping == 'opposingteam' ? 'Opposing Team' : 'Player'}, highlightTarget : highlightTarget, currentId : grouping == 'player' ? highlightTarget.playerid : highlightTarget.id, teamMatesOnly : false }; if (typeof primaryPosition !== 'undefined') { $scope.setRankingPrimaryPosition(primaryPosition, true); } else { $scope.setRankingPrimaryPosition('all', true); } var queryUrl = $scope.apiEndpoint + 'leagues/' + $scope.game.league.id + '/rankings/' + $scope.game.season.id + '/metrics/' + $scope.ranking.metric.definition + '/' + $scope.ranking.grouping.name + '/primaryposition/' + $scope.ranking.primaryPosition.name + '/context/' + $scope.manpowerSituation + '/' + $scope.periodType + '/' + $scope.granularity + '?maxDate=' + $scope.game.date; if ($scope.gameScope == 'since') { queryUrl += '&minDate=' + $scope.displayDate; } $scope.showLeagueRankingLoading = true; $http.get(queryUrl) .success(function (data) { $scope.ranking.data = data; $scope.showLeagueRankingLoading = false; }) .error(function (data,status) { var message='Could not get ' + $scope.getReportContextString(true) + ' ' + $scope.ranking.grouping.label + ' ' + $scope.ranking.metric.definition + ' league ranking data'; errorStatusCheck.checkErrorStatus(data,status,message); $scope.showLeagueRankingLoading = false; }); $scope.showLeagueRanking = true; mixpanelAPI.send('openLeagueRanking', mixpanelAPI.decorateDetailsWithGameInfo( $scope.decorateDetailsWithReportContext($scope.decoracteDetailsWithRankingContext({})), $scope.game )); } } $scope.closeLeagueRanking = function () { $scope.showLeagueRanking = false; mixpanelAPI.send('closeLeagueRanking', mixpanelAPI.decorateDetailsWithGameInfo( $scope.decorateDetailsWithReportContext($scope.decoracteDetailsWithRankingContext({})), $scope.game )); $scope.ranking = null; } $scope.iGoToPlayerCard = function (playerId) { $scope.goToPlayerCard()(playerId); } $scope.mouseOverSummaryText = function (noteId) { } $scope.mouseLeaveSummaryText = function (noteId) { } $scope.enterEditMode = function (noteId) { } $scope.exitEditMode = function (noteId, saveData) { } } // end of controller }; // end of directoive factory });