Skip to content

Commit

Permalink
Add example for various countries data
Browse files Browse the repository at this point in the history
  • Loading branch information
Prakriti-nith committed Aug 7, 2018
1 parent 78af296 commit 39db236
Show file tree
Hide file tree
Showing 12 changed files with 220 additions and 28 deletions.
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ end
# gem 'daru-io', path: '/Users/athityakumar/Documents/GitHub/Sciruby/daru-io'
# gem 'nyaplot', git: 'https://github.com/SciRuby/nyaplot.git'

gem 'daru-io', :git => 'https://github.com/athityakumar/daru-io.git'
gem 'daru-io', :git => 'https://github.com/Sciruby/daru-io.git'
gem 'daru', :git => 'https://github.com/SciRuby/daru.git'
# gem 'rsruby'
# gem 'rsruby', :git => 'https://github.com/athityakumar/rsruby', :branch => 'fix-stack-error-with-rails'
Expand All @@ -20,10 +20,10 @@ gem 'nokogiri'
gem 'spreadsheet'
# gem 'daru-view', path: '/Users/shekharrajak/Documents/gsoc17/daru-view'
# gem 'daru-io', path: '/Users/shekharrajak/Documents/gsoc17/daru-io'
gem 'daru-view', git: 'https://github.com/Shekharrajak/daru-view.git'
gem 'daru-view', git: 'https://github.com/SciRuby/daru-view.git'

# issue : https://github.com/Shekharrajak/daru_examples_io_view_rails/issues/3
gem 'daru-data_tables', git: 'https://github.com/Shekharrajak/daru-data_tables.git'
gem 'daru-data_tables', git: 'https://github.com/shekharrajak/daru-data_tables.git'

# remove this after https://github.com/Shekharrajak/daru_examples_io_view_rails/issues/8#issuecomment-323335270
gem 'google_visualr', git: 'https://github.com/winston/google_visualr.git'
Expand All @@ -34,7 +34,7 @@ gem 'google_visualr', git: 'https://github.com/winston/google_visualr.git'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.2'
# Use sqlite3 as the database for Active Record
gem 'pg'
gem 'pg', '~> 0.21'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
Expand Down
41 changes: 21 additions & 20 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
GIT
remote: https://github.com/SciRuby/daru-view.git
revision: 1d178bca7c21b6fa4260ed0d6bc017fb1b83f934
specs:
daru-view (0.1.0)
actionview
daru
daru-data_tables
google_visualr
lazy_high_charts
nyaplot
thor

GIT
remote: https://github.com/SciRuby/daru.git
revision: 32dd946556c55ebdd10bf215d618c625edbdd9be
Expand All @@ -7,29 +20,17 @@ GIT
packable (~> 1.3.9)

GIT
remote: https://github.com/Shekharrajak/daru-data_tables.git
revision: de79857df9f94c4c9878835250c069c27dbf47d6
remote: https://github.com/Sciruby/daru-io.git
revision: dce4be1089a6c9902d91a857e0cd43cf1f9832bc
specs:
daru-data_tables (0.1.0)
daru-io (0.1.0)

GIT
remote: https://github.com/Shekharrajak/daru-view.git
revision: dacdfe5e577f210dbc8f9c9356f522976aac58da
remote: https://github.com/shekharrajak/daru-data_tables.git
revision: 660c309fc188d29bb14bb76b90560995d75650e5
specs:
daru-view (0.1.0)
actionview
daru-data_tables (0.1.0)
daru
daru-data_tables
google_visualr
lazy_high_charts
nyaplot

GIT
remote: https://github.com/athityakumar/daru-io.git
revision: 92f815c8133cc5bdd01192dbc4852f76c8058bf2
specs:
daru-io (0.1.0)
daru (~> 0.1.5)

GIT
remote: https://github.com/winston/google_visualr.git
Expand Down Expand Up @@ -241,7 +242,7 @@ DEPENDENCIES
jsonpath
listen (>= 3.0.5, < 3.2)
nokogiri
pg
pg (~> 0.21)
puma (~> 3.7)
rails (~> 5.1.2)
rouge
Expand All @@ -256,4 +257,4 @@ DEPENDENCIES
web-console (>= 3.3.0)

