close #6 total_pages is being used for sorting
This commit is contained in:
+13
-9
@@ -92,20 +92,17 @@ sort_orders = {
|
|||||||
lowest_priority = function(A, B)
|
lowest_priority = function(A, B)
|
||||||
return A.priority < B.priority
|
return A.priority < B.priority
|
||||||
end,
|
end,
|
||||||
most_pages_remaining = function(A, B)
|
most_pages_remaining = function(A, B, data)
|
||||||
if not (A.pages and B.pages) then -- if pages is unknown for both, fallback to percentage
|
if not (A.pages and B.pages) then -- if pages is unknown for both, fallback to percentage
|
||||||
return A.progress < B.progress
|
return A.progress < B.progress
|
||||||
end
|
end
|
||||||
-- TODO figure out an elegant way to pass the required values here
|
local average_page_count = data.total_pages / #data.books
|
||||||
-- local average_page_count = data.total_pages / #data.books
|
|
||||||
-- the previous default wasn't working for my desires, so I'm using a realistic default now
|
|
||||||
local average_page_count = 300
|
|
||||||
local a = (A.pages or average_page_count) - (A.pages or average_page_count) * A.progress
|
local a = (A.pages or average_page_count) - (A.pages or average_page_count) * A.progress
|
||||||
local b = (B.pages or average_page_count) - (B.pages or average_page_count) * B.progress
|
local b = (B.pages or average_page_count) - (B.pages or average_page_count) * B.progress
|
||||||
return a > b
|
return a > b
|
||||||
end,
|
end,
|
||||||
fewest_pages_remaining = function(A, B)
|
fewest_pages_remaining = function(A, B, data)
|
||||||
return not sort_orders.most_pages_remaining(A, B)
|
return not sort_orders.most_pages_remaining(A, B, data)
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,6 +324,13 @@ end
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local prep_sort_function = function(data, sort_function)
|
||||||
|
-- this allows me to pass data as a third argument for functions that use it
|
||||||
|
return function(A, B)
|
||||||
|
return sort_function(A, B, data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local get_books_by_preset = function(data, preset_name)
|
local get_books_by_preset = function(data, preset_name)
|
||||||
local selected_books = {}
|
local selected_books = {}
|
||||||
for i = 1, #data.books do
|
for i = 1, #data.books do
|
||||||
@@ -335,7 +339,7 @@ local get_books_by_preset = function(data, preset_name)
|
|||||||
selected_books[#selected_books + 1] = book
|
selected_books[#selected_books + 1] = book
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.sort(selected_books, sort_orders[data.defaults[preset_name].sort])
|
table.sort(selected_books, prep_sort_function(sort_orders[data.defaults[preset_name].sort], data))
|
||||||
return selected_books
|
return selected_books
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -368,7 +372,7 @@ local print_list = function(data, options)
|
|||||||
selected_books[#selected_books + 1] = book
|
selected_books[#selected_books + 1] = book
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.sort(selected_books, sort_orders[options[2]])
|
table.sort(selected_books, prep_sort_function(sort_orders[options[2]], data))
|
||||||
|
|
||||||
local limit = 10
|
local limit = 10
|
||||||
if options[3] == "all" then
|
if options[3] == "all" then
|
||||||
|
|||||||
Reference in New Issue
Block a user