Pages

Monday, March 29, 2010

Interactive Chart from Google Apps Engine datastore

Create a simple python file chart.py which should have been already mapped to a particular URL pattern in app.yamx

- url: /chart/.*
  script: chart.py

   1: import cgi



   2:  



   3: from google.appengine.ext import db



   4: import hist



   5:  



   6: import os



   7: from google.appengine.ext.webapp import template



   8:  



   9: quotes = db.GqlQuery("SELECT * FROM HistoricalPrices")



  10:  



  11: template_values = {'quotes': quotes,}



  12:  



  13: path = os.path.join(os.path.dirname(__file__), 'index.html')



  14: print template.render(path, template_values)




index.html should look like following





   1: <html>



   2:   <head>



   3:     <script type="text/javascript" src="http://www.google.com/jsapi"></script>
   1:  
   2:     <script type="text/javascript">
   3:       google.load("visualization", "1", {packages:["linechart"]});
   4:       google.setOnLoadCallback(drawChart);
   5:       function drawChart() {
   6:         var data = new google.visualization.DataTable();
   7:         data.addColumn('string', 'Year');
   8:         data.addColumn('number', 'Sales');
   9:         {% for quote in quotes %}        
  10:         data.addRows(1);
  11:         data.setValue({{ forloop.counter0  }}, 0, '{{ quote.TIMESTAMP }}');
  12:         data.setValue({{ forloop.counter0  }}, 1, {{ quote.OPEN }});
  13:         {% endfor %}
  14:         var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
  15:         chart.draw(data, {width: 400, height: 240, legend: 'bottom', title: 'Company Performance'});
  16:       }
  17:     
</script>



   4:   </head>



   5:   <body>



   6:     <div id="chart_div"></div>      



   7:         <b></b>



   8:   </body>



   9: </html>




Here Django's templating engine is used. For the charting component Google Visualization API is used.



Following command can be used for single command update



D:Pythonpython.exe "D:Program FilesGooglegoogle_appengineappcfg.py" --passin --email=<username>@gmail.com update "D:devappsengineproxy"  < gpass



Here gpass is a text file containing the password.

Interactive Chart from Google Apps Engine datastore

Create a simple python file chart.py which should have been already mapped to a particular URL pattern in app.yamx

- url: /chart/.*
  script: chart.py

   1: import cgi



   2:  



   3: from google.appengine.ext import db



   4: import hist



   5:  



   6: import os



   7: from google.appengine.ext.webapp import template



   8:  



   9: quotes = db.GqlQuery("SELECT * FROM HistoricalPrices")



  10:  



  11: template_values = {'quotes': quotes,}



  12:  



  13: path = os.path.join(os.path.dirname(__file__), 'index.html')



  14: print template.render(path, template_values)




index.html should look like following





   1: <html>



   2:   <head>



   3:     <script type="text/javascript" src="http://www.google.com/jsapi"></script>
   1:  
   2:     <script type="text/javascript">
   3:       google.load("visualization", "1", {packages:["linechart"]});
   4:       google.setOnLoadCallback(drawChart);
   5:       function drawChart() {
   6:         var data = new google.visualization.DataTable();
   7:         data.addColumn('string', 'Year');
   8:         data.addColumn('number', 'Sales');
   9:         {% for quote in quotes %}        
  10:         data.addRows(1);
  11:         data.setValue({{ forloop.counter0  }}, 0, '{{ quote.TIMESTAMP }}');
  12:         data.setValue({{ forloop.counter0  }}, 1, {{ quote.OPEN }});
  13:         {% endfor %}
  14:         var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
  15:         chart.draw(data, {width: 400, height: 240, legend: 'bottom', title: 'Company Performance'});
  16:       }
  17:     
</script>



   4:   </head>



   5:   <body>



   6:     <div id="chart_div"></div>      



   7:         <b></b>



   8:   </body>



   9: </html>




Here Django's templating engine is used. For the charting component Google Visualization API is used.



Following command can be used for single command update



D:\Python\python.exe "D:\\Program Files\\Google\\google_appengine\\appcfg.py" --passin --email=<username>@gmail.com update "D:\\dev\\appsengine\\proxy"  < gpass



Here gpass is a text file containing the password.

Loading CSV data in Google Apps Engine datastore

Edit your app.yaml, and add the following lines to the handlers: section:

- url: /remote_api
script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
login: admin


1.Create hist.py similar to the type of data in CSV file.







   1: from google.appengine.ext import db



   2:  



   3: class HistoricalPrices(db.Model):



   4:     SYMBOL = db.StringProperty()



   5:     SERIES  = db.StringProperty()



   6:     OPEN = db.FloatProperty()



   7:     HIGH = db.FloatProperty()



   8:     LOW = db.FloatProperty()



   9:     CLOSE = db.FloatProperty()



  10:     LAST = db.FloatProperty()



  11:     PREVCLOSE = db.FloatProperty()



  12:     TOTTRDQTY = db.FloatProperty()



  13:     TOTTRDVAL = db.FloatProperty()



  14:     TIMESTAMP = db.DateProperty()



  15:     DUMMY1 = db.StringProperty()



  16:         






