Compare commits
10 Commits
83c1d82387
...
refactor
| Author | SHA1 | Date | |
|---|---|---|---|
| 327aae5130 | |||
| 2e9fc3655a | |||
| d549b98a82 | |||
| 76d44e0dfe | |||
| 7352af038b | |||
| 69d701d600 | |||
| b5041dbc54 | |||
| 7f9e806c23 | |||
| ee23e0f0e9 | |||
| b6dc9bd87b |
@@ -18,12 +18,15 @@ At the moment, an alpha version is undertaken, with these features:
|
|||||||
- Set an active user (`a number_of_user`)
|
- Set an active user (`a number_of_user`)
|
||||||
- Show the pieces stored in the database (`s`)
|
- Show the pieces stored in the database (`s`)
|
||||||
- Mark pieces as mastered for the active user (`m number_of_work`)
|
- Mark pieces as mastered for the active user (`m number_of_work`)
|
||||||
- Show pieces by composer (`sc` shows composers, `c number_of_composer` shows pieces)
|
- Show pieces by composer (`c` shows composers, `s number_of_composer` shows pieces)
|
||||||
- Show movements through pieces (`sp piece_number`)
|
- Show movements through works (`sw work_number`)
|
||||||
- Mark movement as mastered for active user (`m number_of_work number_of_movement`)
|
- Mark movement as mastered for active user (`m number_of_work number_of_movement`)
|
||||||
- (planned) Show mastered works/movements for activated user
|
- Show possible commands (`h`)
|
||||||
|
- Show mastered movements for activated user (`sm`)
|
||||||
|
- (planned) display, if work or movement is mastered from active user when viewing works and movements
|
||||||
- (planned) Save recordings per movement in db
|
- (planned) Save recordings per movement in db
|
||||||
- (planned) Listen to saved recordings
|
- (planned) Listen to saved recordings
|
||||||
|
- (planned) Works are shown sorted (opus, collection e.g. "Walzer", "Sonaten")
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
|
|||||||
110
rep_cli.py
110
rep_cli.py
@@ -6,8 +6,20 @@ class Session:
|
|||||||
self.user = -1
|
self.user = -1
|
||||||
self.db_agent = db_agent
|
self.db_agent = db_agent
|
||||||
self.resultstring = 'no results yet'
|
self.resultstring = 'no results yet'
|
||||||
|
self.commands = {'a': (self.set_user, 'Set an active user\n Usage: a number_of_user'),
|
||||||
|
'c': (self.show_composers, 'Shows composers'),
|
||||||
|
'h': (self.show_help, 'Displays this help document'),
|
||||||
|
'm': (self.mark_work_as_mastered, 'Marks work or movement as mastered for the active user\n Usage: m number_of_work, m number_of_work number_of_movement'),
|
||||||
|
'n': (self.create_new_user, 'Creates new user\n Usage: n firstname name'),
|
||||||
|
's': (self.show_works, 'Show the works stored in the database\n Usage: s, s number_of_composer'),
|
||||||
|
'sm': (self.show_mastered, 'Show mastered movements for activated user'),
|
||||||
|
'sw': (self.show_movements, 'Show movements of a work\n Usage: sw work_number'),
|
||||||
|
'su': (self.show_users, 'Show all users'),
|
||||||
|
'q': (self.quit, 'Quits the program')
|
||||||
|
}
|
||||||
|
|
||||||
def set_user(self, db_index):
|
def set_user(self, arguments):
|
||||||
|
db_index = arguments[0]
|
||||||
self.user = db_index
|
self.user = db_index
|
||||||
return 'User set'
|
return 'User set'
|
||||||
|
|
||||||
@@ -27,39 +39,24 @@ class Session:
|
|||||||
|
|
||||||
def invoke_command(self, command, arguments):
|
def invoke_command(self, command, arguments):
|
||||||
self.resultstring = ''
|
self.resultstring = ''
|
||||||
if command == 'a':
|
if command in self.commands.keys():
|
||||||
self.resultstring += self.set_user(arguments[0])
|
self.resultstring += self.commands[command][0](arguments)
|
||||||
elif command == 'c':
|
|
||||||
self.resultstring += self.show_composers()
|
|
||||||
elif command == 'm':
|
|
||||||
self.resultstring += self.mark_work_as_mastered(arguments)
|
|
||||||
elif command == 'n':
|
|
||||||
self.create_new_user(arguments[0], arguments[1])
|
|
||||||
self.resultstring += f'Created new user {arguments[0]} {arguments[1]}.'
|
|
||||||
elif command == 's':
|
|
||||||
self.resultstring += self.show_works()
|
|
||||||
elif command == 'sc':
|
|
||||||
self.resultstring += self.show_works(restraint=f'comp_id = {arguments[0]}')
|
|
||||||
elif command == 'sp':
|
|
||||||
self.resultstring += self.show_movements(arguments[0])
|
|
||||||
elif command == 'su':
|
|
||||||
self.resultstring += self.show_users()
|
|
||||||
elif command == 'q':
|
|
||||||
self.resultstring += 'Bye-bye'
|
|
||||||
else:
|
else:
|
||||||
self.resultstring += 'Could not understand command.'
|
self.resultstring += 'Could not understand command.'
|
||||||
|
|
||||||
def result(self):
|
def result(self):
|
||||||
return self.resultstring
|
return self.resultstring
|
||||||
|
|
||||||
def create_new_user(self, first_name, name):
|
def create_new_user(self, arguments):
|
||||||
|
first_name, name = arguments[0], arguments[1]
|
||||||
sql_command = f'''
|
sql_command = f'''
|
||||||
INSERT INTO pianist (first_name, sec_name)
|
INSERT INTO pianist (first_name, sec_name)
|
||||||
VALUES ("{first_name}", "{name}");
|
VALUES ("{first_name}", "{name}");
|
||||||
'''
|
'''
|
||||||
self.db_agent.execute(sql_command)
|
self.db_agent.execute(sql_command)
|
||||||
|
return f'Created new user {first_name} {name}.'
|
||||||
|
|
||||||
def show_composers(self):
|
def show_composers(self, _):
|
||||||
sql_command = '''
|
sql_command = '''
|
||||||
SELECT id, first_name, name
|
SELECT id, first_name, name
|
||||||
FROM composer
|
FROM composer
|
||||||
@@ -71,14 +68,57 @@ class Session:
|
|||||||
fun_resultstring += f'{item[0]}: {item[2]}, {item[1]}\n'
|
fun_resultstring += f'{item[0]}: {item[2]}, {item[1]}\n'
|
||||||
return fun_resultstring
|
return fun_resultstring
|
||||||
|
|
||||||
def show_movements(self, work_id):
|
def show_help(self, arguments):
|
||||||
|
fun_resultstring = ''
|
||||||
|
if len(arguments) > 0:
|
||||||
|
qu_com = arguments[0]
|
||||||
|
if qu_com in self.commands:
|
||||||
|
fun_resultstring += f'{qu_com}: {self.commands[qu_com][1]}'
|
||||||
|
else:
|
||||||
|
fun_resultstring += f'Command {qu_com} not known, for help press h'
|
||||||
|
else:
|
||||||
|
for key, value in self.commands.items():
|
||||||
|
fun_resultstring += f'{key}: {value[1]}\n'
|
||||||
|
return fun_resultstring
|
||||||
|
|
||||||
|
def show_mastered(self, _):
|
||||||
|
fun_resultstring = 'Please activate user'
|
||||||
|
if not self.user == -1:
|
||||||
|
sql_command = f'''
|
||||||
|
SELECT work_id
|
||||||
|
FROM is_able_to_play
|
||||||
|
WHERE pianist_id = {self.user}
|
||||||
|
GROUP BY work_id
|
||||||
|
'''
|
||||||
|
list_of_work_ids = self.db_agent.execute(sql_command).fetchall()
|
||||||
|
list_of_works = list()
|
||||||
|
for item in list_of_work_ids:
|
||||||
|
list_of_works.append(work_under_id(item[0], self.db_agent))
|
||||||
|
fun_resultstring = 'All mastered movements:\n'
|
||||||
|
for work in list_of_works:
|
||||||
|
for mov_number in work.values['movements'].keys():
|
||||||
|
# check if movement is mastered
|
||||||
|
sql_command = f'''
|
||||||
|
SELECT *
|
||||||
|
FROM is_able_to_play
|
||||||
|
WHERE work_id = {work.id()}
|
||||||
|
AND mov_id = {mov_number}
|
||||||
|
AND pianist_id = {self.user}
|
||||||
|
'''
|
||||||
|
is_mastered = len(self.db_agent.execute(sql_command).fetchall()) > 0
|
||||||
|
if is_mastered:
|
||||||
|
fun_resultstring += f'{work.id()} {mov_number}. {work.pretty_mov(mov_number)}\n'
|
||||||
|
return fun_resultstring
|
||||||
|
|
||||||
|
def show_movements(self, arguments):
|
||||||
|
work_id = arguments[0]
|
||||||
work = work_under_id(work_id, self.db_agent)
|
work = work_under_id(work_id, self.db_agent)
|
||||||
fun_resultstring = ''
|
fun_resultstring = ''
|
||||||
for mov_number in work.values['movements'].keys():
|
for mov_number in work.values['movements'].keys():
|
||||||
fun_resultstring += f'{mov_number}. {work.pretty_mov(mov_number)}\n'
|
fun_resultstring += f'{mov_number}. {work.pretty_mov(mov_number)}\n'
|
||||||
return fun_resultstring
|
return fun_resultstring
|
||||||
|
|
||||||
def show_users(self):
|
def show_users(self, _):
|
||||||
sql_command = '''
|
sql_command = '''
|
||||||
SELECT * FROM pianist;
|
SELECT * FROM pianist;
|
||||||
'''
|
'''
|
||||||
@@ -88,7 +128,11 @@ class Session:
|
|||||||
fun_resultstring += f'{item[0]}: {item[1]} {item[2]}\n'
|
fun_resultstring += f'{item[0]}: {item[1]} {item[2]}\n'
|
||||||
return fun_resultstring
|
return fun_resultstring
|
||||||
|
|
||||||
def show_works(self, restraint='1=1'):
|
def show_works(self, arguments):
|
||||||
|
if len(arguments) > 0:
|
||||||
|
restraint = f'comp_id = {arguments[0]}'
|
||||||
|
else:
|
||||||
|
restraint = '1 = 1'
|
||||||
sql_command = f'''
|
sql_command = f'''
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM work
|
FROM work
|
||||||
@@ -108,7 +152,7 @@ class Session:
|
|||||||
work_id = arguments[0]
|
work_id = arguments[0]
|
||||||
resultstring = 'adding:\n'
|
resultstring = 'adding:\n'
|
||||||
work = work_under_id(work_id, self.db_agent)
|
work = work_under_id(work_id, self.db_agent)
|
||||||
if len(arguments) > 1:
|
if len(arguments) > 1: # in case there is a movement number given
|
||||||
mov_number = int(arguments[1])
|
mov_number = int(arguments[1])
|
||||||
sql_command = f'''
|
sql_command = f'''
|
||||||
INSERT INTO is_able_to_play (work_id, mov_id, pianist_id)
|
INSERT INTO is_able_to_play (work_id, mov_id, pianist_id)
|
||||||
@@ -116,7 +160,7 @@ class Session:
|
|||||||
'''
|
'''
|
||||||
self.db_agent.execute(sql_command)
|
self.db_agent.execute(sql_command)
|
||||||
resultstring += f'{work.pretty_mov(mov_number)}\n'
|
resultstring += f'{work.pretty_mov(mov_number)}\n'
|
||||||
else:
|
else: # mark all movements of the work as mastered
|
||||||
for mov_number in work.values['movements'].keys():
|
for mov_number in work.values['movements'].keys():
|
||||||
sql_command = f'''
|
sql_command = f'''
|
||||||
INSERT INTO is_able_to_play (work_id, mov_id, pianist_id)
|
INSERT INTO is_able_to_play (work_id, mov_id, pianist_id)
|
||||||
@@ -126,6 +170,9 @@ class Session:
|
|||||||
resultstring += f'{work.pretty_mov(mov_number)}\n'
|
resultstring += f'{work.pretty_mov(mov_number)}\n'
|
||||||
return resultstring
|
return resultstring
|
||||||
|
|
||||||
|
def quit(self, _):
|
||||||
|
return 'Bye bye!'
|
||||||
|
|
||||||
# End session
|
# End session
|
||||||
|
|
||||||
class work_under_id:
|
class work_under_id:
|
||||||
@@ -163,7 +210,7 @@ class work_under_id:
|
|||||||
saetze = dict()
|
saetze = dict()
|
||||||
nummern = set()
|
nummern = set()
|
||||||
suw_liste = self.reader.execute(sql_suw).fetchall()
|
suw_liste = self.reader.execute(sql_suw).fetchall()
|
||||||
# 0 work_id, 1 mov_number, 2 numb, 3 designation, 4 mus_key, 5 recording
|
# 0 work_id, 1 mov_number, 2 numb, 3 designation, 4 mus_key
|
||||||
for satz in suw_liste:
|
for satz in suw_liste:
|
||||||
saetze[satz[1]] = satz[2], satz[3], satz[4]
|
saetze[satz[1]] = satz[2], satz[3], satz[4]
|
||||||
if not satz[2] is None:
|
if not satz[2] is None:
|
||||||
@@ -236,10 +283,10 @@ class work_under_id:
|
|||||||
|
|
||||||
# End work_under_id
|
# End work_under_id
|
||||||
|
|
||||||
def parse_user_input(user_in):
|
def parse_user_input(user_in, session):
|
||||||
split_user_in = user_in.split()
|
split_user_in = user_in.split()
|
||||||
command = split_user_in[0]
|
command = split_user_in[0]
|
||||||
if command in ('a', 'c', 'm', 'n', 'q', 's', 'sc', 'sp', 'su'):
|
if command in session.commands.keys():
|
||||||
arguments = split_user_in[1:]
|
arguments = split_user_in[1:]
|
||||||
return (command, arguments)
|
return (command, arguments)
|
||||||
else:
|
else:
|
||||||
@@ -249,9 +296,8 @@ def command_line_loop(session):
|
|||||||
user_in = ''
|
user_in = ''
|
||||||
while not user_in == 'q':
|
while not user_in == 'q':
|
||||||
user_in = input(f'Piano-Repertoire: {session.get_active_user()} >>> ')
|
user_in = input(f'Piano-Repertoire: {session.get_active_user()} >>> ')
|
||||||
command, arguments = parse_user_input(user_in)
|
command, arguments = parse_user_input(user_in, session)
|
||||||
session.invoke_command(command, arguments)
|
session.invoke_command(command, arguments)
|
||||||
# print(f'command: {command}, arguments: {arguments}')
|
|
||||||
print(session.result())
|
print(session.result())
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ CREATE TABLE movement (
|
|||||||
numb VARCHAR(15),
|
numb VARCHAR(15),
|
||||||
designation VARCHAR(63),
|
designation VARCHAR(63),
|
||||||
mus_key VARCHAR(15),
|
mus_key VARCHAR(15),
|
||||||
recording BLOB,
|
|
||||||
PRIMARY KEY(work_id, mov_number),
|
PRIMARY KEY(work_id, mov_number),
|
||||||
FOREIGN KEY(work_id) REFERENCES work(id)
|
FOREIGN KEY(work_id) REFERENCES work(id)
|
||||||
);
|
);
|
||||||
@@ -50,6 +49,7 @@ CREATE TABLE is_able_to_play(
|
|||||||
mov_id INTEGER NOT NULL,
|
mov_id INTEGER NOT NULL,
|
||||||
pianist_id INTEGER NOT NULL,
|
pianist_id INTEGER NOT NULL,
|
||||||
days_to_practice INTEGER DEFAULT 7,
|
days_to_practice INTEGER DEFAULT 7,
|
||||||
|
recording VARCHAR(255),
|
||||||
PRIMARY KEY(work_id, mov_id, pianist_id),
|
PRIMARY KEY(work_id, mov_id, pianist_id),
|
||||||
FOREIGN KEY(work_id, mov_id) REFERENCES movement(work_id, mov_number),
|
FOREIGN KEY(work_id, mov_id) REFERENCES movement(work_id, mov_number),
|
||||||
FOREIGN KEY(pianist_id) REFERENCES pianist(id)
|
FOREIGN KEY(pianist_id) REFERENCES pianist(id)
|
||||||
|
|||||||
Reference in New Issue
Block a user