Repository navigation
Expand file tree
/
Copy pathpoint_calculation.py
More file actions
90 lines (79 loc) · 2.17 KB
/
Copy pathpoint_calculation.py
File metadata and controls
90 lines (79 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""
This file contains code to calculate the points for a player according to the
rules given in the problem statement file.
"""
import sqlite3
def get_team_score(team):
"""
This function takes in the names of players of a team as a list and
returns their scores (points) in a list.
Parameters
----------
team : list
Names of players of the team.
Returns
-------
scores : list
List of scores of players in list team.
"""
game = sqlite3.connect('player_database.db')
cur = game.cursor()
scores = []
for i in team:
player_name = i
# Access database and get stats of the player
command = "SELECT * FROM match WHERE player = '{}';".format(player_name)
stats = []
cur.execute(command)
record = cur.fetchall()
for i in record[0]:
stats.append(i)
stats.remove('{}'.format(player_name))
scores.append(score(stats))
game.close()
return scores
def score(player_stat):
"""
This function takes in the player stats in the form of a list and outputs
the player score according to the rules mentioned in the problem statement.
Parameters
----------
player_stat : list
List of player stats.
Returns
-------
score : int
Score (points) of player accordint to the rules.
"""
score = 0
score += player_stat[0] // 2
if player_stat[0] >= 100:
score += 15
elif player_stat[0] >= 50:
score += 5
try:
strike = player_stat[0] / player_stat[1] * 100
if strike > 100:
score += 6
elif strike > 80:
score += 2
except:
pass
score += player_stat[2] + player_stat[3] * 2
score += player_stat[7] * 10
if player_stat[7] >= 5:
score += 15
elif player_stat[7] >= 3:
score += 5
try:
economy = player_stat[6] / (player_stat[4] / 6)
if economy < 2:
score += 10
elif economy < 3.5:
score += 7
elif economy < 4.5:
score += 4
except:
pass
score += 10 * (player_stat[8] + player_stat[9] + player_stat[10])
return score