diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 39c7d5f1..b790d899 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -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 . diff --git a/app/controllers/logs_controller.rb b/app/controllers/logs_controller.rb index 3b3c21f8..3f84c44f 100644 --- a/app/controllers/logs_controller.rb +++ b/app/controllers/logs_controller.rb @@ -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 diff --git a/app/views/logs/graph.html.slim b/app/views/logs/graph.html.slim new file mode 100644 index 00000000..07e2920a --- /dev/null +++ b/app/views/logs/graph.html.slim @@ -0,0 +1,2 @@ += high_chart('column', @column) += high_chart('spline', @spline) diff --git a/app/views/logs/list.html.slim b/app/views/logs/list.html.slim index 87515273..b69a7f78 100644 --- a/app/views/logs/list.html.slim +++ b/app/views/logs/list.html.slim @@ -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 diff --git a/app/views/welcomes/index.html.slim b/app/views/welcomes/index.html.slim index 7df17a3d..4a1ecfac 100644 --- a/app/views/welcomes/index.html.slim +++ b/app/views/welcomes/index.html.slim @@ -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' + diff --git a/config/routes.rb b/config/routes.rb index 21d58741..d808909d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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