League-of-the-ancient/fonctions.py

87 lines
2.2 KiB
Python

# -*- coding: utf-8 -*-
import csv
LOTAstats_csv = open('LOTAstats.csv','r', encoding ='utf-8')
lecteur = csv.DictReader(LOTAstats_csv, delimiter=',')
LOTA = list(lecteur)
def joueur_testeur(kill,power):
fruit1 = [kill,power]
liste_fruits = []
for fruit in LOTA:
liste_fruits.append((fruit['classe'],int(fruit['frags']),int(fruit['death'])))
test = k_plus_proches(fruit1, liste_fruits,10)
return(test)
from math import sqrt
def distance3D(point_a,point_b):
dist_a_b = sqrt((point_a[0] - point_b[0])**2 + (point_a[1] - point_b[1])**2 )
return dist_a_b
def k_plus_proches(point,liste,k):
dist = []
for a in range (0,len(liste)):
dist.append([])
dist[a].append(distance3D(point,[int(liste[a][1]),int(liste[a][2])]))
dist[a].append(liste[a][0])
k_voisins = []
for e in range (0,k):
plus_petit = dist[0]
plus_petit_index = 0
for f in range (0,len(dist)):
if plus_petit[0] > dist[f][0]:
plus_petit = dist[f]
plus_petit_index = f
k_voisins.append(plus_petit)
dist.pop(plus_petit_index)
return k_voisins
def classejoueur (kill,death):
resulta = joueur_testeur(kill,death)
nombreproche = []
for a in range (0,len(resulta)):
vrai = 0
for b in range (0,len(nombreproche)):
if nombreproche[b][1] == resulta[a][1]:
nombreproche[b][0] += 1
vrai = 1
if vrai == 0 :
nombreproche.append([])
nombreproche[len(nombreproche)-1].append(1)
nombreproche[len(nombreproche)-1].append(resulta[a][1])
indexplus = 0
valeurplus = 0
for a in range (0,len(nombreproche)):
if nombreproche[a][0]>valeurplus:
indexplus = a
valeurplus = nombreproche[a][0]
return(nombreproche[indexplus][1])
def tour(rang):
if rang == 'tomato':
toure = "1 er tour"
elif rang == 'mauvais':
toure = "2 er tour"
elif rang == 'moyen':
toure = "3 eme tour"
elif rang == 'bon':
toure = "4 eme tour"
elif rang == 'unicum':
toure = "tour ultime"
return (toure)