Skip to content

Commit

Permalink
close #19 グラフを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
8398a7 committed Nov 17, 2014
1 parent 6f846f6 commit 7c8145f
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
//= require twitter/bootstrap
//= require dataTables/jquery.dataTables
//= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
//= require highcharts/highcharts
//= require highcharts/highcharts-more
//= require highcharts/highstock
//= require turbolinks
//= require_tree .
59 changes: 59 additions & 0 deletions app/controllers/logs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,63 @@ def show
@logs = Log.where(user_id: current_user.id, created_at: params[:date]).preload(:sheet)
@color = Score.list_color
end

def graph
user_id = User.find_by(iidxid: params[:iidxid]).id
oldest = (User.find_by(id: user_id).logs.order(created_at: :desc).last.created_at.strftime('%Y-%m') + '-01').to_date
now = Time.now.strftime('%Y-%m')
lastest = (now + '-01').to_date
between = between_create(oldest, lastest)

category, fc_count, exh_count, h_count, c_count, e_count, cl_cnt, hd_cnt = [], [], [], [], [], [], [], []
st = between.first[0]
all = Sheet.all.count
between.each do |b|
category.push(b[0].strftime('%Y-%m').slice(2, 5))
cl_cnt.push(all - Log.where(user_id: user_id, new_state: 0..4, created_at: st..b[1]).select(:sheet_id).uniq.count)
hd_cnt.push(all - Log.where(user_id: user_id, new_state: 0..2, created_at: st..b[1]).select(:sheet_id).uniq.count)
fc_count.push(Log.where(user_id: user_id, new_state: 0, created_at: b[0]..b[1]).count)
exh_count.push(Log.where(user_id: user_id, new_state: 1, created_at: b[0]..b[1]).count)
h_count.push(Log.where(user_id: user_id, new_state: 2, created_at: b[0]..b[1]).count)
c_count.push(Log.where(user_id: user_id, new_state: 3, created_at: b[0]..b[1]).count)
e_count.push(Log.where(user_id: user_id, new_state: 4, created_at: b[0]..b[1]).count)
end

@column = LazyHighCharts::HighChart.new('column') do |f|
f.title(text: '月別更新数')
f.chart(type: 'column')
f.xAxis(categories: category)
f.legend(layout: 'vertical', align: 'right', verticalAlign: 'middle', borderWidth: 0)
f.yAxis(allowDecimals: false, title: { text: '更新数' })
f.series(name: 'FC', data: fc_count, color: '#ff8c00')
f.series(name: 'EXH', data: exh_count, color: '#fffacd')
f.series(name: 'HARD', data: h_count, color: '#ff6347')
f.series(name: 'CLEAR', data: c_count, color: '#afeeee')
f.series(name: 'EASY', data: e_count, color: '#98fb98')
end

@spline = LazyHighCharts::HighChart.new('spline') do |f|
f.title(text: '未クリア,未難推移')
f.chart(type: 'spline')
f.xAxis(categories: category)
f.yAxis(allowDecimals: false, max: all, title: { text: '未達成数' })
f.legend(layout: 'vertical', align: 'right', verticalAlign: 'middle', borderWidth: 0)
f.series(name: '未クリア', data: cl_cnt, color: '#afeeee')
f.series(name: '未難', data: hd_cnt, color: '#ff6347')
end
end

private

def between_create(o, l)
array = []
s = o
while 0 < 1
e = s + 1.months - 1.days
array.push([s, e])
s += 1.months
break if s == l + 1.months
end
array
end
end
2 changes: 2 additions & 0 deletions app/views/logs/graph.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
= high_chart('column', @column)
= high_chart('spline', @spline)
1 change: 1 addition & 0 deletions app/views/logs/list.html.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
= link_to '表のクリア推移', sheet_log_path, class: 'btn btn-warning'
= link_to '月別情報', graph_logs_path, class: 'btn btn-success'

h2 更新履歴
table.datatable
Expand Down
8 changes: 8 additions & 0 deletions app/views/welcomes/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@
= n.body
- if @notices.count == 0
p 特にありません。
.col-lg-12
.panel.panel-success
.panel-heading
h3 可視化例
.panel-body
.center
= image_tag '/images/example.png'

1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
patch '/scores/:id' => 'scores#update'

# log
get '/logs/:iidxid/graph' => 'logs#graph', as: :graph_logs
get '/logs/:iidxid/list' => 'logs#list', as: :list_logs
get '/logs/:iidxid/sheet' => 'logs#sheet', as: :sheet_log
get '/logs/:iidxid/:date' => 'logs#show', as: :show_log
Expand Down

0 comments on commit 7c8145f

Please sign in to comment.