Advertisement
Aber_Bluehair

Python code for XII Science JVM 2025 Investigatory Odyssey

Jan 20th, 2025
69
0
364 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.63 KB | None | 0 0
  1. #importing everything required
  2. import mysql.connector as c
  3. import pandas as pd
  4. import numpy as np
  5. import matplotlib.pyplot as plt
  6.  
  7. #creating a connection with mySQL
  8. con=c.connect(host='localhost',user='Aber',password='root',database='Sushant')
  9. if con.is_connected():
  10.     #print('connection successful')
  11.    
  12. #assigning a cursor variable to use SQL statements
  13.     cur=con.cursor()
  14.  
  15. #statements to be displayed for the user
  16. print('Arcane Odyssey Magic Directory:-')
  17. print('1.Add a Magic into directory')
  18. print('2.Update stats of a Magic')
  19. print("3.Delete a Magic's record")
  20. print("4.Display the directory")
  21. print('5.Graphical Representation')
  22. print('6.Exit')
  23. a=int(input('Please make your choice (1 to 6) >>>'))
  24.  
  25. #Adding a Record
  26. if a==1:
  27.     Magic=input('\nEnter name of the Magic >>>')
  28.     Size=input('Enter size multiplier (2 decimal points) >>>')
  29.     Speed=input('Enter speed multiplier (2 decimal points) >>>')
  30.     Basedamage=input('Enter the multiplier of base damage (excluding DoT, 2 decimal points) >>>')
  31.     Maxdamage=input('Enter the multiplier of damage(including DoT, 2 decimal points) >>>')
  32.     Destruction=input('Enter destruction multiplier(2 decimal points) >>>')
  33.     Statusfx=input('Enter status effect associated with the magic when cast, put N/A for no status effect >>>')
  34.     cur.execute("insert into Magicstats(Magic,Size,Speed,Basedamage,Maxdamage,Destruction,Statusfx)values('{}','{}','{}','{}','{}','{}','{}')".format(Magic,Size,Speed,Basedamage,Maxdamage,Destruction,Statusfx))
  35.     con.commit()
  36.     print(Magic,'magic added successfully')
  37.  
  38. #Updating a Record
  39. elif a==2:
  40.     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')
  41.     cur.execute('select * from Magicstats')
  42.     data=cur.fetchall()
  43.     df=pd.DataFrame(data,columns=['Magic','Size','Speed','Base','Max','Dest','Statusfx'])
  44.     print(df)
  45.     M=input('\nEnter name of the Magic to update >>>')
  46.     Si=input('Enter updated size multiplier (2 decimal points) >>>')
  47.     Sp=input('Enter updated speed multiplier (2 decimal points) >>>')
  48.     Basedmg=input('Enter updated multiplier of base damage (excluding DoT, 2 decimal points) >>>')
  49.     Maxdmg=input('Enter updated multiplier of damage(including DoT, 2 decimal points) >>>')
  50.     Dest=input('Enter updated destruction multiplier(2 decimal points) >>>')
  51.     Statfx=input('Enter updated status effect associated with the magic when cast, put N/A for no status effect >>>')
  52.     cur.execute("update Magicstats set Size='{}',Speed='{}',Basedamage='{}',Maxdamage='{}',Destruction='{}',Statusfx='{}' where Magic='{}' ".format(Si,Sp,Basedmg,Maxdmg,Dest,Statfx,M))
  53.     con.commit()
  54.     print(M,'magic updated successfully')
  55.  
  56. #Deleting a Record
  57. elif a==3:
  58.     print('\nCurrent directory of magics:- \n')
  59.     cur.execute('select * from Magicstats')
  60.     data=cur.fetchall()
  61.     df=pd.DataFrame(data,columns=['Magic','Size','Speed','Base','Max','Dest','Statusfx'])
  62.     print(df)
  63.     M=input('Enter the name of Magic to delete >>>')
  64.     cur.execute('select * from Magicstats where Magic="{}"'.format(M))
  65.     name=cur.fetchone()
  66.     if name:
  67.         cur.execute('delete from Magicstats where Magic="{}"'.format(M))
  68.         con.commit()
  69.         print(M,'magic deleted successfully.')
  70.     else:
  71.         print('There is no such magic known as',M,'magic in the directory currently. Perhaps you made a spelling error?')
  72.  
  73. #Displaying the table
  74. elif a==4:
  75.     print('\nCurrent directory of magics:- \n')
  76.     cur.execute('select * from Magicstats')
  77.     data=cur.fetchall()
  78.     df=pd.DataFrame(data,columns=['Magic','Size','Speed','Base','Max','Dest','Statusfx'])
  79.     print(df)
  80.    
  81. #Displaying the table with conditions
  82.     print("\n4.1)Display details of any magic")
  83.     print("4.2)Display the directory as per size")
  84.     print("4.3)Display the directory as per speed")
  85.     print("4.4)Display the directory as per base damage")
  86.     print("4.5)Display only DoT(Damage-over-Time) magics")
  87.     print("4.6)Display the directory as per destruction potential")
  88.     b=float(input('Please make your choice (4.1 to 4.6) >>>'))
  89.    
  90.     if b==4.1:
  91.         M=input("\nEnter the name of magic to display details of >>>")
  92.         cur.execute('select * from magicstats where Magic="{}"'.format(M))
  93.         data=cur.fetchall()
  94.         if data:
  95.             df=pd.DataFrame(data,columns=['Magic','Size','Speed','Base','Max','Dest','Statusfx'])
  96.             print(df)
  97.         else:
  98.             print('There is no such magic known as',M,'magic in the directory currently. Perhaps you made a spelling error?')
  99.            
  100.     if b==4.2:
  101.         print('\n Directory ordered as per size of magics:-\n')
  102.         cur.execute('select * from magicstats order by Size desc')
  103.         data=cur.fetchall()
  104.         df=pd.DataFrame(data,columns=['Magic','Size','Speed','Base','Max','Dest','Statusfx'])
  105.         print(df)
  106.        
  107.     if b==4.3:
  108.         print('\n Directory ordered as per speed of magics:-\n')
  109.         cur.execute('select * from magicstats order by Speed desc')
  110.         data=cur.fetchall()
  111.         df=pd.DataFrame(data,columns=['Magic','Size','Speed','Base','Max','Dest','Statusfx'])
  112.         print(df)
  113.  
  114.     if b==4.4:
  115.         print('\n Directory ordered as per base damage of magics:-\n')
  116.         cur.execute('select * from magicstats order by Basedamage desc')
  117.         data=cur.fetchall()
  118.         df=pd.DataFrame(data,columns=['Magic','Size','Speed','Base','Max','Dest','Statusfx'])
  119.         print(df)
  120.  
  121.     if b==4.5:
  122.         print('\n Directory with only DoT magics:-\n')
  123.         cur.execute('select * from magicstats where basedamage!=maxdamage')
  124.         data=cur.fetchall()
  125.         df=pd.DataFrame(data,columns=['Magic','Size','Speed','Base','Max','Dest','Statusfx'])
  126.         print(df)
  127.        
  128.     if b==4.6:
  129.         print('\n Directory ordered as per destruction potential of magics:-\n')
  130.         cur.execute('select * from magicstats order by Destruction desc')
  131.         data=cur.fetchall()
  132.         df=pd.DataFrame(data,columns=['Magic','Size','Speed','Base','Max','Dest','Statusfx'])
  133.         print(df)
  134.  
  135. #Graphical representation
  136. elif a==5:
  137.     print('\n5.1) Display line graph')
  138.     print('5.2) Display bar graph')
  139.     b=float(input('Please make your choice (5.1 or 5.2) >>>'))
  140.    
  141.     if b==5.1:
  142.         cur.execute('select magic,size,speed,maxdamage,destruction from magicstats')
  143.         data=cur.fetchall()
  144.         df=pd.DataFrame(data)
  145.         plt.plot(df[0],df[1],color='Green',label='Size')
  146.         plt.plot(df[0],df[2],color='Blue',label='Speed')
  147.         plt.plot(df[0],df[3],color='Red',label='Damage')
  148.         plt.plot(df[0],df[4],color='Orange',label='Destruction')
  149.         plt.xlabel('Magic')
  150.         plt.ylabel('Multiplier')
  151.         plt.legend()
  152.         plt.title('Size,Speed,Damage and Destruction multiplier of each magic')
  153.         plt.show()
  154.        
  155.     if b==5.2:
  156.         cur.execute('select magic,size,speed,maxdamage,destruction from magicstats')
  157.         data=cur.fetchall()
  158.         df=pd.DataFrame(data)
  159.         w=0.2
  160.         gap=0.2
  161.         x=np.arange(len(df[0]))*(1+gap)
  162.         plt.bar(x-w*1.5,df[1],w,color='Green',label='Size')
  163.         plt.bar(x-w*0.5,df[2],w,color='Blue',label='Speed')
  164.         plt.bar(x+w*0.5,df[3],w,color='Red',label='Damage')
  165.         plt.bar(x+w*1.5,df[4],w,color='Orange',label='Destruction')
  166.         plt.xlabel('Magic')
  167.         plt.ylabel('Multiplier')
  168.         plt.legend()
  169.         plt.title('Size,Speed,Damage and Destruction multiplier of each magic')
  170.         plt.xticks(x,df[0])
  171.         plt.show()
  172.  
  173. #Exit
  174. elif a==6:
  175.     print('Connection closed')
  176.     con.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement