reorganizing
This commit is contained in:
+2
-66
@@ -1,5 +1,7 @@
|
|||||||
#!/usr/bin/env luajit
|
#!/usr/bin/env luajit
|
||||||
|
local filters = require "lib.filters"
|
||||||
local json = require "lib.dkjson"
|
local json = require "lib.dkjson"
|
||||||
|
local sort_orders = require "lib.sort_orders"
|
||||||
math.randomseed(os.time())
|
math.randomseed(os.time())
|
||||||
|
|
||||||
local default_file = "books.json"
|
local default_file = "books.json"
|
||||||
@@ -50,72 +52,6 @@ local get_random_order = function(array)
|
|||||||
return order
|
return order
|
||||||
end
|
end
|
||||||
|
|
||||||
local filters = {
|
|
||||||
all_books = function(book)
|
|
||||||
if book.hidden then return false end
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
unread = function(book)
|
|
||||||
if book.hidden then return false end
|
|
||||||
if book.progress == 0 then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end,
|
|
||||||
read = function(book)
|
|
||||||
if book.hidden then return false end
|
|
||||||
if book.progress == 1 then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end,
|
|
||||||
in_progress = function(book)
|
|
||||||
if book.hidden then return false end
|
|
||||||
if book.progress > 0 and book.progress < 1 then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end,
|
|
||||||
exclude_series = function(book)
|
|
||||||
if book.hidden then return false end
|
|
||||||
if book.series and not (book.title or book.author) then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
|
|
||||||
local sort_orders
|
|
||||||
sort_orders = {
|
|
||||||
most_progress = function(A, B)
|
|
||||||
return A.progress > B.progress
|
|
||||||
end,
|
|
||||||
least_progress = function(A, B)
|
|
||||||
return A.progress < B.progress
|
|
||||||
end,
|
|
||||||
highest_priority = function(A, B)
|
|
||||||
return A.priority > B.priority
|
|
||||||
end,
|
|
||||||
lowest_priority = function(A, B)
|
|
||||||
return A.priority < B.priority
|
|
||||||
end,
|
|
||||||
most_pages_remaining = function(A, B, data)
|
|
||||||
if not (A.pages and B.pages) then -- if pages is unknown for both, fallback to percentage
|
|
||||||
return A.progress < B.progress
|
|
||||||
end
|
|
||||||
local average_page_count = data.total_pages / data.books_with_page_count
|
|
||||||
if not (average_page_count == average_page_count) then
|
|
||||||
average_page_count = 300 -- based on average novel length
|
|
||||||
end
|
|
||||||
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
|
|
||||||
return a > b
|
|
||||||
end,
|
|
||||||
fewest_pages_remaining = function(A, B, data)
|
|
||||||
return not sort_orders.most_pages_remaining(A, B, data)
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
|
|
||||||
local get_display_name = function(book)
|
local get_display_name = function(book)
|
||||||
local result = ""
|
local result = ""
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
local filters = {
|
||||||
|
all_books = function(book)
|
||||||
|
if book.hidden then return false end
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
unread = function(book)
|
||||||
|
if book.hidden then return false end
|
||||||
|
if book.progress == 0 then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end,
|
||||||
|
read = function(book)
|
||||||
|
if book.hidden then return false end
|
||||||
|
if book.progress == 1 then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end,
|
||||||
|
in_progress = function(book)
|
||||||
|
if book.hidden then return false end
|
||||||
|
if book.progress > 0 and book.progress < 1 then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end,
|
||||||
|
exclude_series = function(book)
|
||||||
|
if book.hidden then return false end
|
||||||
|
if book.series and not (book.title or book.author) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
|
return filters
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
local sort_orders
|
||||||
|
sort_orders = {
|
||||||
|
most_progress = function(A, B)
|
||||||
|
return A.progress > B.progress
|
||||||
|
end,
|
||||||
|
least_progress = function(A, B)
|
||||||
|
return A.progress < B.progress
|
||||||
|
end,
|
||||||
|
highest_priority = function(A, B)
|
||||||
|
return A.priority > B.priority
|
||||||
|
end,
|
||||||
|
lowest_priority = function(A, B)
|
||||||
|
return A.priority < B.priority
|
||||||
|
end,
|
||||||
|
most_pages_remaining = function(A, B, data)
|
||||||
|
if not (A.pages and B.pages) then -- if pages is unknown for both, fallback to percentage
|
||||||
|
return A.progress < B.progress
|
||||||
|
end
|
||||||
|
local average_page_count = data.total_pages / data.books_with_page_count
|
||||||
|
if not (average_page_count == average_page_count) then
|
||||||
|
average_page_count = 300 -- based on average novel length
|
||||||
|
end
|
||||||
|
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
|
||||||
|
return a > b
|
||||||
|
end,
|
||||||
|
fewest_pages_remaining = function(A, B, data)
|
||||||
|
return not sort_orders.most_pages_remaining(A, B, data)
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
|
return sort_orders
|
||||||
Reference in New Issue
Block a user