New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import data from google spreadsheet #88

Merged
merged 16 commits into from Jun 16, 2018

Conversation

Projects
None yet
2 participants
@Prakriti-nith
Contributor

Prakriti-nith commented Apr 7, 2018

#87
This PR adds a feature to retrieve data from google spreadsheets.

Import data from google spreadsheet
Enable rubocop MethodLength in initialize method

@Prakriti-nith Prakriti-nith force-pushed the Prakriti-nith:import_spreadsheet branch from d8d69f7 to a59968d Apr 12, 2018

@Prakriti-nith Prakriti-nith force-pushed the Prakriti-nith:import_spreadsheet branch from 2bbe578 to 10c4d11 Apr 12, 2018

@Prakriti-nith

This comment has been minimized.

Contributor

Prakriti-nith commented Apr 13, 2018

Once the code is reviewed, I will add the tests for the related methods.

@Shekharrajak

This comment has been minimized.

Collaborator

Shekharrajak commented Apr 13, 2018

Writing testcases before writing lines of code is good practice. So testcases must be present for each line of code (test coverage 100%).

@@ -30,6 +30,14 @@
['Lg. Magellanic Cloud', 50000, 120.9],
['Bootes I', 60000, 1223.1]
]
@query_string = 'SELECT A, H, O, Q, R, U LIMIT 5 OFFSET 8'

This comment has been minimized.

@Shekharrajak

Shekharrajak Apr 13, 2018

Collaborator

Please write examples in dummy_iruby and share the link ( like).

This comment has been minimized.

@Shekharrajak

Shekharrajak Apr 19, 2018

Collaborator

I am expecting notebook link like this .

This comment has been minimized.

@Prakriti-nith

Prakriti-nith Apr 22, 2018

Contributor

Here is the link to view the examples.
I am getting the outputs for all the jupyter notebook cells locally but I can't understand why they are not visible online.

This comment has been minimized.

@Shekharrajak

Shekharrajak Apr 22, 2018

Collaborator

Did you try in incognito mode ?

This comment has been minimized.

@Prakriti-nith

Prakriti-nith Apr 25, 2018

Contributor

Yes, I tried the examples in incognito mode. Running each cell individually is showing the correct output but after I save the file and open it again, then only the last output is visible.

def init_script
GoogleVisualr.init_script
end

def generate_body(plot)
plot.to_html
plot.to_html(@data)

This comment has been minimized.

@Shekharrajak

Shekharrajak Apr 13, 2018

Collaborator

Any alternate way, you can think of ?

# Parameters:
# *data [Required] The URL of the spreadsheet in a specified format. Query string can be appended
# to retrieve the data accordingly.
# *div_id [Required] The ID of the DIV element that the Google Chart should be rendered in.

This comment has been minimized.

@Shekharrajak

Shekharrajak Apr 13, 2018

Collaborator

line size ?

@Shekharrajak

Please add few more examples showing how different kind of data can be imported using google spreadsheet in iruby notebook. Also display the dataframe or google datatable for the data imported from google spreadsheet in iruby examples.

I hope you have added testcases covering all the lines.

data.table
elsif data.is_a?(GoogleVisualr::DataTable)
data
elsif data.is_a?(String)

This comment has been minimized.

@Shekharrajak

Shekharrajak Apr 19, 2018

Collaborator

Check whether it is a valid URL or not. If not rescue the Exception + document this enhancement.

This comment has been minimized.

@Prakriti-nith

Prakriti-nith Apr 22, 2018

Contributor

Where should I write the documentation?

This comment has been minimized.

@Shekharrajak

@Prakriti-nith Prakriti-nith force-pushed the Prakriti-nith:import_spreadsheet branch from 3d8b87e to c495929 May 29, 2018

Prakriti-nith added some commits May 29, 2018

@Prakriti-nith

This comment has been minimized.

Contributor

Prakriti-nith commented May 29, 2018

I have resolved the problem of only last chart visibility. We need to have the separate handle_query_response function for each query (refer).
For drawing the chart when data is imported from Google spreadsheet, we are not using google_visualr as we can't feed the data into the table. The query automatically generates the table when var data_table = response.getDataTable(); js code is run.
I have also improved the documentation according to the yard and added some more tests.
Updated examples: link

@Prakriti-nith

This comment has been minimized.

Contributor

Prakriti-nith commented Jun 3, 2018

Prakriti-nith added some commits Jun 4, 2018

@@ -97,7 +121,7 @@ def extract_chart_type(options)
chart_type = chart_type.to_s.capitalize
chart_type = 'SteppedArea' if chart_type == 'Steppedarea'
chart_type = 'TreeMap' if chart_type == 'Treemap'
direct_name = %w[Map Histogram TreeMap Timeline Gauge]
direct_name = %w[Map Histogram TreeMap Timeline Gauge Table]

This comment has been minimized.

@Shekharrajak

Shekharrajak Jun 10, 2018

Collaborator

It is only for chart; not for table. Where do you need this ?

else
add_data_in_table(data)
end
@table = get_table(data) unless data.is_a?(String)

This comment has been minimized.

@Shekharrajak

Shekharrajak Jun 10, 2018

Collaborator

What will happen if string is not a URL?

This comment has been minimized.

@Shekharrajak

Shekharrajak Jun 10, 2018

Collaborator

What will be plot.table when we have URL?

This comment has been minimized.

@Prakriti-nith

Prakriti-nith Jun 11, 2018

Contributor

plot.table will contain the empty table as the DataTable is generated in query response here and we can not retrieve the data from google spreadsheet.

This comment has been minimized.

@Prakriti-nith

Prakriti-nith Jun 13, 2018

Contributor

We might be able to retrieve the data from the URL provided. It is because the URL provides the access to JSON data which can then be stored in a Daru::DataFrame.

This comment has been minimized.

@Shekharrajak

Shekharrajak Jun 16, 2018

Collaborator

We can get the table , as here.

describe GoogleVisualr::BaseChart do
before { Daru::View.plotting_library = :googlecharts }
before(:each) do
@query_string = 'SELECT A, H, O, Q, R, U LIMIT 5 OFFSET 8'

This comment has been minimized.

@Shekharrajak

Shekharrajak Jun 10, 2018

Collaborator

We must use let instead of @.
Please follow better specs.

# @param dom [String] The ID of the DIV element that the Google
# Chart should be rendered in
# @return [String] js code to render the chart
def get_html(dom)

This comment has been minimized.

@Shekharrajak

Shekharrajak Jun 10, 2018

Collaborator

I think, it is same as to_js method.

This comment has been minimized.

@Prakriti-nith

Prakriti-nith Jun 11, 2018

Contributor

Actually, I was going to ask you about this. I wanted to know why are we generating the googlecharts' code with script tag (by calling to_js method) and without script tag (by calling load_js and draw_js) separately in display.rb. We have already defined script tags in the template so we'll definitely be generating the script without the script tags (using load_js and draw_js)?
to_js method is never actually called.

# @param options [Hash] Various options provided by the user to
# incorporate in google charts
# @return [GoogleVisualr::Interactive] Returns the chart object based
# on the chart_type

This comment has been minimized.

@Shekharrajak

Shekharrajak Jun 10, 2018

Collaborator

Thanks for writing this. Please write few examples as well for init and init_table.

@Prakriti-nith Prakriti-nith force-pushed the Prakriti-nith:import_spreadsheet branch from fef20e1 to b0ac922 Jun 11, 2018

@Prakriti-nith Prakriti-nith force-pushed the Prakriti-nith:import_spreadsheet branch from d9662f3 to 8a03874 Jun 11, 2018

@Prakriti-nith

This comment has been minimized.

Contributor

Prakriti-nith commented Jun 14, 2018

@Shekharrajak please review the changes.

@Shekharrajak

I hope specs are covering all the methods/lines you have written.

# '_7zOFDcg8Wm8Xv29_8PWuuW15qmAE/gviz/tq?gid=0&headers=1&tq='
# query = 'SELECT A, H, O, Q, R, U LIMIT 5 OFFSET 8'
# data << query
# chart = Daru::View::Table.new(data)

This comment has been minimized.

@Shekharrajak

Shekharrajak Jun 14, 2018

Collaborator

IRuby notebook example for this?

This comment has been minimized.

@Prakriti-nith

Prakriti-nith Jun 14, 2018

Contributor

I have already added example for this. I have further added an example for the previous one. Link.

add_data_in_table(data)
@table.data = data
# When data is the URL of the spreadsheet then plot.table will contain the empty
# table as the DataTable is generated in query response in js and we can not

This comment has been minimized.

@Shekharrajak

Shekharrajak Jun 14, 2018

Collaborator

Line length < 80 ,please.

@@ -30,6 +30,14 @@
['Lg. Magellanic Cloud', 50000, 120.9],
['Bootes I', 60000, 1223.1]
]
@query_string = 'SELECT A, H, O, Q, R, U LIMIT 5 OFFSET 8'
@data_spreadsheet = 'https://docs.google.com/spreadsheets/d/1XWJLkAwch'\

This comment has been minimized.

@Shekharrajak

Shekharrajak Jun 14, 2018

Collaborator

I know there are some cases where @ is used (which is not correct), please use let instead.

@Shekharrajak

Looks good to me.

else
add_data_in_table(data)
end
@table = get_table(data) unless data.is_a?(String)

This comment has been minimized.

@Shekharrajak

Shekharrajak Jun 16, 2018

Collaborator

We can get the table , as here.

@Shekharrajak

This comment has been minimized.

Collaborator

Shekharrajak commented Jun 16, 2018

Thanks @Prakriti-nith , for writing in wiki page

@Shekharrajak Shekharrajak merged commit 2db0024 into SciRuby:master Jun 16, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment