<commit_before>#!/usr/bin/python

from rom import RomLoader
from sys import argv
from tournament_locations import locations

if __name__ == "__main__":
    roms = argv[1:]

    counts = {
        'Varia': {'Crateria': 0, 'Brinstar': 0, 'Norfair': 0, 'LowerNorfair': 0, 'WreckedShip': 0, 'Maridia': 0},
        'Gravity': {'Crateria': 0, 'Brinstar': 0, 'Norfair': 0, 'LowerNorfair': 0, 'WreckedShip': 0, 'Maridia': 0},
        'SpeedBooster': {'Crateria': 0, 'Brinstar': 0, 'Norfair': 0, 'LowerNorfair': 0, 'WreckedShip': 0, 'Maridia': 0},
        'HiJump': {'Crateria': 0, 'Brinstar': 0, 'Norfair': 0, 'LowerNorfair': 0, 'WreckedShip': 0, 'Maridia': 0},
        'Grapple': {'Crateria': 0, 'Brinstar': 0, 'Norfair': 0, 'LowerNorfair': 0, 'WreckedShip': 0, 'Maridia': 0},
        'SpaceJump': {'Crateria': 0, 'Brinstar': 0, 'Norfair': 0, 'LowerNorfair': 0, 'WreckedShip': 0, 'Maridia': 0},
        'Ice': {'Crateria': 0, 'Brinstar': 0, 'Norfair': 0, 'LowerNorfair': 0, 'WreckedShip': 0, 'Maridia': 0},
        'Bomb': {'Crateria': 0, 'Brinstar': 0, 'Norfair': 0, 'LowerNorfair': 0, 'WreckedShip': 0, 'Maridia': 0},
        'Charge': {'Crateria': 0, 'Brinstar': 0, 'Norfair': 0, 'LowerNorfair': 0, 'WreckedShip': 0, 'Maridia': 0}
    }

    locCounts = {}
    locNames = []
    progItems = ['Varia', 'Gravity', 'SpeedBooster', 'HiJump', 'Grapple', 'SpaceJump', 'Ice', 'Bomb', 'Charge']
    
    for rom in roms:
        romLoader = RomLoader.factory(rom)
        romLoader.assignItems(locations)

        for loc in locations:
            if loc['itemName'] in progItems:
                counts[loc['itemName']][loc['Area']] = counts[loc['itemName']][loc['Area']] + 1
                if not loc['itemName'] in locCounts:
                    locCounts[loc['itemName']] = {}
                if not loc['Name'] in locNames:
                    locNames.append(loc['Name'])
                if not loc['Name'] in locCounts[loc['itemName']]:
                    locCounts[loc['itemName']][loc['Name']] = 0
                locCounts[loc['itemName']][loc['Name']] += 1

    outFileName = 'area_stats.csv'
    with open(outFileName, 'w') as outFile:
        outFile.write("ITEM;Crateria;Brinstar;Norfair;WreckedShip;Maridia;LowerNorfair;\n")
        for item in ['Varia', 'Gravity', 'SpeedBooster', 'HiJump', 'Grapple', 'SpaceJump', 'Ice', 'Bomb']:
            outFile.write("{};{};{};{};{};{};{};\n".format(item,
                                                           counts[item]['Crateria'],
                                                           counts[item]['Brinstar'],
                                                           counts[item]['Norfair'],
                                                           counts[item]['WreckedShip'],
                                                           counts[item]['Maridia'],
                                                           counts[item]['LowerNorfair']))
    outFileName = 'loc_stats.csv'
    with open(outFileName, 'w') as outFile:
        outFile.write("LOCATION;")
        for itemName in progItems:
            outFile.write(itemName + ";")
        outFile.write('\n')
        for locName in locNames:
            outFile.write(locName + ";")
            for itemName in progItems:
                c = 0
                if locName in locCounts[itemName]:
                    c = locCounts[itemName][locName]
                outFile.write(str(c) + ';')
            outFile.write('\n')<commit_msg>get_stats: rewritten to read 1st items log instead of ROM<commit_after>#!/usr/bin/python

from rom import RomLoader
from sys import argv
from tournament_locations import locations

if __name__ == "__main__":
    firstLogs = argv[1:]

    itemNames = []
    areaCounts = {}
    areaNames = []
    locCounts = {}
    locNames = []
    
    for log in firstLogs:
        with open(log, 'r') as logFile:
            lines = logFile.readlines()
        lines = [l.strip() for l in lines]
        for i in range(1, len(lines)): # skip header
            line = lines[i]
            fields = line.split(';')
            item, loc, area = fields[0], fields[1], fields[2]
            if loc not in locNames:
                locNames.append(loc)
            if area not in areaNames:
                areaNames.append(area)
            if item not in itemNames:
                itemNames.append(item)
            if item not in locCounts:
                locCounts[item] = {}
            if item not in areaCounts:
                areaCounts[item] = {}
            if area not in areaCounts[item]:
                areaCounts[item][area] = 0
            if loc not in locCounts[item]:
                locCounts[item][loc] = 0
            areaCounts[item][area] += 1
            locCounts[item][loc] += 1

    outFileName = 'area_stats.csv'
    with open(outFileName, 'w') as outFile:
        outFile.write("ITEM;{}\n".format(';'.join(areaNames)))
        for item in itemNames:
            outFile.write(item)
            for area in areaNames:
                c = 0
                if area in areaCounts[item]:
                    c = areaCounts[item][area]
                outFile.write(';' + str(c))
            outFile.write('\n')
    outFileName = 'loc_stats.csv'
    with open(outFileName, 'w') as outFile:
        outFile.write("LOCATION;")
        for itemName in itemNames:
            outFile.write(itemName + ";")
        outFile.write('\n')
        for locName in locNames:
            outFile.write(locName + ";")
            for itemName in itemNames:
                c = 0
                if locName in locCounts[itemName]:
                    c = locCounts[itemName][locName]
                outFile.write(str(c) + ';')
            outFile.write('\n')
{'fraction_non_alphanumeric': 0.1492041280391814, 'fraction_numerical': 0.012419100927059647, 'mean_word_length': 1.887878787878788, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6760168', 'n_tokens_mistral': 1865, 'n_tokens_neox': 1732, 'n_words': 420}