cz.cuni.amis.pogamut.ut2004.agent.module.sensor
Class AgentStats

java.lang.Object
  extended by cz.cuni.amis.pogamut.base.agent.module.AgentModule<AGENT>
      extended by cz.cuni.amis.pogamut.base.agent.module.SensorModule<IObservingAgent>
          extended by cz.cuni.amis.pogamut.ut2004.agent.module.sensor.AgentStats
All Implemented Interfaces:
IComponent

public class AgentStats
extends SensorModule<IObservingAgent>

Memory module specialized on collecting various statistics about the bot such as number of deaths, suicides, etc.

The module abides GameRestarted (clear stats upon the restart) and can be set to export collected data into certain file.


Field Summary
protected  int deaths
          How many times the observed bot has died.
protected  int doubleDamageCount
          How many times the bot had double damage.
protected  double doubleDamageTime
          Total number of seconds the bot had double damage.
protected  java.io.File fileToOutput
          Concrete file we're currently using.
protected  java.util.Map<ItemType.Category,java.lang.Integer> itemsByCategoryCollected
          How many items according to its ItemType.Category the bot has collected.
protected  java.util.Map<ItemType,java.lang.Integer> itemsCollected
          How many items the bot has collected according to their item type.
protected  java.util.Map<UnrealId,java.lang.Integer> killed
          Contains statistics about bot that was KILLED BY OBSERVED BOT.
protected  java.util.Map<UnrealId,java.lang.Integer> killedBy
          Contains statistics about bots that KILLED OBSERVED BOT.
protected  int killedByOthers
          How many times was this bot killed by other players.
protected  int killedOthers
          How many times this bot has killed other players.
protected  Location lastLocation
           
protected  int numberOfPlayersKilledWithoutDeath
          How many other players this bot has killed during its single life.
protected  boolean observer
           
protected  java.util.Formatter outputFile
          Formatter that is used to output strings into the UT2004AnalyzerObserver#observerFile.
protected  java.lang.String pathToOutput
          Path to output as passed by the user.
protected  int playerKilledInRow
           
protected  java.util.Map<UnrealId,PlayerScore> playerScores
          Most rescent message containing info about the player's score.
protected  boolean shooting
          Whether the bot is shooting.
protected  java.lang.Object statsMutex
           
protected  int suicides
          How many times this bot has comitted suicide.
protected  java.util.Map<java.lang.Integer,TeamScore> teamScores
          Most rescent message containing info about the player team's score.
protected  double timeMoving
          For how long in total the bot was moving (had non-zero (> 1) velocity)
protected  double timeShooting
          For how long in total the bot was shooting.
protected  int totalItemsCollected
          Total number of items the bot has collected.
protected  double travelledDistance
          Sum of the bot's travelled distance.
protected  java.util.Map<ItemType,java.lang.Double> weaponsUsedTime
          For how long the bot was shooting with a certain weapon, truly counting the number of seconds the Shoot command has been effective for the bot.
 
Fields inherited from class cz.cuni.amis.pogamut.base.agent.module.SensorModule
worldView
 
Fields inherited from class cz.cuni.amis.pogamut.base.agent.module.AgentModule
agent, controller, eventBus, log
 
Constructor Summary
AgentStats(IObservingAgent bot)
          Constructor.
AgentStats(IObservingAgent bot, java.util.logging.Logger log)
          Constructor.
 
Method Summary
protected  void botKilled(BotKilled event)
           
protected  java.lang.String fixSemicolon(java.lang.String text)
           
