Added Calice Score; Renamed Calice to Calice Rating

This commit is contained in:
Dominik Moritz Roth 2022-03-19 12:18:14 +01:00
parent f9c70a8ee4
commit 8e8592bb29

View File

@ -554,36 +554,47 @@ class calibreDB():
@classmethod
def _requireCaliceColumn(cls):
if not 'calice' in cls.getCustomColumns():
raise Error('Custom Column missing from CalibreDB. Create it using the "createCaliceColumn" command.')
cols = cls.getCustomColumns()
avai = ['calice_score' in cols, 'calice_rating' in cols]
if not any(avai):
raise Error('Custom Columns missing from CalibreDB. Create columns for "Calice Score" and/or "Calice Rating" using the "createCaliceColumn" command.')
return avai
@classmethod
def createCaliceColumn(cls):
if 'calice' in cls.getCustomColumns():
def createCaliceRatingColumn(cls):
if 'calice_rating' in cls.getCustomColumns():
raise Error('Custom Column already exists.')
cls._getTxt("add_custom_column calice 'Calice AI Rating' rating")
cls._getTxt("add_custom_column calice_rating 'Calice Rating' rating")
@classmethod
def writeCaliceColumn(cls, bookId, rating):
cls.writeCaliceColumnMultiple({bookId: rating})
def createCaliceScoreColumn(cls):
if 'calice_score' in cls.getCustomColumns():
raise Error('Custom Column already exists.')
cls._getTxt("add_custom_column calice_score 'Calice Score' float")
@classmethod
def writeCaliceColumnMultiple(cls, ratings):
def writeCaliceColumn(cls, bookId, score):
cls.writeCaliceColumnMultiple({bookId: score})
@classmethod
def writeCaliceColumnMultiple(cls, scores):
from tqdm.auto import tqdm
cls._requireCaliceColumn()
for bookId in tqdm(ratings):
rating = ratings[bookId]
cls._getTxt('set_custom calice '+str(bookId)+' '+str(int(round(rating))))
sco, rat = cls._requireCaliceColumn()
for bookId in tqdm(scores):
score = scores[bookId]
if sco:
cls._getTxt('set_custom calice_score '+str(bookId)+' '+str(score))
if rat:
cls._getTxt('set_custom calice_rating '+str(bookId)+' '+str(int(round(score))))
def calice(G):
ratings = {}
scores = {}
for n in list(G.nodes):
node = G.nodes[n]
if node['t'] in ['book']:
if 'score' in node and node['score'] != None:
ratings[node['calibreID']] = node['score']
print('Inserting '+str(len(ratings))+' ratings into the calibreDB')
calibreDB.writeCaliceColumnMultiple(ratings)
scores[node['calibreID']] = node['score']
calibreDB.writeCaliceColumnMultiple(scores)
print('Done.')
def remove_html_tags(text):
@ -1420,7 +1431,9 @@ def cliInterface(imgDef=False):
p_new.add_argument('-n', type=int, default=10, help='number of books to recommend')
p_col = cmds.add_parser('calice', description="TODO", aliases=[])
p_createCol = cmds.add_parser('createCaliceColumn', description="TODO", aliases=[])
p_createCol.add_argument('type', choices=['score', 'rating', 'both'])
p_full = cmds.add_parser('full', description="TODO", aliases=[])
@ -1501,9 +1514,13 @@ def mainCLI(args):
calice(G)
exit()
elif args.cmd=="createCaliceColumn":
calibreDB.createCaliceColumn()
print('[*] Column was created.')
print('[i] To allow displaying half-stars, please active them manually in the calibre-settings.')
if args.type in ['score', 'both']:
calibreDB.createCaliceScoreColumn()
print('[*] Column "Calice Score" was created.')
if args.type in ['rating', 'both']:
calibreDB.createCaliceRatingColumn()
print('[*] Column "Calice Rating" was created.')
print('[i] To allow displaying half-stars, please active them manually in the calibre-settings.')
exit()
else:
raise Exception("Bad")