mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
Add the ability to sort the log
This commit is contained in:
parent
a6827ee7e2
commit
0cdd06ddad
2 changed files with 26 additions and 14 deletions
|
@ -107,6 +107,7 @@ class PysolStatsFormatter:
|
||||||
|
|
||||||
def getLogResults(self, player, prev_games):
|
def getLogResults(self, player, prev_games):
|
||||||
t_won, tlost = 0, 0
|
t_won, tlost = 0, 0
|
||||||
|
stats = []
|
||||||
for pg in prev_games:
|
for pg in prev_games:
|
||||||
if not isinstance(pg, tuple):
|
if not isinstance(pg, tuple):
|
||||||
continue
|
continue
|
||||||
|
@ -147,7 +148,8 @@ class PysolStatsFormatter:
|
||||||
_("Won"), _("Perfect"))[pg[2]+2]
|
_("Won"), _("Perfect"))[pg[2]+2]
|
||||||
# writer.plog(name, gamenumber, date, status, gameid=gameid,
|
# writer.plog(name, gamenumber, date, status, gameid=gameid,
|
||||||
# won=pg[2])
|
# won=pg[2])
|
||||||
yield [name, gamenumber, date, status, pg[2], gameid]
|
stats.append([name, gamenumber, date, status, pg[2], gameid])
|
||||||
|
return stats
|
||||||
|
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
|
@ -376,11 +376,18 @@ class TreeFormatter(PysolStatsFormatter):
|
||||||
self.parent_window.tree_items.append(id)
|
self.parent_window.tree_items.append(id)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def writeLog(self, player, prev_games):
|
def writeLog(self, player, prev_games, sort_by='date'):
|
||||||
if not player or not prev_games:
|
if not player or not prev_games:
|
||||||
return 0
|
return 0
|
||||||
num_rows = 0
|
num_rows = 0
|
||||||
for result in self.getLogResults(player, prev_games):
|
results = self.getLogResults(player, prev_games)
|
||||||
|
if sort_by == 'gamenumber':
|
||||||
|
results.sort(key=lambda x: x[1])
|
||||||
|
elif sort_by == 'name':
|
||||||
|
results.sort(key=lambda x: x[0])
|
||||||
|
elif sort_by == 'status':
|
||||||
|
results.sort(key=lambda x: x[3])
|
||||||
|
for result in results:
|
||||||
t1, t2, t3, t4, t5, t6 = result
|
t1, t2, t3, t4, t5, t6 = result
|
||||||
id = self.tree.insert("", "end", text=t1, values=(t2, t3, t4))
|
id = self.tree.insert("", "end", text=t1, values=(t2, t3, t4))
|
||||||
self.parent_window.tree_items.append(id)
|
self.parent_window.tree_items.append(id)
|
||||||
|
@ -388,15 +395,16 @@ class TreeFormatter(PysolStatsFormatter):
|
||||||
num_rows += 1
|
num_rows += 1
|
||||||
if num_rows > self.MAX_ROWS:
|
if num_rows > self.MAX_ROWS:
|
||||||
break
|
break
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def writeFullLog(self, player):
|
def writeFullLog(self, player, sort_by='date'):
|
||||||
prev_games = self.app.stats.prev_games.get(player)
|
prev_games = self.app.stats.prev_games.get(player)
|
||||||
return self.writeLog(player, prev_games)
|
return self.writeLog(player, prev_games, sort_by=sort_by)
|
||||||
|
|
||||||
def writeSessionLog(self, player):
|
def writeSessionLog(self, player, sort_by='date'):
|
||||||
prev_games = self.app.stats.session_games.get(player)
|
prev_games = self.app.stats.session_games.get(player)
|
||||||
return self.writeLog(player, prev_games)
|
return self.writeLog(player, prev_games, sort_by=sort_by)
|
||||||
|
|
||||||
|
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
|
@ -600,6 +608,7 @@ class FullLogFrame(AllGamesFrame):
|
||||||
'XXXXXXXXXXXX')
|
'XXXXXXXXXXXX')
|
||||||
self.games = {}
|
self.games = {}
|
||||||
self.formatter.resizeHeader(player, header)
|
self.formatter.resizeHeader(player, header)
|
||||||
|
self.sort_by = 'date'
|
||||||
|
|
||||||
def createHeader(self, player):
|
def createHeader(self, player):
|
||||||
header = self.formatter.getLogHeader()
|
header = self.formatter.getLogHeader()
|
||||||
|
@ -607,11 +616,10 @@ class FullLogFrame(AllGamesFrame):
|
||||||
|
|
||||||
def fillTreeview(self, player):
|
def fillTreeview(self, player):
|
||||||
if self.tree_items:
|
if self.tree_items:
|
||||||
return
|
for item in self.tree.get_children():
|
||||||
self.formatter.writeFullLog(player)
|
self.tree.delete(item)
|
||||||
|
self.tree_items = []
|
||||||
def headerClick(self, column):
|
self.formatter.writeFullLog(player, sort_by=self.sort_by)
|
||||||
pass
|
|
||||||
|
|
||||||
def getSelectedGame(self):
|
def getSelectedGame(self):
|
||||||
sel = self.tree.selection()
|
sel = self.tree.selection()
|
||||||
|
@ -624,8 +632,10 @@ class FullLogFrame(AllGamesFrame):
|
||||||
class SessionLogFrame(FullLogFrame):
|
class SessionLogFrame(FullLogFrame):
|
||||||
def fillTreeview(self, player):
|
def fillTreeview(self, player):
|
||||||
if self.tree_items:
|
if self.tree_items:
|
||||||
return
|
for item in self.tree.get_children():
|
||||||
self.formatter.writeSessionLog(player)
|
self.tree.delete(item)
|
||||||
|
self.tree_items = []
|
||||||
|
self.formatter.writeSessionLog(player, sort_by=self.sort_by)
|
||||||
|
|
||||||
|
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
|
|
Loading…
Add table
Reference in a new issue