gnome-applets r10827 - in trunk/invest-applet: . docs/C invest



Author: callum
Date: Sat May  3 01:10:40 2008
New Revision: 10827
URL: http://svn.gnome.org/viewvc/gnome-applets?rev=10827&view=rev

Log:
Make the change item in the invest applet an actual percentage.

Modified:
   trunk/invest-applet/ChangeLog
   trunk/invest-applet/docs/C/invest-applet.xml
   trunk/invest-applet/invest/__init__.py
   trunk/invest-applet/invest/chart.py
   trunk/invest-applet/invest/quotes.py
   trunk/invest-applet/invest/widgets.py

Modified: trunk/invest-applet/docs/C/invest-applet.xml
==============================================================================
--- trunk/invest-applet/docs/C/invest-applet.xml	(original)
+++ trunk/invest-applet/docs/C/invest-applet.xml	Sat May  3 01:10:40 2008
@@ -147,7 +147,7 @@
             </listitem>
             <listitem>
               <para>
-                The recent change in the stock price
+                The change in the stock price over the last day.
               </para>
             </listitem>
             <listitem>

Modified: trunk/invest-applet/invest/__init__.py
==============================================================================
--- trunk/invest-applet/invest/__init__.py	(original)
+++ trunk/invest-applet/invest/__init__.py	Sat May  3 01:10:40 2008
@@ -61,8 +61,8 @@
 
 QUOTES_URL="http://finance.yahoo.com/d/quotes.csv?s=%(s)s&f=sl1d1t1c1ohgv&e=.csv"
 
-# Sample: "APPL",76.05,"1/9/2006","4:00pm",0.00,N/A,N/A,N/A,500
-QUOTES_CSV_FIELDS=["ticker", ("trade", float), "date", "time", ("variation", float)]
+# Sample (25/4/2008): UCG.MI,"4,86",09:37:00,2008/04/25,"0,07","4,82","4,87","4,82",11192336
+QUOTES_CSV_FIELDS=["ticker", ("trade", float), "time", "date", ("variation", float), ("open", float)]
 
 try:
 	STOCKS = cPickle.load(file(STOCKS_FILE))

Modified: trunk/invest-applet/invest/chart.py
==============================================================================
--- trunk/invest-applet/invest/chart.py	(original)
+++ trunk/invest-applet/invest/chart.py	Sat May  3 01:10:40 2008
@@ -230,6 +230,10 @@
 	def open_cb(handle, result):
 		if result:
 			print "Open of sparkline chart for ticker %s failed:" % ticker, result
+			# FIXME: show 'n/a' if sparkline is not available
+			# this works but is very dangerous (infinite loop)
+			# FinancialSparklineChartPixbuf('WRONG', update_callback, userdata)
+			update_callback(None, userdata)
 		else:
 			loader = gtk.gdk.PixbufLoader()
 			handle.read(GNOMEVFS_CHUNK_SIZE, read_cb, loader)

Modified: trunk/invest-applet/invest/quotes.py
==============================================================================
--- trunk/invest-applet/invest/quotes.py	(original)
+++ trunk/invest-applet/invest/quotes.py	Sat May  3 01:10:40 2008
@@ -8,7 +8,7 @@
 import invest, invest.about, invest.chart
 
 class QuoteUpdater(gtk.ListStore):
-	SYMBOL, TICKER_ONLY, BALANCE, BALANCE_PCT, VALUE, VARIATION = range(6)	
+	SYMBOL, TICKER_ONLY, BALANCE, BALANCE_PCT, VALUE, VARIATION_PCT = range(6)
 	def __init__ (self, change_icon_callback):
 		gtk.ListStore.__init__ (self, gobject.TYPE_STRING, bool, float, float, float, float, gtk.gdk.Pixbuf)
 		gobject.timeout_add(invest.AUTOREFRESH_TIMEOUT, self.refresh)
@@ -57,7 +57,11 @@
 						result[fields[0]][field[0]] = 0
 				else:
 					result[fields[0]][field] = fields[i]
-					
+			# calculated fields
+			try:
+				result[fields[0]]['variation_pct'] = result[fields[0]]['variation'] / float(result[fields[0]]['trade'] - result[fields[0]]['variation']) * 100
+			except ZeroDivisionError:
+				result[fields[0]]['variation_pct'] = 0
 		return result 
 
 	def populate(self, quotes):
@@ -72,7 +76,7 @@
 		positions_count = 0
 
 		for ticker, val in quote_items:
-			pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, 1, 1)
+			pb = None
 			
 			# Check whether the symbol is a simple quote, or a portfolio value
 			is_simple_quote = True
@@ -83,8 +87,8 @@
 			
 			if is_simple_quote:
 				simple_quotes_count += 1
-				row = self.insert(0, [ticker, True, 0, 0, val["trade"], val["variation"], pb])
-				simple_quotes_change += val['variation']
+				row = self.insert(0, [ticker, True, 0, 0, val["trade"], val["variation_pct"], pb])
+				simple_quotes_change += val['variation_pct']
 			else:
 				positions_count += 1
 				current = sum([purchase["amount"]*val["trade"] for purchase in invest.STOCKS[ticker] if purchase["amount"] != 0])
@@ -94,19 +98,23 @@
 					change = 100*balance/paid
 				else:
 					change = 100 # Not technically correct, but it will look more intuitive than the real result of infinity.
-				row = self.insert(0, [ticker, False, balance, change, val["trade"], val["variation"], pb])
+				row = self.insert(0, [ticker, False, balance, change, val["trade"], val["variation_pct"], pb])
 				positions_balance += balance
 				
 			invest.chart.FinancialSparklineChartPixbuf(ticker, self.set_pb_callback, row)
 
 		if simple_quotes_count > 0:
 			change = simple_quotes_change/float(simple_quotes_count)
-			self.change_icon_callback(change/abs(change))
+			if change != 0:
+				self.change_icon_callback(change/abs(change))
+			else:
+				self.change_icon_callback(change)
 		else:
 			self.change_icon_callback(positions_balance/abs(positions_balance))
 
 	def set_pb_callback(self, pb, row):
-		self.set_value(row, 6, pb)
+		if pb != None:
+			self.set_value(row, 6, pb)
 	
 	# check if we have only simple quotes
 	def simple_quotes_only(self):

Modified: trunk/invest-applet/invest/widgets.py
==============================================================================
--- trunk/invest-applet/invest/widgets.py	(original)
+++ trunk/invest-applet/invest/widgets.py	Sat May  3 01:10:40 2008
@@ -43,12 +43,11 @@
 
 		simple_quotes_only = quotes_updater.simple_quotes_only()
 
-		# model: SYMBOL, TICKER_ONLY, BALANCE, BALANCE_PCT, VALUE, VARIATION
-		# old col_names = ['Symbol', 'Value/Balance', 'Variation/Balance PCT', 'Value']
+		# model: SYMBOL, TICKER_ONLY, BALANCE, BALANCE_PCT, VALUE, VARIATION_PCT
 		# Translators: these words all refer to a stock. Last is short
 		# for "last price". Gain is referring to the gain since the 
 		# stock was purchased.
-		col_names = [_('Ticker'), _('Last'), _('Change'), _('Chart'), _('Gain'), _('Gain %')]
+		col_names = [_('Ticker'), _('Last'), _('Change %'), _('Chart'), _('Gain'), _('Gain %')]
 		col_cellgetdata_functions = [self._getcelldata_symbol, self._getcelldata_value,
 			self._getcelldata_variation, None, self._getcelldata_balance, 
 			self._getcelldata_balancepct]
@@ -84,10 +83,11 @@
 
 	def _getcelldata_variation(self, column, cell, model, iter):
 		color = GREEN
-		if model[iter][model.VARIATION] < 0: color = RED
+		if model[iter][model.VARIATION_PCT] < 0: color = RED
+		change_pct = model[iter][model.VARIATION_PCT]
 		cell.set_property('markup',
 			"<span foreground='%s'>%+.2f%%</span>" %
-			(color, model[iter][model.VARIATION]))
+			(color, change_pct))
 
 	def _getcelldata_balance(self, column, cell, model, iter):
 		is_ticker_only = model[iter][model.TICKER_ONLY]



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]