print "Loading mod: replay_avgfps v2016-05-25 (http://forum.worldoftanks.eu/index.php?/topic/527647-)"

from debug_utils import LOG_NOTE

from PlayerEvents import g_playerEvents
from gui.app_loader import g_appLoader
import BigWorld, BattleReplay, time

start_time = None
last_time = None
sum_fpsReplay = 0
sum_fps = 0

def new_updateDebugInfo(self, fps, ping, lag, fpsReplay):
    global start_time, last_time, sum_fpsReplay, sum_fps
    if fpsReplay != 0 and fpsReplay != -1:
        t = time.time()
        if start_time is None:
            start_time = t
            avg_fpsReplay = fpsReplay
            avg_fps = fps
        else:
            duration = t - last_time
            sum_fpsReplay = duration * fpsReplay + sum_fpsReplay
            sum_fps = duration * fps + sum_fps
            duration = t - start_time
            avg_fpsReplay = sum_fpsReplay / duration
            avg_fps = sum_fps / duration
        last_time = t
        fps = '{0}({1})'.format(fps, int(avg_fps))
    else:
        fps = str(fps)
    ping = str(ping)
    self.flashObject.as_updateDebugInfo(fps, ping, lag)

from gui.Scaleform.Battle import DebugPanel
DebugPanel.updateDebugInfo = new_updateDebugInfo
