From 3268cd9982689a39a9ebcc96e13e9799351a3c2e Mon Sep 17 00:00:00 2001 From: Gabor Guzmics Date: Wed, 24 May 2017 12:59:12 +0200 Subject: [PATCH] =?UTF-8?q?=E2=98=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scon/logs/base.py | 4 +- src/scon/logs/chat.py | 2 +- src/scon/logs/combat.py | 32 +++++++----- src/scon/logs/game.py | 106 ++++++++++++++++++++------------------ src/scon/logs/logfiles.py | 2 +- src/scon/quick.py | 40 +++++++++++--- 6 files changed, 110 insertions(+), 76 deletions(-) diff --git a/src/scon/logs/base.py b/src/scon/logs/base.py index 73c890a..362a206 100644 --- a/src/scon/logs/base.py +++ b/src/scon/logs/base.py @@ -56,8 +56,10 @@ class Log(object): # datetime.time(hour[, minute[, second[, microsecond[, tzinfo]]]]) _time = datetime.time( int(self.values.get('hh')), int(self.values.get('mm')), - int(self.values.get('ss'), 0), + int(self.values.get('ss', 0)), int(self.values.get('ns', 0)) ) + self._timestamp = _time + return _time def unpack(self, force=False): ''' unpacks this log from its data and saves values ''' diff --git a/src/scon/logs/chat.py b/src/scon/logs/chat.py index b9a64c8..a75cfc2 100644 --- a/src/scon/logs/chat.py +++ b/src/scon/logs/chat.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from logs.base import Log, L_WARNING, Stacktrace +from .base import Log, L_WARNING, Stacktrace import re """ Responsible for Chat Log. diff --git a/src/scon/logs/combat.py b/src/scon/logs/combat.py index 8a1e1a7..0a96970 100644 --- a/src/scon/logs/combat.py +++ b/src/scon/logs/combat.py @@ -4,21 +4,8 @@ This is the most important part for dealing with actual statistics, since every action taken in a combat instance gets logged here. - - - ------------------------------------ - Note: - All logs start with something like - 23:53:29.137 | LOGDATA - - LOGDATA can be quite different depending on the logfile. - - other forms encountered: - 23:54:00.600 WARNING| - - combat logs: - 01:04:38.805 CMBT | """ + import re from .base import Log, L_CMBT, Stacktrace import logging @@ -409,3 +396,20 @@ COMBAT_LOGS = [ Apply, Damage, Spawn, Spell, Reward, Participant, Rocket, Heal, Stacktrace, ] + +""" + + + ------------------------------------ + Note: + All logs start with something like + 23:53:29.137 | LOGDATA + + LOGDATA can be quite different depending on the logfile. + + other forms encountered: + 23:54:00.600 WARNING| + + combat logs: + 01:04:38.805 CMBT | +""" \ No newline at end of file diff --git a/src/scon/logs/game.py b/src/scon/logs/game.py index d406611..8c98d21 100644 --- a/src/scon/logs/game.py +++ b/src/scon/logs/game.py @@ -1,56 +1,18 @@ #!/usr/bin/python # -*- coding: utf-8 -*- - -from logs.base import Log, L_WARNING, Stacktrace -import re """ This deals with the Game.Log file This file records lots of junk, but is needed to establish actions taken between combat sessions, or retrieve more detailed information about running instances. It is also the typical place for a Stacktrace to happen. - - --------------------------------------- -Interesting Lines: - -23:16:27.427 | Steam initialized appId 212070, userSteamID 1|1|4c5a01, userName 'G4bOrg' -23:16:36.214 | ====== starting level: 'levels/mainmenu/mainmenu' ====== -23:16:38.822 | ====== level started: 'levels/mainmenu/mainmenu' success ====== -23:16:44.251 | ====== starting level: 'levels\mainmenu\mm_empire' ====== -23:16:46.464 | ====== level started: 'levels\mainmenu\mm_empire' success ====== - ---- Date: 2014-07-18 (Fri Jul 2014) Mitteleuropäische Sommerzeit UTC+01:00 - -23:55:55.517 | MasterServerSession: connect to dedicated server, session 6777304, at addr 159.253.138.162|35005 -23:55:55.543 | client: start connecting to 159.253.138.162|35005... -23:55:55.683 | client: connected to 159.253.138.162|35005, setting up session... -23:55:55.886 | client: ADD_PLAYER 0 (OregyenDuero [OWL], 00039C86) status 6 team 1 group 1178422 -23:55:55.886 | client: ADD_PLAYER 1 (R0gue, 0012768A) status 6 team 2 group 1178451 -23:55:55.886 | client: ADD_PLAYER 2 (g4borg [OWL], 0003A848) status 1 team 1 group 1178422 -23:55:55.886 | client: ADD_PLAYER 3 (WladTepes, 001210D8) status 6 team 1 -23:55:55.886 | client: ADD_PLAYER 4 (oberus [], 000FE9B2) status 6 team 2 -23:55:55.886 | client: ADD_PLAYER 5 (TheGuns58, 00121C58) status 6 team 1 -23:55:55.886 | client: ADD_PLAYER 6 (Belleraphon, 0004C744) status 2 team 2 -23:55:55.886 | client: ADD_PLAYER 7 (TopoL, 00007E1F) status 6 team 1 -23:55:55.886 | client: ADD_PLAYER 8 (unicoimbraPT, 000C4FAC) status 6 team 2 -23:55:55.886 | client: ADD_PLAYER 9 (AeroBobik [], 00082047) status 6 team 1 -23:55:55.886 | client: ADD_PLAYER 10 (Samson4321 [], 000B93AF) status 6 team 2 -23:55:55.886 | client: ADD_PLAYER 11 (nol [], 00069165) status 6 team 1 -23:55:55.886 | client: ADD_PLAYER 12 (Pudwoppa, 000334A4) status 2 team 2 -23:55:55.886 | client: ADD_PLAYER 13 (IgorMad [], 000D2AF3) status 6 team 1 -23:55:55.886 | client: ADD_PLAYER 14 (YokaI, 000F1CC9) status 6 team 2 -23:55:55.886 | client: ADD_PLAYER 15 (MrAnyKey [], 0012246C) status 6 team 2 group 1178451 -23:55:55.886 | client: ADD_PLAYER 30 ((bot)David, 00000000) status 4 team 1 -23:55:55.886 | client: ADD_PLAYER 31 ((bot)George, 00000000) status 4 team 2 -23:55:55.886 | client: server assigned id 2 -23:55:55.886 | client: got level load message 's1340_thar_aliendebris13' -23:55:55.889 | reset d3d device -23:55:56.487 | ReplayManager: stopping activity due to map change -23:55:56.576 | ====== starting level: 'levels\area2\s1340_thar_aliendebris13' KingOfTheHill client ====== - - """ +from .base import Log, L_WARNING, Stacktrace +import re +import logging +trash_log = logging.getLogger('trash_log') + + class GameLog(Log): __slots__ = Log.__slots__ @classmethod @@ -90,16 +52,14 @@ class GameLog(Log): self.trash = False return True # unknown? + trash_log.info('%s\t\t%s' % (self.__class__.__name__, self.values.get('log', ''))) self.trash = True def explain(self): ''' returns a String readable by humans explaining this Log ''' return self.values.get('log', 'Unknown Game Log') -class WarningLog(Log): - # has no slots, always trash. - trash = True - +class WarningLog(Log): @classmethod def is_handler(cls, log): if log.get('logtype', None) == L_WARNING: @@ -107,6 +67,7 @@ class WarningLog(Log): return False def __init__(self, values=None): + super(WarningLog, self).__init__() self.trash = True ######################################################################################################## @@ -203,10 +164,53 @@ class LevelStarted(GameLog): -GAME_LOGS = [#SteamInitialization, +GAME_LOGS = [SteamInitialization, MasterServerSession, ClientInfo, StartingLevel, - #LevelStarted, + LevelStarted, Stacktrace, - ] \ No newline at end of file + ] + +""" + + +-------------------------------------- +Interesting Lines: + +23:16:27.427 | Steam initialized appId 212070, userSteamID 1|1|4c5a01, userName 'G4bOrg' +23:16:36.214 | ====== starting level: 'levels/mainmenu/mainmenu' ====== +23:16:38.822 | ====== level started: 'levels/mainmenu/mainmenu' success ====== +23:16:44.251 | ====== starting level: 'levels\mainmenu\mm_empire' ====== +23:16:46.464 | ====== level started: 'levels\mainmenu\mm_empire' success ====== + +--- Date: 2014-07-18 (Fri Jul 2014) Mitteleuropäische Sommerzeit UTC+01:00 + +23:55:55.517 | MasterServerSession: connect to dedicated server, session 6777304, at addr 159.253.138.162|35005 +23:55:55.543 | client: start connecting to 159.253.138.162|35005... +23:55:55.683 | client: connected to 159.253.138.162|35005, setting up session... +23:55:55.886 | client: ADD_PLAYER 0 (OregyenDuero [OWL], 00039C86) status 6 team 1 group 1178422 +23:55:55.886 | client: ADD_PLAYER 1 (R0gue, 0012768A) status 6 team 2 group 1178451 +23:55:55.886 | client: ADD_PLAYER 2 (g4borg [OWL], 0003A848) status 1 team 1 group 1178422 +23:55:55.886 | client: ADD_PLAYER 3 (WladTepes, 001210D8) status 6 team 1 +23:55:55.886 | client: ADD_PLAYER 4 (oberus [], 000FE9B2) status 6 team 2 +23:55:55.886 | client: ADD_PLAYER 5 (TheGuns58, 00121C58) status 6 team 1 +23:55:55.886 | client: ADD_PLAYER 6 (Belleraphon, 0004C744) status 2 team 2 +23:55:55.886 | client: ADD_PLAYER 7 (TopoL, 00007E1F) status 6 team 1 +23:55:55.886 | client: ADD_PLAYER 8 (unicoimbraPT, 000C4FAC) status 6 team 2 +23:55:55.886 | client: ADD_PLAYER 9 (AeroBobik [], 00082047) status 6 team 1 +23:55:55.886 | client: ADD_PLAYER 10 (Samson4321 [], 000B93AF) status 6 team 2 +23:55:55.886 | client: ADD_PLAYER 11 (nol [], 00069165) status 6 team 1 +23:55:55.886 | client: ADD_PLAYER 12 (Pudwoppa, 000334A4) status 2 team 2 +23:55:55.886 | client: ADD_PLAYER 13 (IgorMad [], 000D2AF3) status 6 team 1 +23:55:55.886 | client: ADD_PLAYER 14 (YokaI, 000F1CC9) status 6 team 2 +23:55:55.886 | client: ADD_PLAYER 15 (MrAnyKey [], 0012246C) status 6 team 2 group 1178451 +23:55:55.886 | client: ADD_PLAYER 30 ((bot)David, 00000000) status 4 team 1 +23:55:55.886 | client: ADD_PLAYER 31 ((bot)George, 00000000) status 4 team 2 +23:55:55.886 | client: server assigned id 2 +23:55:55.886 | client: got level load message 's1340_thar_aliendebris13' +23:55:55.889 | reset d3d device +23:55:56.487 | ReplayManager: stopping activity due to map change +23:55:56.576 | ====== starting level: 'levels\area2\s1340_thar_aliendebris13' KingOfTheHill client ====== + +""" \ No newline at end of file diff --git a/src/scon/logs/logfiles.py b/src/scon/logs/logfiles.py index 08f0139..2c2703b 100644 --- a/src/scon/logs/logfiles.py +++ b/src/scon/logs/logfiles.py @@ -32,7 +32,7 @@ class CombatLogFile(LogFile): return line class GameLogFile(LogFile): - ''' Game Log ''' + ''' Game Log ''' def resolve(self, line): for klass in GAME_LOGS: if klass.is_handler(line): diff --git a/src/scon/quick.py b/src/scon/quick.py index 423bf26..24f3465 100644 --- a/src/scon/quick.py +++ b/src/scon/quick.py @@ -21,16 +21,40 @@ if __name__ == '__main__': print (logf.idstr) logf.parse_files(['game.log', 'combat.log']) - if logf.combat_log: - print(('length combat log ', len(logf.combat_log.lines))) - if logf.game_log: - print(('length game log ', len(logf.game_log.lines))) - print(battle_factory(logf)) - print ("Cleaning.") + battles = battle_factory(logf) + + if len(battles) < 1: + # skip this + continue + + for battle in battles: + print(battle.level) + + combat_log_lines, game_log_lines = (0, 0) + + if logf.combat_log: + combat_log_lines = len(logf.combat_log.lines) + if logf.game_log: + game_log_lines = len(logf.game_log.lines) + + preserved = 0 + for line in logf.game_log.lines: + if isinstance(line, dict): + continue + if not line.trash: + preserved += 1 + print("Actually %s lines should be preserved in game.log on clean..." % preserved) + logf.clean() if logf.combat_log: - print(('length combat log ', len(logf.combat_log.lines))) + print('combat.log: %s lines were eliminated during cleaning (%s -> %s)' % ( combat_log_lines - len(logf.combat_log.lines), + combat_log_lines, + len(logf.combat_log.lines), + ) ) if logf.game_log: - print(('length game log ', len(logf.game_log.lines))) + print('game.log: %s lines were eliminated during cleaning (%s -> %s)' % ( game_log_lines - len(logf.game_log.lines), + game_log_lines, + len(logf.game_log.lines), + ) ) \ No newline at end of file