protected  void gameRestarted(GameRestarted event)
           
 UnrealId getBotId()
          Returns Id of the bot, sensitive to isObserver().
 double getCurrentMatchTime()
          Current match time - note that this might different from the current GB2004 time because the match time is reset upon GameRestarted.
 double getCurrentUT2004Time()
          Returns current UT2004 time (without any deltas, i.e., this is completely driven by the time from BeginMessages).
 int getDeaths()
          How many times in total your bot has died (regardless the type of death).
 int getDoubleDamageCount()
          How many times your bot had double damage so far.
 double getDoubleDamageTime()
          For how long (in total) your bot had double damage.
 java.util.Map<ItemType.Category,java.lang.Integer> getItemsByCategoryCollected()
          How many items (per respective ItemType.Category) your bot has collected so far.
 java.util.Map<ItemType,java.lang.Integer> getItemsCollected()
          How many items (per ItemType) your bot has collected so far (in total).
 java.util.Map<UnrealId,java.lang.Integer> getKilled()
          Returns map that counts how many time your bot kills other bot (according to opponent bot ID), i.e., under the key (other bot ID) is "how many time your bot has billed the other bot".
 java.util.Map<UnrealId,java.lang.Integer> getKilledBy()
          Who has killed your bot the most? This map holds number according to killers' ides.
 int getKilledByOthers()
          How many times your bot has been killed by other bots.
 int getKilledOthers()
          How many other bots your bot has killed so far.
 double getMatchStartTime()
          Returns the global UT2004 time that we're considering as a start-of-match.
 int getNumberOfPlayersKilledWithoutDeath()
          The biggest number of other bots killed in a row (without being killed).
 java.io.File getOutputFile()
          Actually used file for outputting of stats.
protected  java.io.File getOutputFile(java.lang.String pathToFile, boolean seekAlternatives)
          Returns File for a given 'pathToFile'.
 java.lang.String getOutputPath()
          Returns the output path as supplied in startOutput(String) or startOutput(String, boolean).
 java.util.Map<UnrealId,PlayerScore> getPlayerScores()
          Returns map with scores of respective players in the game.
 int getScore()
          Current score of your bot.
 int getSuicides()
          How many times your bot has committed suicide.
 int getTeamScore()
          Current score of the bot's team.
 java.util.Map<java.lang.Integer,TeamScore> getTeamScores()
          Returns map with scores of respective teams in the game.
 double getTimeMoving()
          For how long your bot was moving (in total).
 double getTimeShooting()
          For how long your bot was shooting (in total).
 int getTotalItemsCollected()
          Total number of items the bot collected (including items received when the bot respawns).
 double getTravelledDistance()
          How big distance your bot has travelled so far.
 java.util.Map<ItemType,java.lang.Double> getWeaponsUsedTime()
          For how long your bot was using a certain weapon (in total).
 boolean isLogBeforeMatchRestart()
          Should we log something before GameRestarted? Default: TRUE.
 boolean isLogging()
          Whether the object is currently collecting stats.
 boolean isObserver()
          Whether the module is being used inside observer.
 boolean isOutputting()
          Whether the object is currently logging (it may be false while the match is being restarted).
 boolean isShooting()
          Whether the bot is currently shooting
 boolean isTimeInitialized()
          Whether we have already received at least two BeginMessage in order to have all time-vars initialized so we may collect all stats.
protected  void itemPickedUp(ItemPickedUp event)
           
protected  void kill()
          Kills the agent module.
 void outputHeader(java.util.Formatter output)
          Outputs stats headers into the 'output'.
protected  void outputStatLine(double time, java.lang.String... eventOutput)
          Outputs stats line with event IFF logging (i.e., outputFile is not null, was initialized by startOutput(String) or startOutput(String, boolean)).
 void outputStatLine(java.util.Formatter output, double time, java.lang.String... eventOutput)
          Outputs stats line into 'output' appending 'eventOutput' at the end (also separated by semicolons)
protected  void playerKilled(PlayerKilled event)
           
 void resetMatchTime()
          Resets match time to ZERO again (if is initialized, i.e., getCurrentMatchTime() > 0).
 void resetStats()
          Reset all stats, DOES NOT RESET getCurrentMatchTime() (use resetMatchTime() for that purpose separately).
 void setLogBeforeMatchRestart(boolean logBeforeMatchRestart)
          Sets whether we should collect stats before GameRestarted event.
 void setObserver(boolean observer)
          Sets whether the module is being used inside observer.
protected  void start(boolean startToPaused)
          Starts the agent module.
 void startOutput(java.lang.String pathToFile)
          Starts or redirect logging to 'pathToFile'.
 void startOutput(java.lang.String pathToFile, boolean seekAlternatives)
          Starts or redirect logging to 'pathToFile'.
protected  void stop()
          Stops the agent module.
 void stopOutput()
          Stops outputting of stats into file, nullify outputFile and fileToOutput.
protected  void updateStats(EndMessage event)
          Called when EndMessage is received, writes another line into the UT2004AnalyzerObsStats#outputFile.
 
Methods inherited from class cz.cuni.amis.pogamut.base.agent.module.AgentModule
cleanUp, getComponentId, getLog, getState, initComponentId, isRunning, pause, reset, resume, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

observer

protected boolean observer

killed

protected java.util.Map<UnrealId,java.lang.Integer> killed
Contains statistics about bot that was KILLED BY OBSERVED BOT.


killedBy

protected java.util.Map<UnrealId,java.lang.Integer> killedBy
Contains statistics about bots that KILLED OBSERVED BOT. Does not contain "suicidies", i.e., value for the key that is this bot ID.


playerScores

protected java.util.Map<UnrealId,PlayerScore> playerScores
Most rescent message containing info about the player's score.


teamScores

protected java.util.Map<java.lang.Integer,TeamScore> teamScores
Most rescent message containing info about the player team's score.


deaths

protected int deaths
How many times the observed bot has died.


suicides

protected int suicides
How many times this bot has comitted suicide.


killedByOthers

protected int killedByOthers
How many times was this bot killed by other players.


killedOthers

protected int killedOthers
How many times this bot has killed other players.


travelledDistance

protected double travelledDistance
Sum of the bot's travelled distance.


shooting

protected boolean shooting
Whether the bot is shooting.


timeShooting

protected double timeShooting
For how long in total the bot was shooting.


timeMoving

protected double timeMoving
For how long in total the bot was moving (had non-zero (> 1) velocity)


weaponsUsedTime

protected java.util.Map<ItemType,java.lang.Double> weaponsUsedTime
For how long the bot was shooting with a certain weapon, truly counting the number of seconds the Shoot command has been effective for the bot.


itemsCollected

protected java.util.Map<ItemType,java.lang.Integer> itemsCollected
How many items the bot has collected according to their item type.


itemsByCategoryCollected

protected java.util.Map<ItemType.Category,java.lang.Integer> itemsByCategoryCollected
How many items according to its ItemType.Category the bot has collected.


totalItemsCollected

protected int totalItemsCollected
Total number of items the bot has collected.


numberOfPlayersKilledWithoutDeath

protected int numberOfPlayersKilledWithoutDeath
How many other players this bot has killed during its single life.


doubleDamageCount

protected int doubleDamageCount
How many times the bot had double damage.


doubleDamageTime

protected double doubleDamageTime
Total number of seconds the bot had double damage.


statsMutex

protected java.lang.Object statsMutex

pathToOutput

protected java.lang.String pathToOutput
Path to output as passed by the user.


fileToOutput

protected java.io.File fileToOutput
Concrete file we're currently using.


outputFile

protected java.util.Formatter outputFile
Formatter that is used to output strings into the UT2004AnalyzerObserver#observerFile.


playerKilledInRow

protected int playerKilledInRow

lastLocation

protected Location lastLocation
Constructor Detail

AgentStats

public AgentStats(IObservingAgent bot)
Constructor. Setups the memory module based on bot's world view.

Parameters:
bot - owner of the module that is using it

AgentStats

public AgentStats(IObservingAgent bot,
                  java.util.logging.Logger log)
Constructor. Setups the memory module based on bot's world view.

Parameters:
bot - owner of the module that is using it
log - Logger to be used for logging runtime/debug info. If null, the module creates its own logger.
Method Detail

isObserver

public boolean isObserver()
Whether the module is being used inside observer. Default: FALSE.

Returns:

setObserver

public void setObserver(boolean observer)
Sets whether the module is being used inside observer. Default: FALSE.

Parameters:
observer -

getBotId

public UnrealId getBotId()
Returns Id of the bot, sensitive to isObserver().

Returns:

outputHeader

public void outputHeader(java.util.Formatter output)
Outputs stats headers into the 'output'.

Parameters:
output -

outputStatLine

public void outputStatLine(java.util.Formatter output,
                           double time,
                           java.lang.String... eventOutput)
Outputs stats line into 'output' appending 'eventOutput' at the end (also separated by semicolons)

Parameters:
output -
eventOutput -

outputStatLine

protected void outputStatLine(double time,
                              java.lang.String... eventOutput)
Outputs stats line with event IFF logging (i.e., outputFile is not null, was initialized by startOutput(String) or startOutput(String, boolean)).

Parameters:
eventOutput -

fixSemicolon

protected java.lang.String fixSemicolon(java.lang.String text)

resetStats

public void resetStats()
Reset all stats, DOES NOT RESET getCurrentMatchTime() (use resetMatchTime() for that purpose separately).


resetMatchTime

public void resetMatchTime()
Resets match time to ZERO again (if is initialized, i.e., getCurrentMatchTime() > 0).


isOutputting

public boolean isOutputting()
Whether the object is currently logging (it may be false while the match is being restarted).

Returns:

getOutputPath

public java.lang.String getOutputPath()
Returns the output path as supplied in startOutput(String) or startOutput(String, boolean).

For concretely used file for the output, use getOutputFile().

Returns:

getOutputFile

public java.io.File getOutputFile()
Actually used file for outputting of stats.

Returns:

startOutput

public void startOutput(java.lang.String pathToFile)
Starts or redirect logging to 'pathToFile'. If it targets dir, throws an exception. Existing file will be overwritten.

Parameters:
pathToFile - (target file format is .csv, should not need to end with any extension, will be supplied)
See Also:
setOutputPath(String, boolean)

stopOutput

public void stopOutput()
Stops outputting of stats into file, nullify outputFile and fileToOutput.

After the call:


getOutputFile

protected java.io.File getOutputFile(java.lang.String pathToFile,
                                     boolean seekAlternatives)
Returns File for a given 'pathToFile'. Target file is either non-existent or is file (otherwise throws an exception).

If 'seekAlternatives' is true, the method will try to find another file if 'pathToFile' already exists by appending "_000", "_001", ... If alternative filename is found, it is returned. Otherwise throws an exception.

Parameters:
pathToFile -
seekAlternatives -
Returns:

startOutput

public void startOutput(java.lang.String pathToFile,
                        boolean seekAlternatives)
Starts or redirect logging to 'pathToFile'. If it targets dir, throws an exception. Existing file will be overwritten.

If 'seekAlternatives' is true, the method will try to find another file if 'pathToFile' already exists by appending "_000", "_001", ... If alternative filename is found, the log is redirected there. Otherwise throws an exception.

Parameters:
pathToFile - (target file format is .csv, should not need to end with any extension, will be supplied)
seekAlternatives - whether to try other file (using suffixes to file name '_000', '_001', ..., '_999'

getKilled

public java.util.Map<UnrealId,java.lang.Integer> getKilled()
Returns map that counts how many time your bot kills other bot (according to opponent bot ID), i.e., under the key (other bot ID) is "how many time your bot has billed the other bot".


getPlayerScores

public java.util.Map<UnrealId,PlayerScore> getPlayerScores()
Returns map with scores of respective players in the game.

Returns:

getTeamScores

public java.util.Map<java.lang.Integer,TeamScore> getTeamScores()
Returns map with scores of respective teams in the game.

Returns:

getCurrentMatchTime

public double getCurrentMatchTime()
Current match time - note that this might different from the current GB2004 time because the match time is reset upon GameRestarted.

Returns negative number if it can't be evaluated, i.e., the match has not been started (and we're waiting for it, that happens only if you have used setLogBeforeMatchRestart(boolean)), or we do not have enough data.

Returns:

getCurrentUT2004Time

public double getCurrentUT2004Time()
Returns current UT2004 time (without any deltas, i.e., this is completely driven by the time from BeginMessages).

Returns negative number if it can't be evaluated.

Returns:

getKilledOthers

public int getKilledOthers()
How many other bots your bot has killed so far.

Returns:

isShooting

public boolean isShooting()
Whether the bot is currently shooting

