<commit_before>h1. fusion-tables

This gem lets you easily interact with Google Fusion Tables from your Ruby application. Here is a "live visualisation of london bike hire availability":http://tables.googlelabs.com/DataSource?snapid=78314 and some "example maps and charts":http://www.tokumine.com/2010/08/10/fusion-tables-gem/.

h2. Gem Dependencies

* gdata_19 >= 1.1.2

h2. Installation

bc. gem install fusion_tables

h2. Rubies

Tested on:

* 1.8.7
* 1.9.2-p0

h2. To Use

bc. require 'fusion_tables'

or in Rails 2.3.x

bc. config.gem 'fusion_tables'

h2. API examples
 
"Twitter example":http://github.com/tokumine/fusion-tables/blob/master/examples/compare_tweets.rb
"Boris bike example":http://github.com/tokumine/fusion-tables/blob/master/examples/boris_bikes.rb 
"Tests":http://github.com/tokumine/fusion-tables/tree/master/test/

Here is a brief rundown:

<pre><code># Connect to service	
@ft = GData::Client::FusionTables.new      
@ft.clientlogin(username, password)

# Browse existing tables
@ft.show_tables
 # => [table_1, table_2] 

# Getting table id suitable for using with google maps (see more below)
table_1.id #=> 42342 (the table's google id)

# Count data
table_1.count #=> 1

# Select data
table_1.select 
 #=> data

# Select data with conditions
table_1.select "name", "WHERE x=n"
 #=> data

# Select ROWIDs
row_ids = table_1.select "ROWID"

# Drop tables
@ft.drop table_1.id                    # table id
@ft.drop [table_1.id, table_2.id]     # arrays of table ids
@ft.drop /yacht/                      # regex on table name

# Creating a table
cols = [{:name => "friend name",    :type => 'string' },
        {:name => "age",            :type => 'number' },
        {:name => "meeting time",   :type => 'datetime' },
        {:name => "where",          :type => 'location' }]

new_table = @ft.create_table "My upcoming meetings", cols

# Inserting rows (auto chunks every 500)
data = [{"friend name" 	=> "<NAME>", 
         "age"          => 25, 
         "meeting time" => Time.utc(2010,"aug",10,20,15,1),
         "where"        => "29 Acacia Road, Nuttytown"}]
new_table.insert data

# Delete row
new_table.delete row_id
</code></pre>

h2. Fusion Tables secret Geospatial Sauce

*"Geolocated Tweets example":http://tables.googlelabs.com/DataSource?snapid=73106*

Fusion Tables is a labs product from Google. You can "read more here":http://tables.googlelabs.com/, but the key thing is that it gives you *access to the google tile mill for fast generation of google map layers across large datasets* 

Fusion Tables supports the following geometry types:

* lat/long
* addresses (automatically geocodes them for you)
* KML (point, polyline, polygon, multipolygon)

h2. Integrate with google maps v3

Adding a fusion tables datalayer with many points/polygons to your v3 map is as simple as:

bc. layer = new google.maps.FusionTablesLayer(139529);

That's it<commit_msg>sample code for UPDATE workaround<commit_after>h1. fusion-tables

This gem lets you easily interact with Google Fusion Tables from your Ruby application. Here is a "live visualisation of london bike hire availability":http://tables.googlelabs.com/DataSource?snapid=78314 and some "example maps and charts":http://www.tokumine.com/2010/08/10/fusion-tables-gem/.

h2. Gem Dependencies

* gdata_19 >= 1.1.2

h2. Installation

bc. gem install fusion_tables

h2. Rubies

Tested on:

* 1.8.7
* 1.9.2-p0

h2. To Use

bc. require 'fusion_tables'

or in Rails 2.3.x

bc. config.gem 'fusion_tables'

h2. API examples
 
"Twitter example":http://github.com/tokumine/fusion-tables/blob/master/examples/compare_tweets.rb
"Boris bike example":http://github.com/tokumine/fusion-tables/blob/master/examples/boris_bikes.rb 
"Tests":http://github.com/tokumine/fusion-tables/tree/master/test/

Here is a brief rundown:

<pre><code># Connect to service	
@ft = GData::Client::FusionTables.new      
@ft.clientlogin(username, password)

# Browse existing tables
@ft.show_tables
 # => [table_1, table_2] 

# Getting table id suitable for using with google maps (see more below)
table_1.id #=> 42342 (the table's google id)

# Count data
table_1.count #=> 1

# Select data
table_1.select 
 #=> data

# Select data with conditions
table_1.select "name", "WHERE x=n"
 #=> data

# Select ROWIDs
row_ids = table_1.select "ROWID"

# Drop tables
@ft.drop table_1.id                    # table id
@ft.drop [table_1.id, table_2.id]     # arrays of table ids
@ft.drop /yacht/                      # regex on table name

# Creating a table
cols = [{:name => "friend name",    :type => 'string' },
        {:name => "age",            :type => 'number' },
        {:name => "meeting time",   :type => 'datetime' },
        {:name => "where",          :type => 'location' }]

new_table = @ft.create_table "My upcoming meetings", cols

# Inserting rows (auto chunks every 500)
data = [{"friend name" 	=> "<NAME>", 
         "age"          => 25, 
         "meeting time" => Time.utc(2010,"aug",10,20,15,1),
         "where"        => "29 Acacia Road, Nuttytown"}]
new_table.insert data

# Delete row
new_table.delete row_id
</code></pre>

Currently UPDATE query is not implemented, you could always delete all data and start over again. 

But you could also do this:

<pre><code>
require 'active_support/core_ext/array/grouping'

# get the table as above..

data = []
list = table.select("*", "WHERE location contains '%20' ORDER BY permalink LIMIT 2")

list.each do |item|
  data << item
  id  = table.select("ROWID", "WHERE permalink = '%s'" % item[:permalink])
  id  = id.first[:rowid]
  puts "deleting %d" % id
  table.delete(id)
end

#modify location, remove text that breaks longlat value..
data.map {|item| item[:location] = item[:location].gsub('%20','')}

data.in_groups_of(50, false) do |group|
  puts "inserting to fusion table: %d items" % group.size
  table.insert(group)
end
</code></pre>

h2. Fusion Tables secret Geospatial Sauce

*"Geolocated Tweets example":http://tables.googlelabs.com/DataSource?snapid=73106*

Fusion Tables is a labs product from Google. You can "read more here":http://tables.googlelabs.com/, but the key thing is that it gives you *access to the google tile mill for fast generation of google map layers across large datasets* 

Fusion Tables supports the following geometry types:

* lat/long
* addresses (automatically geocodes them for you)
* KML (point, polyline, polygon, multipolygon)

h2. Integrate with google maps v3

Adding a fusion tables datalayer with many points/polygons to your v3 map is as simple as:

bc. layer = new google.maps.FusionTablesLayer(139529);

That's it
{'fraction_non_alphanumeric': 0.124373576309795, 'fraction_numerical': 0.025968109339407745, 'mean_word_length': 3.573611111111111, 'pattern_counts': {'":': 14, '<': 19, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '600870', 'n_tokens_mistral': 2317, 'n_tokens_neox': 2161, 'n_words': 687}