From 8c55c1eea69288a22cd78d66e831ed8effbf7f5d Mon Sep 17 00:00:00 2001 From: fkloft Date: Thu, 13 Mar 2014 22:02:11 +0100 Subject: [PATCH] [plugin/guess-player-levels] Fix error in algorithm; skip calculations if player is already known to be L8 --- plugins/guess-player-levels.user.js | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/plugins/guess-player-levels.user.js b/plugins/guess-player-levels.user.js index 64895a0c..c67ec530 100644 --- a/plugins/guess-player-levels.user.js +++ b/plugins/guess-player-levels.user.js @@ -181,6 +181,8 @@ window.plugin.guessPlayerLevels.extractPortalData = function(data) { window.plugin.guessPlayerLevels.extractChatData = function(data) { var attackData = {}; function addAttackMessage(nick, timestamp, portal) { + var details = window.plugin.guessPlayerLevels.fetchLevelDetailsByPlayer(nick); + if(details.guessed == 8 || details.min == 8) return; // we wouldn't get better results, so skip the calcula if(!attackData[nick]) attackData[nick] = {}; if(!attackData[nick][timestamp]) attackData[nick][timestamp] = []; attackData[nick][timestamp].push(portal); @@ -288,11 +290,6 @@ window.plugin.guessPlayerLevels.handleAttackData = function(nick, latlngs) { circle = window.plugin.guessPlayerLevels.calculateCircleWithAnchor(latlngs.slice(0, i + 1), latlng); } - // don't know under what circumstances, but sometimes the calculation fails. ignore nonsense data - if(circle.x == 0 || circle.y == 0) { - return; - } - // circle.range is useless, because it is calculated in degrees (simplified algorithm!) var latlng = L.latLng(circle.y, circle.x); var range = 0; @@ -302,8 +299,9 @@ window.plugin.guessPlayerLevels.handleAttackData = function(nick, latlngs) { range = d; } - // same as above. ignore nonsense data - if(range > 1000) { + // In earlier versions, the algorithm failed. Should be fixed now, but just to be sure, we ignore escalating values... + if(circle.x == 0 || circle.y == 0 || range > 1000) { + console.warn("ignoring attack data: ", nick, latlngs, circle, range); return; } @@ -343,12 +341,12 @@ window.plugin.guessPlayerLevels.calculateCircleWithAnchors = function(latlngs, a for(var i=0; i