<commit_before>import bottle
from bottle import route, run, template, post, get, response, request
from json import dumps, loads

from logic import Vector, VectorCollection

import random

from copy import copy

import socket

import re

from parser import data, means
#from parser import data


# enable app

app = bottle.app()


# NOTE: no average draft pick in numeric keys!
numeric_keys = r"3PTM AST BLK FG% FGA FGM FT% FTA FTM PTS REB ST TO".split(" ")

team_keys = "team draftPosition isPlayer".split(" ")

team_name_regex = re.compile(r"\w{,3} \-")

def game_state_to_array(obj):
	assert isinstance(obj, dict)

	# prehistory is not in chronological order
	# because it actually doesn't matter (and we can't recover that information)
	prehistory = []

	player_index = None

	players = len(obj)

	for key, value in obj.iteritems():
		assert set(value.keys()) == set(team_keys)

		vectors = value["team"]

		if (value["isPlayer"]):
			player_index = value["draftPosition"]-1

		for yahoo_rank, vector_obj in vectors.iteritems():
			my_vector = {}
			for k,v in vector_obj.iteritems():
				if k in numeric_keys:
					my_vector[k] = float(v)
				else:
					my_vector[k] = v

			my_vector["yahoo-rank"] = my_vector

			vector_name = team_name_regex.split(vector_obj["playerName"])[0].strip()

			my_vector["name"] = vector_name

			prehistory.append( (value["draftPosition"]-1, my_vector) )



	return {"prehistory" : prehistory, "player_index" : player_index, "players" : players}


def position_of_name(string):
	for idx,row in enumerate(data):
		if data["name"] == string:
			return idx, row
	raise ValueError


# sample data

sample = ("""{
    "player1": {"2":{"injured":false,"ADP":"2.6","FGM":"583","FGA":"1102","FG%":".530","FTM":"326","FTA":"411","FT%":".793","3PTM":"2.5","PTS":"1496","REB":"682","AST":"112","ST":"107","BLK":"202","TO":"110","playerName":"<NAME> NO - PF,C"}},
    "player2: {
"12":{"injured":false,"ADP":"14.5","FGM":"608","FGA":"1222","FG%":".498","FTM":"172","FTA":"236","FT%":".728","3PTM":"1.6","PTS":"1389","REB":"675","AST":"136","ST":"59.5","BLK":"87.0","TO":"94.9","playerName":"<NAME> - PF,C"},
"17":{"injured":false,"ADP":"20.9","FGM":"462","FGA":"967","FG%":".478","FTM":"345","FTA":"422","FT%":".819","3PTM":"65.7","PTS":"1336","REB":"556","AST":"137","ST":"65.7","BLK":"61.2","TO":"122","playerName":"<NAME> - PF,C"}}
  }""")


players = VectorCollection.create(dicts = data, means = means, numeric_keys = numeric_keys)
<commit_msg>fix yahoo rank<commit_after>import bottle
from bottle import route, run, template, post, get, response, request
from json import dumps, loads

from logic import Vector, VectorCollection

import random

from copy import copy

import socket

import re

from parser import data, means
#from parser import data


# enable app

app = bottle.app()


# NOTE: no average draft pick in numeric keys!
numeric_keys = r"3PTM AST BLK FG% FGA FGM FT% FTA FTM PTS REB ST TO".split(" ")

team_keys = "team draftPosition isPlayer".split(" ")

team_name_regex = re.compile(r"\w{,3} \-")

def game_state_to_array(obj):
	assert isinstance(obj, dict)

	# prehistory is not in chronological order
	# because it actually doesn't matter (and we can't recover that information)
	prehistory = []

	player_index = None

	players = len(obj)

	for key, value in obj.iteritems():
		assert set(value.keys()) == set(team_keys)

		vectors = value["team"]

		if (value["isPlayer"]):
			player_index = value["draftPosition"]-1

		for yahoo_rank, vector_obj in vectors.iteritems():
			my_vector = {}
			for k,v in vector_obj.iteritems():
				if k in numeric_keys:
					my_vector[k] = float(v)
				else:
					my_vector[k] = v

			my_vector["yahoo-rank"] = yahoo_rank

			vector_name = team_name_regex.split(vector_obj["playerName"])[0].strip()

			my_vector["name"] = vector_name

			prehistory.append( (value["draftPosition"]-1, my_vector) )



	return {"prehistory" : prehistory, "player_index" : player_index, "players" : players}





# sample data

sample = ("""{
    "player1": {"2":{"injured":false,"ADP":"2.6","FGM":"583","FGA":"1102","FG%":".530","FTM":"326","FTA":"411","FT%":".793","3PTM":"2.5","PTS":"1496","REB":"682","AST":"112","ST":"107","BLK":"202","TO":"110","playerName":"<NAME> - PF,C"}},
    "player2: {
"12":{"injured":false,"ADP":"14.5","FGM":"608","FGA":"1222","FG%":".498","FTM":"172","FTA":"236","FT%":".728","3PTM":"1.6","PTS":"1389","REB":"675","AST":"136","ST":"59.5","BLK":"87.0","TO":"94.9","playerName":"<NAME> - PF,C"},
"17":{"injured":false,"ADP":"20.9","FGM":"462","FGA":"967","FG%":".478","FTM":"345","FTA":"422","FT%":".819","3PTM":"65.7","PTS":"1336","REB":"556","AST":"137","ST":"65.7","BLK":"61.2","TO":"122","playerName":"<NAME> - PF,C"}}
  }""")


players = VectorCollection.create(dicts = data, means = means, numeric_keys = numeric_keys)

{'fraction_non_alphanumeric': 0.22473542228678148, 'fraction_numerical': 0.05934841253372069, 'mean_word_length': 5.703755215577191, 'pattern_counts': {'":': 104, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2283963', 'n_tokens_mistral': 2020, 'n_tokens_neox': 1722, 'n_words': 351}