2.Now Create the loader code StockLoader.py





   1: import datetime



   2: from google.appengine.ext import db



   3: from google.appengine.tools import bulkloader



   4: import hist



   5:  



   6: class HistoryLoader(bulkloader.Loader):



   7:     def __init__(self):



   8:         bulkloader.Loader.__init__(self, 'HistoricalPrices',



   9:                                    [('SYMBOL', str),



  10:                                     ('SERIES', str),



  11:                                     ('OPEN', float),



  12:                                     ('HIGH', float),



  13:                                     ('LOW', float),



  14:                                     ('CLOSE', float),



  15:                                     ('LAST', float),



  16:                                     ('PREVCLOSE', float),



  17:                                     ('TOTTRDQTY', float),



  18:                                     ('TOTTRDVAL', float),                                    



  19:                                     ('TIMESTAMP',



  20:                                      lambda x: datetime.datetime.strptime(x, '%d-%b-%Y').date()),



  21:                                     ('DUMMY1', str)



  22:                                    ])



  23:  



  24: loaders = [HistoryLoader]




 



3.Following commands to execute the above.



"D:Program FilesGooglegoogle_appengineappcfg.py" upload_data --config_file=StockLoader.py --filename=test.csv --kind=HistoricalPrices  "D:devappsengineproxy"



 



where test.csv is something like following



UNITECH,EQ,82.9,83.8,82.45,82.8,82.8,82.3,19904383,1652618271.55,4-JAN-2010,

UNITECH,EQ,83.5,84.9,83.4,84.1,84,82.8,34197626,2882001214.7,5-JAN-2010,


UNITECH,EQ,84.5,85.45,83.2,84.85,84.7,84.1,34704003,2936028889.35,6-JAN-2010,


UNITECH,EQ,85.2,85.7,83.85,84.15,84.15,84.85,28855332,2446134892.4,7-JAN-2010,



last directory mentioned is the directory of the apps engine project directory where app.yaml file exists



ref http://code.google.com/appengine/docs/python/tools/uploadingdata.html

Loading CSV data in Google Apps Engine datastore

Edit your app.yaml, and add the following lines to the handlers: section:

- url: /remote_api
script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
login: admin


1.Create hist.py similar to the type of data in CSV file.







   1: from google.appengine.ext import db



   2:  



   3: class HistoricalPrices(db.Model):



   4:     SYMBOL = db.StringProperty()



   5:     SERIES  = db.StringProperty()



   6:     OPEN = db.FloatProperty()



   7:     HIGH = db.FloatProperty()



   8:     LOW = db.FloatProperty()



   9:     CLOSE = db.FloatProperty()



  10:     LAST = db.FloatProperty()



  11:     PREVCLOSE = db.FloatProperty()



  12:     TOTTRDQTY = db.FloatProperty()



  13:     TOTTRDVAL = db.FloatProperty()



  14:     TIMESTAMP = db.DateProperty()



  15:     DUMMY1 = db.StringProperty()



  16:         






2.Now Create the loader code StockLoader.py





   1: import datetime



   2: from google.appengine.ext import db



   3: from google.appengine.tools import bulkloader



   4: import hist



   5:  



   6: class HistoryLoader(bulkloader.Loader):



   7:     def __init__(self):



   8:         bulkloader.Loader.__init__(self, 'HistoricalPrices',



   9:                                    [('SYMBOL', str),



  10:                                     ('SERIES', str),



  11:                                     ('OPEN', float),



  12:                                     ('HIGH', float),



  13:                                     ('LOW', float),



  14:                                     ('CLOSE', float),



  15:                                     ('LAST', float),



  16:                                     ('PREVCLOSE', float),



  17:                                     ('TOTTRDQTY', float),



  18:                                     ('TOTTRDVAL', float),                                    



  19:                                     ('TIMESTAMP',



  20:                                      lambda x: datetime.datetime.strptime(x, '%d-%b-%Y').date()),



  21:                                     ('DUMMY1', str)



  22:                                    ])



  23:  



  24: loaders = [HistoryLoader]




 



3.Following commands to execute the above.



"D:\Program Files\Google\google_appengine\appcfg.py" upload_data --config_file=StockLoader.py --filename=test.csv --kind=HistoricalPrices  "D:\dev\appsengine\proxy"



 



where test.csv is something like following



UNITECH,EQ,82.9,83.8,82.45,82.8,82.8,82.3,19904383,1652618271.55,4-JAN-2010,

