Exemplo n.º 1
0
def getcompetitorrace(outfile,
                      eventid,
                      eventinstanceid,
                      singleeventid,
                      limit=None):
    #-------------------------------------------------------------------------------
    '''
    create file for competitor race based on eventid, eventinstanceid, singleeventid
    
    :param outfile: base filename for output file, event and distance are appended to name
    :param eventid: event id from running.competitor.com
    :param eventinstanceid: event instance id from running.competitor.com
    :param singleeventid: single event id from running.competitor.com
    :param limit: limit number of records (for testing only)
    
    :rtype: name of file which was created
    '''

    cc = Competitor()
    cc.setraceyear(eventid, eventinstanceid, singleeventid)
    results = cc.getresults(limit)

    # build filename using racename and distance
    # racename needs to be str() else translate gets ValueError because transtab is not Unicode mapping
    racename = str(results[0].racename)
    dist = '{:.1f}'.format(results[0].distmiles)
    if dist == 13.1:
        dist = 'halfmarathon'
    elif dist == 26.2:
        dist = 'marathon'
    else:
        dist = '{}miles'.format(dist)
    # change all ' ' to '-' and quotes to 'x' in racename
    transtab = maketrans(''' '"''', '-xx')
    tracename = racename.translate(transtab)
    outfilename = '{}-{}-{}.csv'.format(outfile, tracename, dist)

    # open output results file
    RS_ = open(outfilename, 'wb')
    RS = csv.DictWriter(RS_, competitor2raceresult.values())
    RS.writeheader()

    # write the results to the file
    for result in results:
        filerow = {}
        for attr in result.attrs:
            filerow[competitor2raceresult[attr]] = getattr(result, attr)
        RS.writerow(filerow)

    # close file
    RS_.close()

    # let caller know the name of the file which was built
    return outfilename
Exemplo n.º 2
0
def parse_gender_map_into_competitor_objects():
    player_map = {}
    with open('/Users/noah.denier/repo/psychology-research/data/gender_map.csv'
              ) as gender_csv_file:
        gender_map = csv.reader(gender_csv_file, delimiter=',')
        line_count = 0
        for player in gender_map:
            if line_count == 0:
                print(f'Column names are {", ".join(player)}')
                line_count += 1
            else:
                player_map[player[0]] = Competitor(player[0], player[1])

    return player_map
def test_processing_dataframe():
    """Test that dataframe is correctly processed"""
    hallon = Competitor("Hallon")
    function_returns_list = hallon.process_dataframe(hallon.get_dataframe())
    assert len(function_returns_list) == 0
def test_getting_dataframe():
    """Test that dataframe is returning something"""
    hallon = Competitor("Hallon")
    function_returns_list = hallon.get_dataframe()
    assert len(function_returns_list) != 0
Exemplo n.º 5
0
# -*- coding: utf-8 -*-
"""
Created on Mon May 14 17:12:19 2018

@author: greg
"""

import requests
from bs4 import BeautifulSoup
import codecs
import time
import pandas as pd
import numpy as np
from competition import Competition
from competitor import Competitor
from dataManager import DataManager

competition_manager = Competition()
competitor_manager = Competitor()
data_manager = DataManager()
Exemplo n.º 6
0
 def spawnCompetitors(self):
     for i in range(self.compSpawnRate):
         loc = random.choice(GLOBAL.COMP_SPAWNS)
         rect = pygame.Rect(loc[0], loc[1], GLOBAL.COMP_WIDTH,
                            GLOBAL.COMP_HEIGHT)
         self.comps.append(Competitor('veryfi', rect, GLOBAL.COMP_SPEED))
Exemplo n.º 7
0
    for f in event_files:
        full_path = event_dir + f
        listOfSetResultFiles.append(full_path)

for f in listOfSetResultFiles:
    with open(f) as set_results_file:
        set_results_json = json.load(set_results_file)
        for set in set_results_json["data"]["event"]["sets"]["nodes"]:
            player_1_results = set["slots"][0]
            player_2_results = set["slots"][1]
            player_1_key = format_player_key(
                player_1_results["entrant"]["name"])
            player_2_key = format_player_key(
                player_2_results["entrant"]["name"])
            if player_1_key not in player_map:
                player_map[player_1_key] = Competitor(player_1_key, 'U')
            if player_2_key not in player_map:
                player_map[player_2_key] = Competitor(player_2_key, 'U')
            report_set(player_map, player_1_results, player_1_key,
                       player_2_key)

results_list_form = []
results_list_form.append(['Gamertag', 'Gender', 'Wins', 'Losses'])
for player in player_map.items():
    player_list_form = []
    player_list_form.append(player[1].gamertag)
    player_list_form.append(player[1].gender)
    player_list_form.append(player[1].wins)
    player_list_form.append(player[1].losses)
    results_list_form.append(player_list_form)