Added a dark-mode
This commit is contained in:
parent
5fc161fcc0
commit
f27d89e43d
39
caliGraph.py
39
caliGraph.py
@ -437,7 +437,7 @@ def loadBooksFromDB():
|
|||||||
return json.loads(os.popen("calibredb list --for-machine -f all").read())
|
return json.loads(os.popen("calibredb list --for-machine -f all").read())
|
||||||
|
|
||||||
|
|
||||||
def buildBookGraph(books):
|
def buildBookGraph(books, darkMode=False):
|
||||||
G = nx.Graph()
|
G = nx.Graph()
|
||||||
|
|
||||||
# Books
|
# Books
|
||||||
@ -462,7 +462,7 @@ def buildBookGraph(books):
|
|||||||
return G
|
return G
|
||||||
|
|
||||||
|
|
||||||
def graphAddAuthors(G, books):
|
def graphAddAuthors(G, books, darkMode=False):
|
||||||
for author in getAllAuthors(books):
|
for author in getAllAuthors(books):
|
||||||
G.add_node('a/'+author, color='green', t='author', label=author)
|
G.add_node('a/'+author, color='green', t='author', label=author)
|
||||||
for book in books:
|
for book in books:
|
||||||
@ -471,7 +471,7 @@ def graphAddAuthors(G, books):
|
|||||||
return G
|
return G
|
||||||
|
|
||||||
|
|
||||||
def graphAddRecommenders(G, books):
|
def graphAddRecommenders(G, books, darkMode=False):
|
||||||
for rec in getAllRecommenders(books):
|
for rec in getAllRecommenders(books):
|
||||||
G.add_node('r/'+rec, color='orange', t='recommender', label=rec)
|
G.add_node('r/'+rec, color='orange', t='recommender', label=rec)
|
||||||
for book in books:
|
for book in books:
|
||||||
@ -480,7 +480,7 @@ def graphAddRecommenders(G, books):
|
|||||||
return G
|
return G
|
||||||
|
|
||||||
|
|
||||||
def graphAddTopLists(G, books):
|
def graphAddTopLists(G, books, darkMode=False):
|
||||||
for tl in getAllTopLists(books):
|
for tl in getAllTopLists(books):
|
||||||
G.add_node('t/'+tl, color='yellow', t='topList', label=tl)
|
G.add_node('t/'+tl, color='yellow', t='topList', label=tl)
|
||||||
for book in books:
|
for book in books:
|
||||||
@ -490,7 +490,7 @@ def graphAddTopLists(G, books):
|
|||||||
return G
|
return G
|
||||||
|
|
||||||
|
|
||||||
def graphAddSeries(G, books):
|
def graphAddSeries(G, books, darkMode=False):
|
||||||
for series in getAllSeries(books):
|
for series in getAllSeries(books):
|
||||||
G.add_node('s/'+series, color='red', t='series', label=series, shape='triangle')
|
G.add_node('s/'+series, color='red', t='series', label=series, shape='triangle')
|
||||||
for book in books:
|
for book in books:
|
||||||
@ -499,9 +499,9 @@ def graphAddSeries(G, books):
|
|||||||
return G
|
return G
|
||||||
|
|
||||||
|
|
||||||
def graphAddTags(G, books):
|
def graphAddTags(G, books, darkMode=False):
|
||||||
for tag in getAllTags(books):
|
for tag in getAllTags(books):
|
||||||
G.add_node('t/'+tag, color='lightGray', t='tag', label=tag, shape='box')
|
G.add_node('t/'+tag, color=['lightGray','darkgray'][darkMode], t='tag', label=tag, shape='box')
|
||||||
for book in books:
|
for book in books:
|
||||||
for tag in getTags(book):
|
for tag in getTags(book):
|
||||||
G.add_edge('t/'+tag, book['id'], color=readColor(book))
|
G.add_edge('t/'+tag, book['id'], color=readColor(book))
|
||||||
@ -552,8 +552,10 @@ def addScoreToLabels(G):
|
|||||||
node['label'] += " (~0±∞)"
|
node['label'] += " (~0±∞)"
|
||||||
|
|
||||||
|
|
||||||
def genAndShowHTML(G, showButtons=False):
|
def genAndShowHTML(G, showButtons=False, darkMode=False, arrows=False):
|
||||||
net = Network('1080px', '1920px')
|
net = Network('1080px', '1920px',
|
||||||
|
directed=arrows,
|
||||||
|
bgcolor=['#FFFFFF','#181818'][darkMode])
|
||||||
if showButtons:
|
if showButtons:
|
||||||
net.show_buttons(filter_=['configure', 'layout',
|
net.show_buttons(filter_=['configure', 'layout',
|
||||||
'interaction', 'physics', 'edges'])
|
'interaction', 'physics', 'edges'])
|
||||||
@ -561,15 +563,15 @@ def genAndShowHTML(G, showButtons=False):
|
|||||||
net.show('nx.html')
|
net.show('nx.html')
|
||||||
|
|
||||||
|
|
||||||
def buildFullGraph():
|
def buildFullGraph(darkMode=False):
|
||||||
books = loadBooksFromDB()
|
books = loadBooksFromDB()
|
||||||
G = buildBookGraph(books)
|
G = buildBookGraph(books, darkMode=darkMode)
|
||||||
|
|
||||||
graphAddAuthors(G, books)
|
graphAddAuthors(G, books, darkMode=darkMode)
|
||||||
graphAddRecommenders(G, books)
|
graphAddRecommenders(G, books, darkMode=darkMode)
|
||||||
graphAddTopLists(G, books)
|
graphAddTopLists(G, books, darkMode=darkMode)
|
||||||
graphAddSeries(G, books)
|
graphAddSeries(G, books, darkMode=darkMode)
|
||||||
graphAddTags(G, books)
|
graphAddTags(G, books, darkMode=darkMode)
|
||||||
return G, books
|
return G, books
|
||||||
|
|
||||||
|
|
||||||
@ -889,6 +891,7 @@ def cliInterface():
|
|||||||
parser.add_argument('--remove-edge', action="store_true")
|
parser.add_argument('--remove-edge', action="store_true")
|
||||||
parser.add_argument('--keep-top-lists', action="store_true")
|
parser.add_argument('--keep-top-lists', action="store_true")
|
||||||
parser.add_argument('--keep-useless-recommenders', action="store_true")
|
parser.add_argument('--keep-useless-recommenders', action="store_true")
|
||||||
|
parser.add_argument('--dark-mode', action="store_true")
|
||||||
cmds = parser.add_subparsers(required=True, dest='cmd')
|
cmds = parser.add_subparsers(required=True, dest='cmd')
|
||||||
|
|
||||||
p_rec = cmds.add_parser('recommend', description="TODO", aliases=['rec'])
|
p_rec = cmds.add_parser('recommend', description="TODO", aliases=['rec'])
|
||||||
@ -918,7 +921,7 @@ def cliInterface():
|
|||||||
train(args.g, args.full)
|
train(args.g, args.full)
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
G, books = buildFullGraph()
|
G, books = buildFullGraph(darkMode=args.dark_mode)
|
||||||
mu, std = genScores(G, books)
|
mu, std = genScores(G, books)
|
||||||
|
|
||||||
if args.cmd=="recommend":
|
if args.cmd=="recommend":
|
||||||
@ -954,7 +957,7 @@ def cliInterface():
|
|||||||
if not args.no_list:
|
if not args.no_list:
|
||||||
printBestList(G)
|
printBestList(G)
|
||||||
if not args.no_web:
|
if not args.no_web:
|
||||||
genAndShowHTML(G)
|
genAndShowHTML(G, darkMode=args.dark_mode)
|
||||||
|
|
||||||
|
|
||||||
weights = loadWeights()
|
weights = loadWeights()
|
||||||
|
Loading…
Reference in New Issue
Block a user