BUNDLED WITH
1.15.4
1.16.2
3 changes: 3 additions & 0 deletions app/assets/javascripts/countries.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/countries.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Countries controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
12 changes: 12 additions & 0 deletions app/controllers/countries_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CountriesController < ApplicationController
def data_countries
# getting data from url : http://countryapi.gear.host/v1/Country/getCountries
url = 'http://countryapi.gear.host/v1/Country/getCountries'
complex_read_instance = Daru::IO::Importers::JSON.read(url)
@countries_df = complex_read_instance.call(
Country: "$..Response..Name",
NumericCode: "$..Response..NumericCode",
Area: "$..Response..Area"
)
end
end
7 changes: 5 additions & 2 deletions app/controllers/front_page_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ def home
Routes: [
'SciRuby repos',
'SciRuby repo watchers',
'Indian election data'
'Indian election data',
'Countries data'
],
Desc: [
'Shows import from JSON API, charts, tables, and export',
'Shows import from JSON API, charts, tables, and export',
'Shows import from HTML pages, charts and tables'
'Shows import from HTML pages, charts and tables',
'Shows import from JSON API, multiple charts using PlotList, tables with formatters and CSS styling in HighCharts'
],
Link: [
view_context.link_to('sciruby/repos', {action: 'repos', controller: 'sciruby_github'}, target: '_blank'),
view_context.link_to('sciruby/watchers', {action: 'watchers', controller: 'sciruby_github'}, target: '_blank'),
view_context.link_to('election/data', {action: 'data', controller: 'election'}, target: '_blank'),
view_context.link_to('countries', {action: 'data_countries', controller: 'countries'}, target: '_blank'),
]
}, order: %i[Routes Desc Link])
end
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/countries_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CountriesHelper
end
159 changes: 159 additions & 0 deletions app/views/countries/data_countries.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<h1>Countries Data</h1>

