new feature: output is sorted by composer/opus or composer/collection
This commit is contained in:
@@ -24,7 +24,7 @@ At the moment, an alpha version is undertaken, with these features:
|
||||
- Show possible commands (`h`)
|
||||
- Show mastered movements for activated user (`sm`)
|
||||
- display, if work or movement is mastered from active user when viewing works and movements
|
||||
- (planned) Works are shown sorted (opus, collection e.g. "Walzer", "Sonaten")
|
||||
- Works are shown sorted by composer and opus/work_directory-number (`s`, `smo`) or by composer and collection (`sm`)
|
||||
- (planned) Remove work or movement from being mastered for active user
|
||||
- (planned) Remove user
|
||||
- (planned) Fix known bugs
|
||||
|
||||
35
rep_cli.py
35
rep_cli.py
@@ -14,6 +14,7 @@ class Session:
|
||||
'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'),
|
||||
'smo': (self.show_mastered_opus, 'Show mastered movements for activated user, sorted by opus.'),
|
||||
'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')
|
||||
@@ -104,7 +105,7 @@ class Session:
|
||||
fun_resultstring += f'{key}: {value[1]}\n'
|
||||
return fun_resultstring
|
||||
|
||||
def show_mastered(self, _):
|
||||
def show_mastered(self, _, key='standard'):
|
||||
fun_resultstring = 'Please activate user'
|
||||
if not self.user == -1:
|
||||
sql_command = f'''
|
||||
@@ -118,7 +119,12 @@ class Session:
|
||||
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 sorted(list_of_works):
|
||||
if key == 'opus':
|
||||
list_of_works.sort(key=lambda work_s: work_s.opus_and_wd_for_comparison())
|
||||
else:
|
||||
list_of_works.sort(key=lambda work_s: work_s.sammlung())
|
||||
list_of_works.sort()
|
||||
for work in list_of_works:
|
||||
for mov_number in work.values['movements'].keys():
|
||||
# check if movement is mastered
|
||||
sql_command = f'''
|
||||
@@ -133,6 +139,9 @@ class Session:
|
||||
fun_resultstring += f'{work.id()} {mov_number}. {work.pretty_mov(mov_number)}\n'
|
||||
return fun_resultstring
|
||||
|
||||
def show_mastered_opus(self, arguments):
|
||||
return self.show_mastered(arguments, key='opus')
|
||||
|
||||
def show_movements(self, arguments):
|
||||
work_id = arguments[0]
|
||||
work = work_under_id(work_id, self.db_agent)
|
||||
@@ -171,7 +180,8 @@ class Session:
|
||||
for item in list_of_work_ids:
|
||||
list_of_works.append(work_under_id(item[0], self.db_agent))
|
||||
fun_resultstring = ''
|
||||
for work in list_of_works:
|
||||
list_of_works.sort(key=lambda wo: wo.opus_and_wd_for_comparison())
|
||||
for work in sorted(list_of_works):
|
||||
mastered = self.percentage_of_work_is_mastered(work)
|
||||
if mastered == 100:
|
||||
fun_resultstring += '[x] '
|
||||
@@ -267,6 +277,22 @@ class work_under_id:
|
||||
def id(self):
|
||||
return self.values['id']
|
||||
|
||||
def just_num(self, st):
|
||||
num_str = ''
|
||||
for c in st:
|
||||
if c.isdigit():
|
||||
num_str += c
|
||||
return int(num_str)
|
||||
|
||||
def opus_and_wd_for_comparison(self):
|
||||
op = 9999 # no composer has that many!
|
||||
if not self.values['opus'] is None:
|
||||
op = self.just_num(self.values['opus'])
|
||||
wd = 0 # no directory starts with 0
|
||||
if not self.values['wd_number'] is None:
|
||||
wd = self.just_num(self.values['wd_number'])
|
||||
return (op, wd)
|
||||
|
||||
def pretty_string(self):
|
||||
ret_str = ''
|
||||
for key in ['first_name', 'name',
|
||||
@@ -317,8 +343,7 @@ class work_under_id:
|
||||
return ret_str
|
||||
|
||||
def __lt__(self, other):
|
||||
return ((self.values['name'], self.sammlung()) <
|
||||
(other.values['name'], self.sammlung()))
|
||||
return (self.values['name'] < other.values['name'])
|
||||
|
||||
# End work_under_id
|
||||
|
||||
|
||||
Reference in New Issue
Block a user