UNITECH,EQ,83.5,84.9,83.4,84.1,84,82.8,34197626,2882001214.7,5-JAN-2010,


UNITECH,EQ,84.5,85.45,83.2,84.85,84.7,84.1,34704003,2936028889.35,6-JAN-2010,


UNITECH,EQ,85.2,85.7,83.85,84.15,84.15,84.85,28855332,2446134892.4,7-JAN-2010,



last directory mentioned is the directory of the apps engine project directory where app.yaml file exists



ref http://code.google.com/appengine/docs/python/tools/uploadingdata.html

Thursday, March 25, 2010

Tech Days 2010



Tech Days 2010 is an annual event from Oracle that have raised the bar on technology. With exclusive previews of “what's next,” the conferences have provided insights, information, and expertise to developers around the world.



At Tech Days 2010, we heard hear from the brightest minds as they share cutting-edge technologies and ideas that can boost your career beyond the ordinary. With multiple tracks, 50+ sessions, hands-on labs, in-depth technology coverage, and exciting keepsakes, Tech Days 2010 is not just another conference to attend. It's THE conference to attend.

It was incredible to meet James Gosling (http://blogs.sun.com/jag/) , He was the keynote speaker on the day 1 (24th march) at Tech days by Oracle.  Major highlight was JavaFx which he not only demonstrated but also his entire slide turned out to be a JavaFx program by him which was only 400 odd lines of code. That was productivity at its best.



The sessions started with a wonderful talk by Arun Gupta and followed by various other speakers like Abhishek Mahanty and chuck Mun Lee.Reports of both Day 1 and Day 2 can be found in Arun's blog. Some other  of the notes can be found at

http://varunkumar-n.blogspot.com/2010/03/james-goslings-talk-tech-days-2010.html
and
http://blog.varunkumar.me/2010/03/tech-days-2010-hyderabad-day-2.html

Tech Days 2010

It was incredible to see James Gosling (http://blogs.sun.com/jag/)live as a keynote speaker on the day 1 (24th march) at Tech days by Oracle.

The sessions started with a wonderful talk by Arun Gupta.

Most of the notes can be found at http://varunkumar-n.blogspot.com/2010/03/james-goslings-talk-tech-days-2010.html

Arun’s blog for Day 2 is as follows

http://blogs.sun.com/arungupta/entry/day_2_tech_days_2010

Some more photos …

Sunday, March 14, 2010

Simple Free Web Proxy Server

http://proxy.neilghosh.com/ is a new addition to the set of tools in this site.This uses Python scripts in Google apps engine.
Thanks to the article in labnol.org. You can see the difference between visiting a site with and without proxy.

It does not work for all the websites which are restricted in your region (specially the once with rich contents ) but you explore others.

Simple Free Web Proxy Server

http://proxy.neilghosh.com/ is a new addition to the set of tools in this site.This uses Python scripts in Google apps engine.
Thanks to the article in labnol.org. You can see the difference between visiting a site with and without proxy.

It does not work for all the websites which are restricted in your region (specially the once with rich contents ) but you explore others.

Tuesday, March 9, 2010

How to change the default Google Desktop Data index folder

Google desktop search uses a folder in which it stores its index files. This folder called “Google Desktop Data” is by default place in the “My Documents” folder of your pc. To me that’s not a logical place though as I only want to have files I actively use to be in the “Mt Documents” folders. Music, Video, Word-files and spreadsheets are fine, index files from a search tool are not.
Unfortunately Google Desktop does not offer the ability to change the location of its index files. This is what you have to do if you want another location for the Google Desktop Data folder:

  • 1. Stop Google Desktop (Right-click the tray icon->Exit)
  • 2. Move Google Desktop Data directory to the desired location.
  • 3. Run regedit (go to start -> Run… -> regedit)
  • 4. Locate HKEY_CURRENT_USERSoftwareGoogleGoogle Desktopdata_dir
  • 5. Change its value to the location, chosen in step 2
  • 6. Start Google Desktop again

How to change the default Google Desktop Data index folder

Google desktop search uses a folder in which it stores its index files. This folder called “Google Desktop Data” is by default place in the “My Documents” folder of your pc. To me that’s not a logical place though as I only want to have files I actively use to be in the “Mt Documents” folders. Music, Video, Word-files and spreadsheets are fine, index files from a search tool are not.
Unfortunately Google Desktop does not offer the ability to change the location of its index files. This is what you have to do if you want another location for the Google Desktop Data folder:

  • 1. Stop Google Desktop (Right-click the tray icon->Exit)
  • 2. Move Google Desktop Data directory to the desired location.
  • 3. Run regedit (go to start -> Run… -> regedit)
  • 4. Locate HKEY_CURRENT_USER\Software\Google\Google Desktop\data_dir
  • 5. Change its value to the location, chosen in step 2
  • 6. Start Google Desktop again