-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
257 lines (237 loc) · 8.04 KB
/
main.py
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# Importing Libraries
import pandas as pd
import matplotlib.pyplot as plt
from numpy import random
import mysql.connector
# Defining Colours for Printing Purposes
red = (255, 51, 51)
yellow = (255, 255, 102)
green = (102, 255, 102)
blue = (102, 178, 255)
purple = (204, 153, 255)
orange = (255, 178, 102)
dark_blue = (102, 102, 255)
pink = (255, 153, 204)
# Functions for printing a coloured text
def print_colored(color, text):
print(f"\033[38;2;{color[0]};{color[1]};{color[2]}m{text}\033[38;2;255;255;255m")
print()
def input_colored(color, text):
input1 = input(
f"\033[38;2;{color[0]};{color[1]};{color[2]}m{text}\033[38;2;255;255;255m"
)
print()
return input1
# MYSQL Connection
conn = mysql.connector.connect(user="root", password="password", database="project")
cursor = conn.cursor()
cursor.execute("SELECT * FROM stats")
# Reading the database as a dataframe
df = pd.DataFrame(cursor.fetchall()).astype(float)
df.columns = cursor.column_names
# Welcome Screen
print_colored(
purple,
"""
───▄▀▀▀▄▄▄▄▄▄▄▀▀▀▄───
───█▒▒░░░░░░░░░▒▒█───
────█░░█░░░░░█░░█──── WELCOME TO SONG STAT MANAGEMENT SYSTEM
─▄▄──█░░░▀█▀░░░█──▄▄─
█░░█─▀▄░░░░░░░▄▀─█░░█
█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█ - Made by: Sakshham & Vasundhra
█░░╦─╦╔╗╦─╔╗╔╗╔╦╗╔╗░░█ Bhagat Sharma
█░░║║║╠─║─║─║║║║║╠─░░█
█░░╚╩╝╚╝╚╝╚╝╚╝╩─╩╚╝░░█
""",
)
# Define Function For HISTOGRAM
def histogram():
print_colored(orange, "\n: SELECT DATA :")
print_colored(
pink,
"Which data would you like to view? \n (1) Danceability \n (2) Energy \n (3) Tempo \n (4) Time_Signature ",
)
reply5 = input_colored(blue, "Select one - (1)/(2)/(3)/(4) : ")
if reply5 == "1":
df["Danceability"].plot(kind="hist", color="yellow", edgecolor="black")
plt.show()
elif reply5 == "2":
df["Energy"].plot(kind="hist", color="red", edgecolor="black")
plt.show()
elif reply5 == "3":
df["Tempo"].plot(kind="hist", color="green", edgecolor="black")
plt.show()
elif reply5 == "4":
df["Time_signature"].plot(kind="hist", color="purple", edgecolor="black")
plt.show()
else:
print_colored(red, "Choose a valid option")
return
# Define Common Function For PLOTTING
def axis_select(type: str):
random_color = str(
random.choice(
["red", "green", "blue", "yellow", "purple", "pink", "black", "brown"]
)
)
# random_marker = str(random.choice(["o", "d"]))
# print(random_marker)
print_colored(orange, "\n: SELECT AXES : ")
print_colored(
yellow, " (1) Danceability \n (2) Energy \n (3) Tempo \n (4) Time_signature"
)
reply3 = input_colored(blue, "Select X-axis - (1)/(2)/(3)/(4): ")
reply4 = input_colored(blue, "Select Y-axis - (1)/(2)/(3)/(4): ")
if reply3 == "1" and reply4 == "2":
df.plot(
kind=type,
color=random_color,
x="Danceability",
y="Energy",
)
elif reply3 == "1" and reply4 == "3":
df.plot(
kind=type,
color=random_color,
x="Danceability",
y="Tempo",
)
elif reply3 == "1" and reply4 == "4":
df.plot(
kind=type,
color=random_color,
x="Danceability",
y="Time_signature",
)
elif reply3 == "2" and reply4 == "1":
df.plot(
kind=type,
color=random_color,
x="Energy",
y="Danceability",
)
elif reply3 == "2" and reply4 == "3":
df.plot(
kind=type,
color=random_color,
x="Energy",
y="Tempo",
)
elif reply3 == "2" and reply4 == "4":
df.plot(
kind=type,
color=random_color,
x="Energy",
y="Time_signature",
)
elif reply3 == "3" and reply4 == "1":
df.plot(
kind=type,
color=random_color,
x="Tempo",
y="Danceability",
)
elif reply3 == "3" and reply4 == "2":
df.plot(
kind=type,
color=random_color,
x="Tempo",
y="Energy",
)
elif reply3 == "3" and reply4 == "4":
df.plot(
kind=type,
color=random_color,
x="Tempo",
y="Time_signature",
)
elif reply3 == "4" and reply4 == "1":
df.plot(
kind=type,
color=random_color,
x="Time_signature",
y="Danceability",
)
elif reply3 == "4" and reply4 == "2":
df.plot(
kind=type,
color=random_color,
x="Time_signature",
y="Energy",
)
elif reply3 == "4" and reply4 == "3":
df.plot(
kind=type,
color=random_color,
x="Time_signature",
y="Tempo",
)
else:
print_colored(red, "Choose a valid option")
return
print(f": SHOWING A GRAPH OF TYPE *{type.upper()}*")
plt.show()
# Define Function For Deleting The DATA
def delete(rec):
cursor.execute(f"DELETE from stats WHERE Sno = {rec}")
cursor.execute("ALTER TABLE stats DROP Sno")
cursor.execute("ALTER TABLE stats ADD Sno INT AUTO_INCREMENT PRIMARY KEY FIRST")
conn.commit()
print_colored(green, "Deleted Record")
# Define Function For Adding The DATA
def add(Danceability, Energy, Tempo, Time_signature):
cursor.execute(
f"INSERT into stats(Danceability, Energy, Tempo, Time_signature) VALUES({Danceability}, {Energy}, {Tempo}, {Time_signature})"
)
conn.commit()
print_colored(green, "Added a new record")
# Main Screen
while True:
print_colored(
dark_blue,
"What do you want to do ? \n (1) View Graph \n (2) Edit Data \n (3) View Data \n (4) Exit",
)
reply = input_colored(blue, "Select one - (1)/(2)/(3)/(4) : ")
if reply == "1":
print_colored(orange, "\n: VIEW GRAPHS : ")
print_colored(
green,
"Which type of graph do you want to view? \n (1) Line Graph \n (2) Bar Graph \n (3) Histogram \n (4) Scatter",
)
reply2 = input_colored(blue, "Select one - (1)/(2)/(3)/(4): ")
if reply2 == "1":
axis_select("line")
elif reply2 == "2":
axis_select("bar")
elif reply2 == "3":
histogram()
elif reply2 == "4":
axis_select("scatter")
else:
print_colored(red, "Choose a valid option")
elif reply == "2":
print_colored(orange, "What do you want to do?\n (1) Add \n (2) Delete")
action = input_colored(blue, "Select one - (1)/(2): ")
if action == "1":
danceability = float(
input_colored(dark_blue, "Enter value for Danceability: ")
)
energy = float(input_colored(dark_blue, "Enter value for Energy: "))
tempo = float(input_colored(dark_blue, "Enter value for Tempo: "))
ts = int(input_colored(dark_blue, "Enter value for Time Signature: "))
add(danceability, energy, tempo, ts)
break
if action == "2":
rec = int(input_colored(blue, "Enter which record you want to delete?: "))
if rec <= len(df.index):
delete(rec)
else:
print_colored(red, "Choose a valid index")
break
elif reply == "3":
print_colored(green, df.to_string(index=False))
elif reply == "4":
print_colored(purple, "Thanks for using ^^")
exit()
else:
print_colored(red, "Choose a valid option")