Returns:

getTimeShooting

public double getTimeShooting()
For how long your bot was shooting (in total). In seconds.

Returns:

getTimeMoving

public double getTimeMoving()
For how long your bot was moving (in total). In seconds.

Returns:

getWeaponsUsedTime

public java.util.Map<ItemType,java.lang.Double> getWeaponsUsedTime()
For how long your bot was using a certain weapon (in total). In seconds.

Returns:

getItemsCollected

public java.util.Map<ItemType,java.lang.Integer> getItemsCollected()
How many items (per ItemType) your bot has collected so far (in total).

Returns:

getItemsByCategoryCollected

public java.util.Map<ItemType.Category,java.lang.Integer> getItemsByCategoryCollected()
How many items (per respective ItemType.Category) your bot has collected so far.

Returns:

getTotalItemsCollected

public int getTotalItemsCollected()
Total number of items the bot collected (including items received when the bot respawns).

Returns:

getNumberOfPlayersKilledWithoutDeath

public int getNumberOfPlayersKilledWithoutDeath()
The biggest number of other bots killed in a row (without being killed).

Returns:

getDoubleDamageCount

public int getDoubleDamageCount()
How many times your bot had double damage so far.

Returns:

getDoubleDamageTime

public double getDoubleDamageTime()
For how long (in total) your bot had double damage. In seconds.

Returns:

getKilledBy

public java.util.Map<UnrealId,java.lang.Integer> getKilledBy()
Who has killed your bot the most? This map holds number according to killers' ides.

Returns:

getDeaths

public int getDeaths()
How many times in total your bot has died (regardless the type of death).

Returns:

getTravelledDistance

public double getTravelledDistance()
How big distance your bot has travelled so far. In UT-Units.

Returns:

getSuicides

public int getSuicides()
How many times your bot has committed suicide.

Returns:

getScore

public int getScore()
Current score of your bot.

Returns:

getTeamScore

public int getTeamScore()
Current score of the bot's team.

Returns:

getKilledByOthers

public int getKilledByOthers()
How many times your bot has been killed by other bots.

Returns:

isTimeInitialized

public boolean isTimeInitialized()
Whether we have already received at least two BeginMessage in order to have all time-vars initialized so we may collect all stats.


getMatchStartTime

public double getMatchStartTime()
Returns the global UT2004 time that we're considering as a start-of-match.

Returns:

isLogging

public boolean isLogging()
Whether the object is currently collecting stats.

This depends on three things:

  1. we have to have isTimeInitialized()
  2. and we should not be waiting for GameRestarted, i.e., you have used setLogBeforeMatchRestart(boolean)
  3. we have already received bot's Self

Returns:

isLogBeforeMatchRestart

public boolean isLogBeforeMatchRestart()
Should we log something before GameRestarted? Default: TRUE.

Returns:

setLogBeforeMatchRestart

public void setLogBeforeMatchRestart(boolean logBeforeMatchRestart)
Sets whether we should collect stats before GameRestarted event. Default: FALSE.

Best to be utilized in IUT2004BotController.prepareBot(UT2004Bot).

Parameters:
logBeforeMatchRestart -

gameRestarted

protected void gameRestarted(GameRestarted event)

botKilled

protected void botKilled(BotKilled event)

playerKilled

protected void playerKilled(PlayerKilled event)

itemPickedUp

protected void itemPickedUp(ItemPickedUp event)

updateStats

protected void updateStats(EndMessage event)
Called when EndMessage is received, writes another line into the UT2004AnalyzerObsStats#outputFile.


start

protected void start(boolean startToPaused)
Description copied from class: AgentModule
Starts the agent module. (Called even if starting to paused state.)

Overrides:
start in class AgentModule<IObservingAgent>

stop

protected void stop()
Description copied from class: AgentModule
Stops the agent module.

Calls AgentModule.cleanUp().

Overrides:
stop in class AgentModule<IObservingAgent>

kill

protected void kill()
Description copied from class: AgentModule
Kills the agent module.

Calls AgentModule.cleanUp().

Overrides:
kill in class AgentModule<IObservingAgent>