Fix crasher in Grapher if no hands returned.

Should alert user or at least draw something in right pane.
This commit is contained in:
Worros 2008-12-11 23:55:03 +09:00
parent 90803b297f
commit 3a1ddad58f

View File

@ -83,22 +83,24 @@ class GuiGraphViewer (threading.Thread):
self.ax.set_xlabel("Hands", fontsize = 12) self.ax.set_xlabel("Hands", fontsize = 12)
self.ax.set_ylabel("$", fontsize = 12) self.ax.set_ylabel("$", fontsize = 12)
self.ax.grid(color='g', linestyle=':', linewidth=0.2) self.ax.grid(color='g', linestyle=':', linewidth=0.2)
#This line will crash if no hands exist in the query. if(line == None):
text = "All Hands, " + sitename + str(name) + "\nProfit: $" + str(line[-1]) + "\nTotal Hands: " + str(len(line)) #TODO: Do something useful like alert user
print "No hands returned by graph query"
else:
text = "All Hands, " + sitename + str(name) + "\nProfit: $" + str(line[-1]) + "\nTotal Hands: " + str(len(line))
self.ax.annotate(text, self.ax.annotate(text,
xy=(10, -10), xy=(10, -10),
xycoords='axes points', xycoords='axes points',
horizontalalignment='left', verticalalignment='top', horizontalalignment='left', verticalalignment='top',
fontsize=10) fontsize=10)
#Draw plot
self.ax.plot(line,)
#Draw plot self.canvas = FigureCanvas(self.fig) # a gtk.DrawingArea
self.ax.plot(line,) self.graphBox.add(self.canvas)
self.canvas.show()
self.canvas = FigureCanvas(self.fig) # a gtk.DrawingArea
self.graphBox.add(self.canvas)
self.canvas.show()
#end of def showClicked #end of def showClicked
def getRingProfitGraph(self, name, site): def getRingProfitGraph(self, name, site):
@ -106,6 +108,9 @@ class GuiGraphViewer (threading.Thread):
#returns (HandId,Winnings,Costs,Profit) #returns (HandId,Winnings,Costs,Profit)
winnings = self.db.cursor.fetchall() winnings = self.db.cursor.fetchall()
if(winnings == ()):
return None
y=map(lambda x:float(x[3]), winnings) y=map(lambda x:float(x[3]), winnings)
line = cumsum(y) line = cumsum(y)
return line/100 return line/100