<div class="panel panel-default">
<div class="panel-heading">Code to import data from API into <code>Daru::DataFrame</code> (yes, that's all!):</div>
<div class="panel-body">
<%=
rouge(%{
url = 'http://countryapi.gear.host/v1/Country/getCountries'
complex_read_instance = Daru::IO::Importers::JSON.read(url)
@countries_df = complex_read_instance.call(
Country: "$..Response..Name",
NumericCode: "$..Response..NumericCode",
Area: "$..Response..Area"
)
})
%>
</div>
</div>

<h2>Data table - 250 rows</h2>

<div class="view-and-code">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#view-1" aria-controls="view" role="tab" data-toggle="view-1">View</a></li>
<li role="presentation"><a href="#code-1" aria-controls="code" role="tab" data-toggle="code-1">Code</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="view-1">
<%=
Daru::View::Table.new(
@countries_df,
{ adapter: :googlecharts, pageSize: 25,
height: 300, allowHtml: true },
{ formatters: {
f1: {
type: 'Color',
range: [[0, 30000, 'white', 'red'],
[30001, 100000, 'white', 'yellow'],
[100001, nil, 'white', 'green']],
columns: 2
},
f2: {
type: 'Bar',
options: {
base: 500
},
columns: 1
}
}
}
).div.html_safe
%>
</div>
<div role="tabpanel" class="tab-pane" id="code-1">
<%= rouge(%{
Daru::View::Table.new(
@countries_df,
{ adapter: :googlecharts, pageSize: 25,
height: 300, allowHtml: true },
{ formatters: {
f1: {
type: 'Color',
range: [[0, 30000, 'white', 'red'],
[30001, 100000, 'white', 'yellow'],
[100001, nil, 'white', 'green']],
columns: 2
},
f2: {
type: 'Bar',
options: {
base: 500
},
columns: 1
}
}
}
).div.html_safe
}) %>
</div>
</div>
</div>

<h2>Multiple Charts using PlotList</h2>

<div class="view-and-code">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#view-2" aria-controls="view" role="tab" data-toggle="view-2">View</a></li>
<li role="presentation"><a href="#code-2" aria-controls="code" role="tab" data-toggle="code-2">Code</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="view-2">
<%=
Daru::View::PlotList.new(
[ Daru::View::Plot.new(
@countries_df.row[0..7][:Country, :Area],
adapter: :googlecharts, type: :pie, title: "Relative Area distribution for 8 countries - GoogleChart"
),
Daru::View::Plot.new(
@countries_df.row[0..7][:Country, :Area],
adapter: :highcharts, chart: { type: 'pie' }, title: { text: 'Relative Area distribution for 8 countries - HighChart'}
)
]
).div.html_safe
%>
</div>
<div role="tabpanel" class="tab-pane" id="code-2">
<%= rouge(%{
Daru::View::PlotList.new(
[ Daru::View::Plot.new(
@countries_df.row[0..7][:Country, :Area],
adapter: :googlecharts, type: :pie, title: "Relative Area distribution for 8 countries - GoogleChart"
),
Daru::View::Plot.new(
@countries_df.row[0..7][:Country, :Area],
adapter: :highcharts, chart: { type: 'pie' }, title: { text: 'Relative Area distribution for 8 countries - HighChart'}
)
]
).div.html_safe
}) %>
</div>
</div>
</div>

<h2>Scatter chart with styling grid and ticks</h2>

<div class="view-and-code">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#view-3" aria-controls="view-3" role="tab" data-toggle="view-3">View</a></li>
<li role="presentation"><a href="#code-3" aria-controls="code-3" role="tab" data-toggle="code-3">Code</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="view-3">
<%=
daru_chart(
@countries_df.row[0..50][:Country, :NumericCode],
adapter: :highcharts,
chart: { type: 'column' },
css: ['.highcharts-xaxis-grid .highcharts-grid-line {stroke-width: 2px;stroke: #d8d8d8;}',
'.highcharts-xaxis .highcharts-tick {stroke-width: 2px;stroke: #d8d8d8;}'],
xAxis: { categories: @countries_df.row[0..50][:Country].to_a },
title: { text: 'NumericCode of countries'}
)
%>
</div>
<div role="tabpanel" class="tab-pane" id="code-3">
<%= rouge(%{
daru_chart(
@countries_df.row[0..50][:Country, :NumericCode],
adapter: :highcharts,
chart: { type: 'column' },
css: ['.highcharts-xaxis-grid .highcharts-grid-line {stroke-width: 2px;stroke: #d8d8d8;}',
'.highcharts-xaxis .highcharts-tick {stroke-width: 2px;stroke: #d8d8d8;}'],
xAxis: { categories: @countries_df.row[0..50][:Country].to_a },
title: { text: 'NumericCode of countries'}
)
}) %>
</div>
</div>
</div>
4 changes: 2 additions & 2 deletions app/views/front_page/home.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
</p>
<div class="row">
<div class="col-md-6">
<p><a class="btn btn-lg btn-success" href="https://github.com/athithyakumar/daru-io" role="button">daru-io</a></p>
<p><a class="btn btn-lg btn-success" href="https://github.com/Sciruby/daru-io" role="button">daru-io</a></p>
<p class="text-muted">A set of independent importers/exporters from various data sources and formats.</p>
</div>
<div class="col-md-6">
<p><a class="btn btn-lg btn-success" href="https://github.com/shekharrajak/daru-view" role="button">daru-view</a></p>
<p><a class="btn btn-lg btn-success" href="https://github.com/Sciruby/daru-view" role="button">daru-view</a></p>
<p class="text-muted">A set of view helpers for web frameworks, for pretty representations of data.</p>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<!-- dependent script -->
<%=raw Daru::View.dependent_script(:datatables) %>
<%=raw Daru::View.dependent_script(:googlecharts) %>
<%=raw Daru::View.dependent_script(:highcharts) %>

<style>
.container { max-width: 800px; }
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
get '/sciruby/repos', to: 'sciruby_github#repos'
get '/sciruby/watchers', to: 'sciruby_github#watchers'
get '/election/data', to: 'election#data'
get '/countries', to: 'countries#data_countries'
get '/', to: 'front_page#home'
end
7 changes: 7 additions & 0 deletions test/controllers/countries_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class CountriesControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end

0 comments on commit 39db236

Please sign in to comment.