Untitled Document
Untitled Document
SCHOOL, CHENNAI 34
M.Srinivasa Ramanujam
XII B
20628130
BONAFIDE CERTIFICATE
Date: _____________
P.G.T In _______________
Chennai
Date: _________________
Examiner
Seal
ACKNOWLEDGEMENT
I would like to extend my gratitude to Mrs. Vasanthi S, our principal for giving us
this marvelous opportunity. I will treasure the knowledge imparted to me by Mrs.
Kala L Dass, our computer science teacher. My sincere thanks to her for her
incredible teaching and guidance.I also thank my parents and friends for their
constant support and cooperation.
INDEX
PARTICULARS PG NO
CASE STUDY 1
MYSQL TABLE STRUCTURES 3
ALGORITHM 4
SAMPLE FLOW CHART 5
PROJECT CODE 6
SAMPLE SCREENSHOTS 19
LIMITATIONS 20
SCOPE FOR IMPROVEMENT 21
BIBLIOGRAPHY 22
CASE STUDY
This project is a Python script that connects to a MySQL database and uses it to retrieve
data about tennis players, as well as simulate a game and predict the winner of a match.
The script includes several functions, including ranking(), player(), stats() and predict().
The ranking() function retrieves and sorts data from the 'main' table in the 'ys' database,
and then prints the name and points of each player. The player() function takes in the
name of a player, and returns the full name of the player if any of the input is a nickname
of the player, which is used to make sure the right player is selected. The stats() function
retrieves and prints the name, points, country and win-loss record of a player from the
'main' table. The predict() function takes in the name of two players and a court, retrieves
data about the players and the court from the 'main' and 'court' tables in the 'ys' database
and uses it to simulate and predict the winner of a match.
Prerequisites:
● A MySQL server installed and running on the local machine
● A database named 'ys' with a table named 'main' that contains information about
the players
● MySQL connector for Python should be installed
Connecting to the Database
● The script starts by importing the 'mysql.connector' and 'random' libraries and then
establishes a connection to the 'ys' database with the following line of code:
● x=mc.connect(host='localhost',user='root',database = 'ys',password="mysql")
● The host is set to 'localhost' as the database is on the same machine as the script,
the user is set to 'root', the database is set to 'ys' and password is 'mysql'.
Functions
● ranking()
This function retrieves data from the 'main' table in the 'ys' database and sorts it by
points. It then prints the name and points of each player in a graphical format.
● player(p1)
This function takes in the name of a player, and returns the full name of the player
if any of the input is a nickname of the player, which is used to make sure the right
player is selected.
● stats()
This function retrieves and prints the name, points, country and win-loss record of
a player from the 'main' table. It also prints the Grand slam titles of the player if he
has any.
● predict()
This function takes in the name of two players and a court, retrieves data about the
players and the court from the 'main' and 'court' tables in the 'ys' database and uses
it to simulate and predict the winner of a match.
MYSQL TABLE STRUCTURES
Table Main
+---------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| sno | decimal(4,0) | NO | PRI | NULL | |
| name | varchar(30) | YES | | NULL | |
| points | decimal(5,0) | YES | | NULL | |
| country | varchar(20) | YES | | NULL | |
| Winloss | varchar(15) | YES | | NULL | |
+---------+--------------+------+-----+---------+-------+
Table Court
+------------+-------------+------+-----+---------+-----+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-----+
| sno | int(3) | YES | | NULL | |
| hardcourt | varchar(20) | YES | | NULL | |
| grasscourt | varchar(20) | YES | | NULL | |
| claycourt | varchar(20) | YES | | NULL | |
| hard_year | varchar(20) | YES | | NULL | |
| clay_year | varchar(20) | YES | | NULL | |
| grass_year | varchar(20) | YES | | NULL | |
| year | varchar(20) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
ALGORITHM
import mysql.connector as mc
import random as rand
x=mc.connect(host='localhost',user='root',database='ys',password
="mysql")
cr=x.cursor()
def ranking():
cr.execute("Select name,points from main")
rin=cr.fetchall()
ri=rin.sort()
for x in ri:
ufg=x[1]
hg=ufg/35
print(x[0],":","|"*hg,hg*35)
def player(p1):
if p1 in ["Djokovik","Novak","Djoker","Djokovic"]:
p1="Novak Djokovic"
if p1 in ["Raefeal Nadal","Nadal","Rafa"]:
p1="Rafael Nadal"
if p1 in ["Kyrgios","kyrigios"]:
p1="Nick Kyrgios"
if p1 in ["Sinner","Jannik","Siner","Janik Sinner"]:
p1="Jannik Sinner"
if p1 in ["Zverev","Sacha","Zevrev"]:
p1="Alexander Zverev"
if p1=="Alcaraz":
p1="Carlos Alcaraz"
if p1 in ["Tsitsi","Tsitsipas","Stefanos
Tsitsipas","Stefanos"]:
p1="Stefanos Tsitsipas"
if p1 in["Casper","Rudd","Casper Rudd"]:
p1="Casper Rudd"
return p1
list_final1=[]
list_final2=[]
#for stats
def stats():
cr.execute("use ys")
print("Welcome to stats! We have stats for the following
players \n1.Novak Djokovic\n2.Rafael Nadal \n3.Nick Kyrgios
\n4.Jannik sinner \n5.Carlos Alcaraz \n6.Alexander Zverev
\n7.Stefanos Tsitsipas\n8.Casper Rudd: ")
p1=input("Enter name of player you want to Search:").title()
p1=player(p1)
cr.execute('SELECT name,points,country,winloss from main
where name like %s',(p1,))
m=cr.fetchall()
print("Name , Rating , Country , W-L
" )
for a in m:
print(a)
if p1=="Novak Djokovic":
print("21 Grand Slams\n1.Australian Open:9\n2.French Open
2\n3.Wimbledon:7\n4.US Open:3")
if p1=="Carlos Alcaraz":
print("1 Grand Slam\n1.US Open:1")
if p1=="Rafael Nadal":
print("22 Grand Slams\n1.Australian Open:2\n2.French Open
14\n3.Wimbledon:2\n4.US Open:4")
if p1=="Nick Kyrgios":
print("1 Grand Slam in Doubles\n1.Australian
Open(Doubles):1")
#prediction algorithm
def predict():
print("Welcome to score prediction! Please chose from the
following players \n1.Novak Djokovic\n2.Rafael Nadal \n3.Nick
Kyrgios \n4.Jannik sinner\n6.Alexander Zverev \n7.Stefanos
Tsitsipas\n8.Casper Rudd \n9.Dannil Medvedev")
p1=input("Enter name of player 1 you want to
Search:").title()
p1=player(p1)
p2=input("Enter name of player 2 you want to
Search:").title()
p2=player(p2)
court=input("Enter name of court the match is played on:")
while True:
ch=input("Do you want to continue with the set: ")
if ch in ("NO","no",0,"n","N"):
break
# for the win percentage:
for a in m:
#player1
if a[1].lower()==p1.lower():
r1=a[2]
z=a[4].split(sep="-")
z1=int(z[0])
z2=int(z[1])
pc1=(z1/(z2+z1))*15
pe1=pe1+(pc1**1.15)
#player2
elif a[1].lower()==p2.lower():
r2=a[2]
y=a[4].split(sep="-")
y1=int(y[0])
y2=int(y[1])
pc2=(y1/(y2+y1))*15
pe2=(pe2+(pc2**1.15))
#for year pc
for a in m:
#player1
if a[1].lower()==p1.lower():
r1=a[2]
z=a[7].split(sep="-")
z1=int(z[0])
z2=int(z[1])
pc1=(z1/(z2+z1))*15
pe1=pe1+(pc1**1.20)
#player2
elif a[1].lower()==p2.lower():
r2=a[2]
y=a[7].split(sep="-")
y1=int(y[0])
y2=int(y[1])
pc2=(y1/(y2+y1))*15
pe2=(pe2+(pc2**1.20))
point1=int((r1/(r1+r2))*20)
point2=int((r2/(r1+r2))*20)
pe1=pe1+point1
pe2=pe2+point2
#for grass
if court.lower()=="grass":
for a in m:
if a[1].lower()==p1.lower():
b=a[6].split(sep="-")
b1=int(b[0])
b2=int(b[1])
pccourt1=(b1/(b2+b1))*15
pe1=pe1+(pccourt1**1.15)
if a[1].lower()==p2.lower():
c=a[6].split(sep="-")
c1=int(c[0])
c2=int(c[1])
pccourt2=(c1/(c2+c1))*15
pe2=pe2+(pccourt2**1.15)
#for clay
if court.lower()=="clay":
for a in m:
if a[1].lower()==p1.lower():
b=a[7].split(sep="-")
b1=int(b[0])
b2=int(b[1])
pccourt1=(b1/(b2+b1))*15
pe1=pe1+(pccourt1**1.15)
if a[1].lower()==p2.lower():
c=a[7].split(sep="-")
c1=int(c[0])
c2=int(c[1])
pccourt2=(c1/(c2+c1))*15
pe2=pe2+(pccourt2**1.15)
#for hard
if court.lower()=="hard":
for a in m:
if a[1].lower()==p1.lower():
b=a[5].split(sep="-")
b1=int(b[0])
b2=int(b[1])
pccourt1=(b1/(b2+b1))*15
pe1=pe1+(pccourt1**1.15)
if a[1].lower()==p2.lower():
c=a[5].split(sep="-")
c1=int(c[0])
c2=int(c[1])
pccourt2=(c1/(c2+c1))*15
pe2=pe2+(pccourt2**1.15)
#for hard
if court.lower()=="hard":
for a in m:
if a[1].lower()==p1.lower():
b=a[4].split(sep="-")
b1=int(b[0])
b2=int(b[1])
pccourt1=(b1/(b2+b1))*15
pe1=pe1+(pccourt1**1.20)
for i in range (int(pe1)):
list_final1.append(p1)
if a[1].lower()==p2.lower():
c=a[4].split(sep="-")
c1=int(c[0])
c2=int(c[1])
pccourt2=(c1/(c2+c1))*15
pe2=pe2+(pccourt2**1.20)
for i in range (int(pe2)):
list_final2.append(p2)
#final prediction
listfinal=list_final2+list_final1
cu1=0
cu2=0
if cu1>cu2:
print(p1.capitalize())
if cu2>cu1:
print(p2.capitalize())
f1=(cu1,cu2)
if cu1==0 or cu2==0:
predict()
if (cu1,cu2)==(5,6):
fi=[(5,7),(6,7)]
f1=rand.choice(fi)
print(f1)
elif (cu1,cu2)==(6,5):
fi=[(7,5),(7,6)]
f1=rand.choice(fi)
print(f1)
else:
print(f1)
def pc():
i=0
pcl=[]
print("Welcome to score prediction! Please chose from the
following players \n1.Novak Djokovic\n2.Rafael Nadal \n4.Jannik
sinner\n6.Alexander Zverev \n7.Stefanos Tsitsipas\n8.Casper Rudd
")
p1=input("Enter name of player 1 you want to
Search:").title()
p1=player(p1)
p2=input("Enter name of player 2 you want to
Search:").title()
p2=player(p2)
court=input("Enter name of court the match is played on:")
cr.execute('SELECT * FROM main natural join court')
pe1=0
pe2=0
m=cr.fetchall()
setno=1
for i in range(100):
# for the win percentage:
for a in m:
#player1
if a[1].lower()==p1.lower():
r1=a[2]
z=a[4].split(sep="-")
z1=int(z[0])
z2=int(z[1])
pc1=(z1/(z2+z1))*15
pe1=pe1+(pc1**1.15)
#player2
elif a[1].lower()==p2.lower():
r2=a[2]
y=a[4].split(sep="-")
y1=int(y[0])
y2=int(y[1])
pc2=(y1/(y2+y1))*15
pe2=(pe2+(pc2**1.15))
#for year pc
for a in m:
#player1
if a[1].lower()==p1.lower():
r1=a[2]
z=a[7].split(sep="-")
z1=int(z[0])
z2=int(z[1])
pc1=(z1/(z2+z1))*15
pe1=pe1+(pc1**1.20)
#player2
elif a[1].lower()==p2.lower():
r2=a[2]
y=a[7].split(sep="-")
y1=int(y[0])
y2=int(y[1])
pc2=(y1/(y2+y1))*15
pe2=(pe2+(pc2**1.20))
point1=int((r1/(r1+r2))*20)
point2=int((r2/(r1+r2))*20)
pe1=pe1+point1
pe2=pe2+point2
#for grass
if court.lower()=="grass":
for a in m:
if a[1].lower()==p1.lower():
b=a[6].split(sep="-")
b1=int(b[0])
b2=int(b[1])
pccourt1=(b1/(b2+b1))*15
pe1=pe1+(pccourt1**1.15)
if a[1].lower()==p2.lower():
c=a[6].split(sep="-")
c1=int(c[0])
c2=int(c[1])
pccourt2=(c1/(c2+c1))*15
pe2=pe2+(pccourt2**1.15)
#for clay
if court.lower()=="clay":
for a in m:
if a[1].lower()==p1.lower():
b=a[7].split(sep="-")
b1=int(b[0])
b2=int(b[1])
pccourt1=(b1/(b2+b1))*15
pe1=pe1+(pccourt1**1.15)
if a[1].lower()==p2.lower():
c=a[7].split(sep="-")
c1=int(c[0])
c2=int(c[1])
pccourt2=(c1/(c2+c1))*15
pe2=pe2+(pccourt2**1.15)
#for hard
if court.lower()=="hard":
for a in m:
if a[1].lower()==p1.lower():
b=a[5].split(sep="-")
b1=int(b[0])
b2=int(b[1])
pccourt1=(b1/(b2+b1))*15
pe1=pe1+(pccourt1**1.15)
if a[1].lower()==p2.lower():
c=a[5].split(sep="-")
c1=int(c[0])
c2=int(c[1])
pccourt2=(c1/(c2+c1))*15
pe2=pe2+(pccourt2**1.15)
#for hard
if court.lower()=="hard":
for a in m:
if a[1].lower()==p1.lower():
b=a[4].split(sep="-")
b1=int(b[0])
b2=int(b[1])
pccourt1=(b1/(b2+b1))*15
pe1=pe1+(pccourt1**1.20)
for i in range (int(pe1)):
list_final1.append(p1)
if a[1].lower()==p2.lower():
c=a[4].split(sep="-")
c1=int(c[0])
c2=int(c[1])
pccourt2=(c1/(c2+c1))*15
pe2=pe2+(pccourt2**1.20)
for i in range (int(pe2)):
list_final2.append(p2)
#final prediction
listfinal=list_final2+list_final1
cu1=0
cu2=0
if cu1>cu2:
pcl.append(p1.capitalize())
elif cu2>cu1:
pcl.append(p2.capitalize())
print(p1.capitalize(),":",pcl.count(p1.capitalize()))
print(p2.capitalize(),":",pcl.count(p2.capitalize()))
i=i+1
def menu():
while True:
menu=int(input("Welcome. Press \n1.Stats\n2.Win Percentage
Calculator \n4.Quit\n3.Ranking Graph"))
if menu==1:
stats()
if menu==2:
pc()
if menu==4:
break
if menu==3:
ranking()
menu()
SAMPLE SCREENSHOTS
LIMITATIONS
● The code only supports a limited number of players for the stats and prediction
functions, and does not allow for input of new players.
● The ranking function only takes into account player points, and does not consider
other factors such as wins and losses or court surface.
● The prediction function does not make use of any statistical or machine learning
models to make predictions, it only use the data from the database to make a
prediction.
● The code does not handle exceptions or errors that may occur during execution,
such as invalid input or connection errors to the database.
● The code does not have a user interface, it only takes inputs and displays outputs
via the command line.
● The code doesn't handle the case of the input being empty or not entered
SCOPE FOR IMPROVEMENT
https://www.atptour.com/en/
https://www.wikipedia.org/