Created
September 12, 2016 15:02
-
-
Save vishwanatharondekar/b78f953aee69ab694f0d21c1ed6c9690 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
angular.module('hotStar.multisportSDKManager', ['hotStar.utils']) | |
.factory('MultiSportManager', ['$filter', '$rootScope', 'Utils', 'Configuration', '$location', '$cookies', '$q', 'BaseConfig', function($filter, $rootScope, utils, configuration, $location, $cookies, $q, baseConfig) { | |
var sdk; | |
var deferred = $q.defer(); | |
var multisportSDK = { | |
initSDK: function() { | |
try { | |
window.asyncSportzSDK = function() { | |
sdk = new SportzSDK(); | |
deferred.resolve(); | |
} | |
var filename = baseConfig.SPORTS_SDK; | |
$.cachedScript(filename); | |
} catch (e) {} | |
}, | |
callSportsSDK: function(methodName, params) { | |
deferred.promise.then(function() { | |
sdk.call("multisport", methodName, params); | |
}); | |
} | |
}; | |
var utility = { | |
hasMatchScores: function(match) { | |
var teams = match.participants; | |
var scoreCount = 0; | |
for (var i = 0; i < teams.length; i++) { | |
var team = teams[i]; | |
if (team && team.value && team.value != "") | |
return true; | |
} | |
return false; | |
}, | |
removeOversFromScore: function(match) { | |
var teams = match.participants; | |
for (var i = teams.length - 1; i >= 0; i--) { | |
var team = teams[i]; | |
var score = team.value; | |
if (score) { | |
var scoreSplits = score.split(' '); | |
for (var j = 0; j < scoreSplits.length; j++) { | |
var scoreElement = scoreSplits[j]; | |
if (scoreElement == "") { | |
scoreSplits.splice(j--, 1); //remove extra spaces | |
} | |
} | |
var lastscorepart = "" | |
if (scoreSplits[scoreSplits.length - 1].charAt(0) == "f") { | |
lastscorepart = scoreSplits[scoreSplits.length - 1]; | |
scoreSplits.splice(scoreSplits.length - 1, 1); | |
} | |
for (var j = 0; j < scoreSplits.length; j++) { | |
var scoreElement = scoreSplits[j]; | |
if (scoreElement.charAt(0) == "(" && scoreElement.charAt(scoreElement.length - 1) == ")" && match.event_format.toLowerCase() == "test") { //remove overs from test matches. keep the overs of the last innings intact | |
if (j != scoreSplits.length - 1) | |
scoreSplits.splice(j--, 1); | |
} | |
} | |
if (lastscorepart != "") | |
scoreSplits.push(lastscorepart); | |
team.value = scoreSplits.join(' '); | |
//Replacing dec with d as per requirement | |
team.value = team.value.replace(/ dec /g, ' d '); | |
team.value = team.value.replace(/ fol /g, ' f/o '); | |
} | |
} | |
}, | |
addAsteriskForBattingTeam: function(match) { | |
var teams = match.participants; | |
var battingTeam = teams.filter(function(team) { | |
return team.highlight == "true"; | |
})[0]; | |
if (battingTeam && match.event_state == "L" && battingTeam.value && battingTeam.value != "" && (!match.result_code || match.result_code == "")) { | |
var battingTeamScore = battingTeam.value; | |
var scoreSplits = battingTeamScore.split(' '); | |
var andIndex = scoreSplits.indexOf('&'); | |
if (scoreSplits[andIndex + 1].indexOf("*") == -1) | |
scoreSplits[andIndex + 1] = scoreSplits[andIndex + 1] + "*"; | |
battingTeam.value = scoreSplits.join(' '); | |
} | |
}, | |
getTestDay: function(match) { | |
match.isStumps = false; | |
if (match.event_format.toLowerCase() == "test" && match.event_state == "L") { | |
match.isStumps = (match.event_status_id == 120); | |
var currentDate = moment((Number(utils.getCookie('currentSystemTime')))); | |
if (currentDate.year() == 1970) { | |
currentDate = moment((Number(utils.getCookie('currentSystemTime')) * 1000)); | |
} | |
if (!currentDate.isValid()) | |
currentDate = moment(); | |
var startDate = moment(match.start_date, moment.ISO_8601); | |
var testMatchDay = currentDate.dayOfYear() - startDate.dayOfYear() + 1; | |
if (testMatchDay > 0 && testMatchDay < 6) return testMatchDay; | |
} | |
return -1; | |
}, | |
getMatchCentreUrl: function(match) { | |
return "/sports/" | |
+ utils.encodeName(match.sport) | |
+ "/" + utils.encodeName(match.tour_name({shortName: false})) | |
+ "/" + utils.encodeName(match.participants[0].name) | |
+ "-vs-" + utils.encodeName(match.participants[1].name) | |
+ "-" + utils.encodeName(match.event_name) | |
+ "-m" + match.game_id; | |
}, | |
} | |
var SM = { | |
callSportsCollectionByDate: function(params) { | |
multisportSDK.callSportsSDK("getCollectionByDate", params); | |
}, | |
callSportsCollectionByTournament: function(params) { | |
multisportSDK.callSportsSDK("getCollectionByTournament", params); | |
}, | |
callSportsCollectionByGameState: function(params) { | |
multisportSDK.callSportsSDK("getCollectionByGameState", params); | |
}, | |
callSportsDateList: function(params) { | |
multisportSDK.callSportsSDK("getDateList", params); | |
}, | |
callDestroyCallerId: function(params) { | |
multisportSDK.callSportsSDK("destroyCallerId", params); | |
}, | |
getUtility: function() { | |
return utility; | |
} | |
} | |
multisportSDK.initSDK(); | |
return SM; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment