Skip to content

Commit

Permalink
Add XSLX and CSV formats to reports, add HTML report for sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
D Coetzee committed Jan 8, 2015
1 parent af9f6e2 commit 37f8497
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ gem 'pg'
gem 'rack-p3p'
gem 'momentjs-rails' # prereq of datetimepicker
gem 'bootstrap3-datetimepicker-rails'
gem 'rubyzip', "~> 1.0.0" # prereq of axlsx, axlsx 2.0.1 requires old version
gem 'axlsx', "~> 2.0.1"
gem 'axlsx_rails'
gem 'csv_builder'

group :development, :test do
gem 'debugger'
Expand Down
22 changes: 18 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ GEM
autotest-rails (4.2.1)
ZenTest (~> 4.5)
awesome_print (1.2.0)
axlsx (2.0.1)
htmlentities (~> 4.3.1)
nokogiri (>= 1.4.1)
rubyzip (~> 1.0.0)
axlsx_rails (0.1.5)
axlsx
rails (>= 3.1)
bootstrap3-datetimepicker-rails (3.1.3)
momentjs-rails (>= 2.8.1)
builder (3.0.4)
Expand Down Expand Up @@ -74,6 +81,8 @@ GEM
coffee-script-source (1.7.0)
colored (1.2)
columnize (0.8.9)
csv_builder (2.1.1)
actionpack (>= 3.0.0)
cucumber (1.3.15)
builder (>= 2.1.2)
diff-lcs (>= 1.1.3)
Expand Down Expand Up @@ -139,6 +148,7 @@ GEM
hashie (2.1.2)
hike (1.2.3)
hirb (0.7.2)
htmlentities (4.3.3)
i18n (0.6.9)
jasmine-core (2.0.0)
jasmine-jquery-rails (2.0.3)
Expand Down Expand Up @@ -181,16 +191,16 @@ GEM
roodi (~> 3.1)
metric_fu-Saikuro (1.1.3)
mime-types (1.25.1)
mini_portile (0.6.0)
mini_portile (0.6.2)
momentjs-rails (2.8.3)
railties (>= 3.1)
multi_json (1.10.1)
multi_test (0.1.1)
multi_xml (0.5.5)
multipart-post (2.0.0)
newrelic_rpm (3.9.5.251)
nokogiri (1.6.2.1)
mini_portile (= 0.6.0)
nokogiri (1.6.5)
mini_portile (~> 0.6.0)
oauth2 (1.0.0)
faraday (>= 0.8, < 0.10)
jwt (~> 1.0)
Expand Down Expand Up @@ -292,7 +302,7 @@ GEM
sexp_processor (~> 4.0)
ruby_parser (3.6.1)
sexp_processor (~> 4.1)
rubyzip (1.1.4)
rubyzip (1.0.0)
sass (3.2.13)
sass-rails (3.2.6)
railties (~> 3.2.0)
Expand Down Expand Up @@ -341,9 +351,12 @@ PLATFORMS

DEPENDENCIES
autotest-rails
axlsx (~> 2.0.1)
axlsx_rails
bootstrap3-datetimepicker-rails
capybara-puma
coffee-rails (~> 3.2.1)
csv_builder
cucumber-rails
cucumber-rails-training-wheels
cucumber-timecop
Expand Down Expand Up @@ -372,6 +385,7 @@ DEPENDENCIES
rails (= 3.2.18)
rails_12factor
rspec-rails (= 2.14.0)
rubyzip (~> 1.0.0)
sass (= 3.2.13)
sass-rails (~> 3.2.3)
selenium-webdriver
Expand Down
9 changes: 6 additions & 3 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ def chatlog_show

respond_to do |format|
format.html # 'chatlog_show.html.erb'
format.xml # 'chatlog_show.xml.builder'
format.json { render json: @eventlog_sessions }
format.xml # 'chatlog_show.xml.builder'
format.csv # 'chatlog_show.csv.csvbuilder'
format.xlsx # 'chatlog_show.xlsx.axlsx'
end
end

Expand Down Expand Up @@ -65,8 +66,10 @@ def sessions_show
end

respond_to do |format|
format.html # 'sessions_show.html.erb'
format.xml # 'sessions_show.xml.builder'
format.json { render json: @sessions }
format.csv # 'sessions_show.csv.csvbuilder'
format.xlsx # 'sessions_show.xlsx.axlsx'
end
end
end
2 changes: 1 addition & 1 deletion app/views/reports/chatlog.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<label for="datetimepicker_start"><b>Format</b></label><br/>
</div>
<div class='col-sm-1'>
<%= select_tag(:format, options_for_select([['HTML', 'html'], ['XML', 'xml'], ['JSON', 'json']])) %>
<%= select_tag(:format, options_for_select([['HTML', 'html'], ['XML', 'xml'], ['CSV', 'csv'], ['XLSX (Excel)', 'xlsx']])) %>
</div>
</div>
<br><br>
Expand Down
12 changes: 12 additions & 0 deletions app/views/reports/chatlog_show.csv.csvbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
model_class = EventLog
csv << ['Session chat group'] + [:created_at, :task_id, :chat_group, :name, :value].map{|attr| model_class.human_attribute_name(attr)}
@eventlog_sessions.each do |session|
session.each do |event|
csv << [event.task.original_chat_group,
event.created_at,
event.task_id,
event.chat_group,
event.name,
event.value]
end
end
1 change: 0 additions & 1 deletion app/views/reports/chatlog_show.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<%- model_class = EventLog -%>

<!-- Order by original chat group, which is property on Task -->
<% @eventlog_sessions.each do |session| %>
<table class="table">
<tr>
Expand Down
18 changes: 18 additions & 0 deletions app/views/reports/chatlog_show.xlsx.axlsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
model_class = EventLog
wb = xlsx_package.workbook
wb.add_worksheet(name: "Chat Log") do |sheet|
time_format = wb.styles.add_style :format_code => 'MM/DD hh:mm:ss'
sheet.add_row (['Session chat group'] + [:created_at, :task_id, :chat_group, :name, :value].map{|attr| model_class.human_attribute_name(attr)})
@eventlog_sessions.each do |session|
session.each do |event|
sheet.add_row [event.task.original_chat_group,
event.created_at,
event.task_id,
event.chat_group,
event.name,
event.value],
:style => [nil, time_format],
:types => [:string, :time, :integer, :string, :string, :string]
end
end
end
2 changes: 1 addition & 1 deletion app/views/reports/sessions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<label for="datetimepicker_start"><b>Format</b></label><br/>
</div>
<div class='col-sm-1'>
<%= select_tag(:format, options_for_select([['XML', 'xml'], ['JSON', 'json']])) %>
<%= select_tag(:format, options_for_select([['HTML', 'html'], ['XML', 'xml'], ['CSV', 'csv'], ['XLSX (Excel)', 'xlsx']])) %>
</div>
</div>
<br><br>
Expand Down
12 changes: 12 additions & 0 deletions app/views/reports/sessions_show.csv.csvbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
csv << ['chat_group', 'group_size',
'question_id', 'correct_choice',
'start_time_0', 'start_time_1', 'start_time_2',
'initial_choice_0', 'initial_choice_1', 'initial_choice_2',
'final_choice_0', 'final_choice_1', 'final_choice_2']
@sessions.each do |session|
csv << [session[:chat_group], session[:group_size],
session[:question_id], session[:correct_choice],
session[:start_time_0], session[:start_time_1], session[:start_time_2],
session[:initial_choice_0], session[:initial_choice_1], session[:initial_choice_2],
session[:final_choice_0], session[:final_choice_1], session[:final_choice_2]]
end
34 changes: 34 additions & 0 deletions app/views/reports/sessions_show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<table class="table">
<tr>
<th>chat_group</th>
<th>group_size</th>
<th>question_id</th>
<th>correct_choice</th>
<th>start_time_0</th>
<th>start_time_1</th>
<th>start_time_2</th>
<th>initial_choice_0</th>
<th>initial_choice_1</th>
<th>initial_choice_2</th>
<th>final_choice_0</th>
<th>final_choice_1</th>
<th>final_choice_2</th>
</tr>
<% @sessions.each do |session| %>
<tr>
<td><%= session[:chat_group] %></td>
<td><%= session[:group_size] %></td>
<td><%= session[:question_id] %></td>
<td><%= session[:correct_choice] %></td>
<td><%= session[:start_time_0] %></td>
<td><%= session[:start_time_1] %></td>
<td><%= session[:start_time_2] %></td>
<td><%= session[:initial_choice_0] %></td>
<td><%= session[:initial_choice_1] %></td>
<td><%= session[:initial_choice_2] %></td>
<td><%= session[:final_choice_0] %></td>
<td><%= session[:final_choice_1] %></td>
<td><%= session[:final_choice_2] %></td>
</tr>
<% end %>
</table>
22 changes: 22 additions & 0 deletions app/views/reports/sessions_show.xlsx.axlsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
wb = xlsx_package.workbook
wb.add_worksheet(name: "Sessions") do |sheet|
time_format = wb.styles.add_style :format_code => 'MM/DD hh:mm:ss'
sheet.add_row ['chat_group', 'group_size',
'question_id', 'correct_choice',
'start_time_0', 'start_time_1', 'start_time_2',
'initial_choice_0', 'initial_choice_1', 'initial_choice_2',
'final_choice_0', 'final_choice_1', 'final_choice_2']
@sessions.each do |session|
sheet.add_row [session[:chat_group], session[:group_size],
session[:question_id], session[:correct_choice],
session[:start_time_0], session[:start_time_1], session[:start_time_2],
session[:initial_choice_0], session[:initial_choice_1], session[:initial_choice_2],
session[:final_choice_0], session[:final_choice_1], session[:final_choice_2]],
:style => [nil, nil, nil, nil, time_format, time_format, time_format],
:types => [:string, :integer,
:integer, :string,
:time, :time, :time,
:string, :string, :string,
:string, :string, :string]
end
end

0 comments on commit 37f8497

Please sign in to comment.