mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Merge branch 'master' of https://github.com/cbhaley/calibre
This commit is contained in:
commit
2ed36fb746
@ -121,21 +121,8 @@ class TagTreeItem(object): # {{{
|
|||||||
return self.tag.avg_rating
|
return self.tag.avg_rating
|
||||||
if not self.children:
|
if not self.children:
|
||||||
return self.tag.avg_rating # leaf node, avg_rating is correct
|
return self.tag.avg_rating # leaf node, avg_rating is correct
|
||||||
if self.cached_average_rating is not None:
|
if self.cached_average_rating is None:
|
||||||
return self.cached_average_rating
|
raise ValueError('Must compute average rating for tag ' + self.tag.original_name)
|
||||||
total = num = 0
|
|
||||||
for child in self.children:
|
|
||||||
r = child.average_rating
|
|
||||||
if r:
|
|
||||||
total += 1
|
|
||||||
num += r
|
|
||||||
if self.tag.avg_rating:
|
|
||||||
total += 1
|
|
||||||
num += self.tag.avg_rating
|
|
||||||
try:
|
|
||||||
self.cached_average_rating = num/float(total)
|
|
||||||
except ZeroDivisionError:
|
|
||||||
self.cached_average_rating = 0
|
|
||||||
return self.cached_average_rating
|
return self.cached_average_rating
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -488,7 +475,7 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
components = [name]
|
components = [name]
|
||||||
return components
|
return components
|
||||||
|
|
||||||
def process_one_node(category, collapse_model, state_map): # {{{
|
def process_one_node(category, collapse_model, book_rating_map, state_map): # {{{
|
||||||
collapse_letter = None
|
collapse_letter = None
|
||||||
key = category.category_key
|
key = category.category_key
|
||||||
is_gst = category.is_gst
|
is_gst = category.is_gst
|
||||||
@ -625,6 +612,8 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
node_parent = child_map[(comp,tag.category)]
|
node_parent = child_map[(comp,tag.category)]
|
||||||
t = node_parent.tag
|
t = node_parent.tag
|
||||||
t.is_hierarchical = '5state' if tag.category != 'search' else '3state'
|
t.is_hierarchical = '5state' if tag.category != 'search' else '3state'
|
||||||
|
if tag.id_set is not None and t.id_set is not None:
|
||||||
|
t.id_set = t.id_set | tag.id_set
|
||||||
intermediate_nodes[t.original_name, t.category] = t
|
intermediate_nodes[t.original_name, t.category] = t
|
||||||
else:
|
else:
|
||||||
if i < len(components)-1:
|
if i < len(components)-1:
|
||||||
@ -652,14 +641,24 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
node_parent = self.create_node(parent=node_parent, data=t,
|
node_parent = self.create_node(parent=node_parent, data=t,
|
||||||
tooltip=tt, icon_map=self.icon_state_map)
|
tooltip=tt, icon_map=self.icon_state_map)
|
||||||
child_map[(comp,tag.category)] = node_parent
|
child_map[(comp,tag.category)] = node_parent
|
||||||
|
|
||||||
|
# Correct the average rating for the node
|
||||||
|
total = count = 0
|
||||||
|
for book_id in t.id_set:
|
||||||
|
rating = book_rating_map.get(book_id, 0)
|
||||||
|
if rating:
|
||||||
|
total += rating/2.0
|
||||||
|
count += 1
|
||||||
|
node_parent.cached_average_rating = float(total)/count if total and count else 0
|
||||||
return
|
return
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# Build the entire node tree. Note that category_nodes is in field
|
# Build the entire node tree. Note that category_nodes is in field
|
||||||
# metadata order so the user categories will be at the end
|
# metadata order so the user categories will be at the end
|
||||||
for category in self.category_nodes:
|
with self.db.new_api.safe_read_lock: # needed as we read from book_value_map
|
||||||
process_one_node(category, collapse_model,
|
for category in self.category_nodes:
|
||||||
state_map.get(category.category_key, {}))
|
process_one_node(category, collapse_model, self.db.new_api.fields['rating'].book_value_map,
|
||||||
|
state_map.get(category.category_key, {}))
|
||||||
|
|
||||||
# Fix up the node tree, reordering as needed and deleting undisplayed nodes
|
# Fix up the node tree, reordering as needed and deleting undisplayed nodes
|
||||||
new_children = []
|
new_children = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user