CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 19
Import data from google spreadsheet #88
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
Conversation
Enable rubocop MethodLength in initialize method
d8d69f7
to
a59968d
Compare
2bbe578
to
10c4d11
Compare
Once the code is reviewed, I will add the tests for the related methods. |
Writing testcases before writing lines of code is good practice. So testcases must be present for each line of code (test coverage 100%). |
spec/adapters/googlecharts_spec.rb
Outdated
@@ -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' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please write examples in dummy_iruby
and share the link ( like).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am expecting notebook link like this .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you try in incognito mode ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line size ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check whether it is a valid URL or not. If not rescue the Exception + document this enhancement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where should I write the documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3d8b87e
to
c495929
Compare
I have resolved the problem of only last chart visibility. We need to have the separate |
@Shekharrajak ping! |
@@ -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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will happen if string is not a URL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will be plot.table
when we have URL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, it is same as to_js
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for writing this. Please write few examples as well for init
and init_table
.
fef20e1
to
b0ac922
Compare
d9662f3
to
8a03874
Compare
@Shekharrajak please review the changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IRuby notebook example for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line length < 80 ,please.
spec/adapters/googlecharts_spec.rb
Outdated
@@ -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'\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know there are some cases where @
is used (which is not correct), please use let
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
else | ||
add_data_in_table(data) | ||
end | ||
@table = get_table(data) unless data.is_a?(String) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can get the table , as here.
Thanks @Prakriti-nith , for writing in wiki page |
#87
This PR adds a feature to retrieve data from google spreadsheets.