Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #importing everything required
- import mysql.connector as c
- import pandas as pd
- import numpy as np
- import matplotlib.pyplot as plt
- #creating a connection with mySQL
- con=c.connect(host='localhost',user='Aber',password='root',database='Sushant')
- if con.is_connected():
- #print('connection successful')
- #assigning a cursor variable to use SQL statements
- cur=con.cursor()
- #statements to be displayed for the user
- print('Arcane Odyssey Magic Directory:-')
- print('1.Add a Magic into directory')
- print('2.Update stats of a Magic')
- print("3.Delete a Magic's record")
- print("4.Display the directory")
- print('5.Graphical Representation')
- print('6.Exit')
- a=int(input('Please make your choice (1 to 6) >>>'))
- #Adding a Record
- if a==1:
- Magic=input('\nEnter name of the Magic >>>')
- Size=input('Enter size multiplier (2 decimal points) >>>')
- Speed=input('Enter speed multiplier (2 decimal points) >>>')
- Basedamage=input('Enter the multiplier of base damage (excluding DoT, 2 decimal points) >>>')
- Maxdamage=input('Enter the multiplier of damage(including DoT, 2 decimal points) >>>')
- Destruction=input('Enter destruction multiplier(2 decimal points) >>>')
- Statusfx=input('Enter status effect associated with the magic when cast, put N/A for no status effect >>>')
- cur.execute("insert into Magicstats(Magic,Size,Speed,Basedamage,Maxdamage,Destruction,Statusfx)values('{}','{}','{}','{}','{}','{}','{}')".format(Magic,Size,Speed,Basedamage,Maxdamage,Destruction,Statusfx))
- con.commit()
- print(Magic,'magic added successfully')
- #Updating a Record
- elif a==2:
- print('\nCurrent directory of magics:-\n (Note:To change the name of a magic, you will need to delete the existing magic record from the table and create its record again)\n')
- cur.execute('select * from Magicstats')
- data=cur.fetchall()
- df=pd.DataFrame(data,columns=['Magic','Size','Speed','Base','Max','Dest','Statusfx'])
- print(df)
- M=input('\nEnter name of the Magic to update >>>')
- Si=input('Enter updated size multiplier (2 decimal points) >>>')
- Sp=input('Enter updated speed multiplier (2 decimal points) >>>')
- Basedmg=input('Enter updated multiplier of base damage (excluding DoT, 2 decimal points) >>>')
- Maxdmg=input('Enter updated multiplier of damage(including DoT, 2 decimal points) >>>')
- Dest=input('Enter updated destruction multiplier(2 decimal points) >>>')
- Statfx=input('Enter updated status effect associated with the magic when cast, put N/A for no status effect >>>')
- cur.execute("update Magicstats set Size='{}',Speed='{}',Basedamage='{}',Maxdamage='{}',Destruction='{}',Statusfx='{}' where Magic='{}' ".format(Si,Sp,Basedmg,Maxdmg,Dest,Statfx,M))
- con.commit()
- print(M,'magic updated successfully')
- #Deleting a Record
- elif a==3:
- print('\nCurrent directory of magics:- \n')
- cur.execute('select * from Magicstats')
- data=cur.fetchall()
- df=pd.DataFrame(data,columns=['Magic','Size','Speed','Base','Max','Dest','Statusfx'])
- print(df)
- M=input('Enter the name of Magic to delete >>>')
- cur.execute('select * from Magicstats where Magic="{}"'.format(M))
- name=cur.fetchone()
- if name:
- cur.execute('delete from Magicstats where Magic="{}"'.format(M))
- con.commit()
- print(M,'magic deleted successfully.')
- else:
- print('There is no such magic known as',M,'magic in the directory currently. Perhaps you made a spelling error?')
- #Displaying the table
- elif a==4:
- print('\nCurrent directory of magics:- \n')
- cur.execute('select * from Magicstats')
- data=cur.fetchall()
- df=pd.DataFrame(data,columns=['Magic','Size','Speed','Base','Max','Dest','Statusfx'])
- print(df)
- #Displaying the table with conditions
- print("\n4.1)Display details of any magic")
- print("4.2)Display the directory as per size")
- print("4.3)Display the directory as per speed")
- print("4.4)Display the directory as per base damage")
- print("4.5)Display only DoT(Damage-over-Time) magics")
- print("4.6)Display the directory as per destruction potential")
- b=float(input('Please make your choice (4.1 to 4.6) >>>'))
- if b==4.1:
- M=input("\nEnter the name of magic to display details of >>>")
- cur.execute('select * from magicstats where Magic="{}"'.format(M))
- data=cur.fetchall()
- if data:
- df=pd.DataFrame(data,columns=['Magic','Size','Speed','Base','Max','Dest','Statusfx'])
- print(df)
- else:
- print('There is no such magic known as',M,'magic in the directory currently. Perhaps you made a spelling error?')
- if b==4.2:
- print('\n Directory ordered as per size of magics:-\n')
- cur.execute('select * from magicstats order by Size desc')
- data=cur.fetchall()
- df=pd.DataFrame(data,columns=['Magic','Size','Speed','Base','Max','Dest','Statusfx'])
- print(df)
- if b==4.3:
- print('\n Directory ordered as per speed of magics:-\n')
- cur.execute('select * from magicstats order by Speed desc')
- data=cur.fetchall()
- df=pd.DataFrame(data,columns=['Magic','Size','Speed','Base','Max','Dest','Statusfx'])
- print(df)
- if b==4.4:
- print('\n Directory ordered as per base damage of magics:-\n')
- cur.execute('select * from magicstats order by Basedamage desc')
- data=cur.fetchall()
- df=pd.DataFrame(data,columns=['Magic','Size','Speed','Base','Max','Dest','Statusfx'])
- print(df)
- if b==4.5:
- print('\n Directory with only DoT magics:-\n')
- cur.execute('select * from magicstats where basedamage!=maxdamage')
- data=cur.fetchall()
- df=pd.DataFrame(data,columns=['Magic','Size','Speed','Base','Max','Dest','Statusfx'])
- print(df)
- if b==4.6:
- print('\n Directory ordered as per destruction potential of magics:-\n')
- cur.execute('select * from magicstats order by Destruction desc')
- data=cur.fetchall()
- df=pd.DataFrame(data,columns=['Magic','Size','Speed','Base','Max','Dest','Statusfx'])
- print(df)
- #Graphical representation
- elif a==5:
- print('\n5.1) Display line graph')
- print('5.2) Display bar graph')
- b=float(input('Please make your choice (5.1 or 5.2) >>>'))
- if b==5.1:
- cur.execute('select magic,size,speed,maxdamage,destruction from magicstats')
- data=cur.fetchall()
- df=pd.DataFrame(data)
- plt.plot(df[0],df[1],color='Green',label='Size')
- plt.plot(df[0],df[2],color='Blue',label='Speed')
- plt.plot(df[0],df[3],color='Red',label='Damage')
- plt.plot(df[0],df[4],color='Orange',label='Destruction')
- plt.xlabel('Magic')
- plt.ylabel('Multiplier')
- plt.legend()
- plt.title('Size,Speed,Damage and Destruction multiplier of each magic')
- plt.show()
- if b==5.2:
- cur.execute('select magic,size,speed,maxdamage,destruction from magicstats')
- data=cur.fetchall()
- df=pd.DataFrame(data)
- w=0.2
- gap=0.2
- x=np.arange(len(df[0]))*(1+gap)
- plt.bar(x-w*1.5,df[1],w,color='Green',label='Size')
- plt.bar(x-w*0.5,df[2],w,color='Blue',label='Speed')
- plt.bar(x+w*0.5,df[3],w,color='Red',label='Damage')
- plt.bar(x+w*1.5,df[4],w,color='Orange',label='Destruction')
- plt.xlabel('Magic')
- plt.ylabel('Multiplier')
- plt.legend()
- plt.title('Size,Speed,Damage and Destruction multiplier of each magic')
- plt.xticks(x,df[0])
- plt.show()
- #Exit
- elif a==6:
- print('Connection closed')
- con.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement