Difference between revisions of "Thread:Talk:RoboRunner/Inconsistent APS with LiteRumble/reply"

From Robowiki
Jump to navigation Jump to search
 
m
 
Line 7: Line 7:
  
 
from statistics import mean
 
from statistics import mean
 +
from collections import defaultdict
  
  
Line 15: Line 16:
 
   scores = ET.parse(gzip.open(f'{roborunner_dir}/data/{bot}.xml.gz', 'r')).getroot()
 
   scores = ET.parse(gzip.open(f'{roborunner_dir}/data/{bot}.xml.gz', 'r')).getroot()
  
  from collections import defaultdict
 
 
   aps_raw = defaultdict(list)
 
   aps_raw = defaultdict(list)
  

Latest revision as of 08:50, 22 December 2022

Here is a Python script that calculates APS correctly. Use this script when you want to align with LiteRumble.

import os
import gzip
import xml.etree.ElementTree as ET

from statistics import mean
from collections import defaultdict


roborunner_dir = os.path.expanduser('~/roborunner')  # replace with your roborunner directory


def get_aps_dict(bot):
  scores = ET.parse(gzip.open(f'{roborunner_dir}/data/{bot}.xml.gz', 'r')).getroot()

  aps_raw = defaultdict(list)

  for bot_list in scores:
    for battle in bot_list:
      battle_scores = {}
      total_score = 0

      for robot_score in battle.findall('robot_score'):
        name = robot_score.find('name').text
        score = int(robot_score.find('score').text)
        battle_scores[name] = score
        total_score += score

      aps = 100 * battle_scores[bot] / total_score

      for name, _ in battle_scores.items():
        if name != bot:
          aps_raw[name].append(aps)

  return dict((name, mean(aps)) for name, aps in aps_raw.items())