Skip to content

Instantly share code, notes, and snippets.

@sebyx07
Created April 20, 2014 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebyx07/11127214 to your computer and use it in GitHub Desktop.
Save sebyx07/11127214 to your computer and use it in GitHub Desktop.
var module = D2_match_analyzer;
var feeder = {
module: module,
inQueue: 0,
getMatchesForCarry: function(){
var self = this;
//check how many are in queue
self.inQueue = module.storage.queue.length;
if(self.inQueue){
if (self.inQueue > 2){
self.module.fetcher.getMatches(2, function(err, data){
if(err){
console.log("unable to process: " + data);
}else{
console.log("radiant win ?: " + data.radiant_win);
}
});
}
else{
self.module.fetcher.getMatches(self.inQueue, function(err, data){
if(err){
console.log("unable to process: " + data);
}else{
console.log("radiant win ?: " + data.radiant_win);
}
});
}
}
console.log("matches in queue " + self.inQueue);
}
};
D2_match_analyzer.feeder = feeder;
Meteor.setInterval(function(){
module.feeder.getMatchesForCarry();
}, 2000);
//TEMP START
Meteor.setInterval(function(){
Meteor.call("TEMP_d2_match_analyzerInsertSampleData", 9, function(err,response){});
}, 10000);
//TEMP END
var module = D2_match_analyzer;
var fetcher = {
module: module,
generateUrl: function(match_id){
return "http://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/V001/?key=EE4B46697AAE3B64E5E4334E10E7AB0F&match_id=" + match_id;
},
getMatches: function(nrMatches, callback) {
var self = this;
//get a number of matches
//returns array of numbers
var match_ids = self.module.storage.getNumberOfMatches(nrMatches);
match_ids.forEach(function(match_id){
var url = self.generateUrl(match_id);
Meteor.http.get(url, function(err, response){
if(!err && !response.data.result.error){
callback(null, response.data.result);
}else{
callback(err || response.data.result.error, match_id);
}
})
});
}
};
D2_match_analyzer.fetcher = fetcher;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment