mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 15:20:13 +01:00
#1153: Convert rest of the stats to use ChartJS
This commit is contained in:
parent
dec82fd26c
commit
f873a93eb3
5 changed files with 206 additions and 255 deletions
|
|
@ -1266,7 +1266,7 @@ button.positive, .widgets a.positive{
|
||||||
background-color:black;
|
background-color:black;
|
||||||
}
|
}
|
||||||
|
|
||||||
.stats_content .open-flash-chart, .stats_content .stats_module {
|
.stats_content .chart, .stats_content .stats_module {
|
||||||
float: left;
|
float: left;
|
||||||
width: 450px;
|
width: 450px;
|
||||||
margin-right:20px;
|
margin-right:20px;
|
||||||
|
|
|
||||||
|
|
@ -11,42 +11,6 @@ class StatsController < ApplicationController
|
||||||
@stats = Stats::UserStats.new(current_user)
|
@stats = Stats::UserStats.new(current_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def actions_done_last12months_data
|
|
||||||
# get actions created and completed in the past 12+3 months. +3 for running
|
|
||||||
# - outermost set of entries needed for these calculations
|
|
||||||
actions_last12months = current_user.todos.created_or_completed_after(@cut_off_year_plus3).select("completed_at,created_at")
|
|
||||||
|
|
||||||
# convert to array and fill in non-existing months
|
|
||||||
@actions_done_last12months_array = put_events_into_month_buckets(actions_last12months, 13, :completed_at)
|
|
||||||
@actions_created_last12months_array = put_events_into_month_buckets(actions_last12months, 13, :created_at)
|
|
||||||
|
|
||||||
# find max for graph in both arrays
|
|
||||||
@max = (@actions_done_last12months_array + @actions_created_last12months_array).max
|
|
||||||
|
|
||||||
# find running avg
|
|
||||||
done_in_last_15_months = put_events_into_month_buckets(actions_last12months, 16, :completed_at)
|
|
||||||
created_in_last_15_months = put_events_into_month_buckets(actions_last12months, 16, :created_at)
|
|
||||||
|
|
||||||
@actions_done_avg_last12months_array = compute_running_avg_array(done_in_last_15_months, 13)
|
|
||||||
@actions_created_avg_last12months_array = compute_running_avg_array(created_in_last_15_months, 13)
|
|
||||||
|
|
||||||
# interpolate avg for current month.
|
|
||||||
@interpolated_actions_created_this_month = interpolate_avg_for_current_month(@actions_created_last12months_array)
|
|
||||||
@interpolated_actions_done_this_month = interpolate_avg_for_current_month(@actions_done_last12months_array)
|
|
||||||
|
|
||||||
@created_count_array = Array.new(13, actions_last12months.created_after(@cut_off_year).count(:all)/12.0)
|
|
||||||
@done_count_array = Array.new(13, actions_last12months.completed_after(@cut_off_year).count(:all)/12.0)
|
|
||||||
render :layout => false
|
|
||||||
end
|
|
||||||
|
|
||||||
def interpolate_avg_for_current_month(set)
|
|
||||||
(set[0]*(1/percent_of_month) + set[1] + set[2]) / 3.0
|
|
||||||
end
|
|
||||||
|
|
||||||
def percent_of_month
|
|
||||||
Time.zone.now.day / Time.zone.now.end_of_month.day.to_f
|
|
||||||
end
|
|
||||||
|
|
||||||
def actions_done_last_years
|
def actions_done_last_years
|
||||||
@page_title = t('stats.index_title')
|
@page_title = t('stats.index_title')
|
||||||
@chart = Stats::Chart.new('actions_done_lastyears_data', :height => 400, :width => 900)
|
@chart = Stats::Chart.new('actions_done_lastyears_data', :height => 400, :width => 900)
|
||||||
|
|
@ -80,98 +44,6 @@ class StatsController < ApplicationController
|
||||||
render :layout => false
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
def actions_done_last30days_data
|
|
||||||
# get actions created and completed in the past 30 days.
|
|
||||||
@actions_done_last30days = current_user.todos.completed_after(@cut_off_30days).select("completed_at")
|
|
||||||
@actions_created_last30days = current_user.todos.created_after(@cut_off_30days).select("created_at")
|
|
||||||
|
|
||||||
# convert to array. 30+1 to have 30 complete days and one current day [0]
|
|
||||||
@actions_done_last30days_array = convert_to_days_from_today_array(@actions_done_last30days, 31, :completed_at)
|
|
||||||
@actions_created_last30days_array = convert_to_days_from_today_array(@actions_created_last30days, 31, :created_at)
|
|
||||||
|
|
||||||
# find max for graph in both hashes
|
|
||||||
@max = [@actions_done_last30days_array.max, @actions_created_last30days_array.max].max
|
|
||||||
|
|
||||||
render :layout => false
|
|
||||||
end
|
|
||||||
|
|
||||||
def actions_completion_time_data
|
|
||||||
@actions_completion_time = current_user.todos.completed.select("completed_at, created_at").reorder("completed_at DESC" )
|
|
||||||
|
|
||||||
# convert to array and fill in non-existing weeks with 0
|
|
||||||
@max_weeks = @actions_completion_time.last ? difference_in_weeks(@today, @actions_completion_time.last.completed_at) : 1
|
|
||||||
@actions_completed_per_week_array = convert_to_weeks_running_array(@actions_completion_time, @max_weeks+1)
|
|
||||||
|
|
||||||
# stop the chart after 10 weeks
|
|
||||||
@count = [10, @max_weeks].min
|
|
||||||
|
|
||||||
# convert to new array to hold max @cut_off elems + 1 for sum of actions after @cut_off
|
|
||||||
@actions_completion_time_array = cut_off_array_with_sum(@actions_completed_per_week_array, @count)
|
|
||||||
@max_actions = @actions_completion_time_array.max
|
|
||||||
|
|
||||||
# get percentage done cumulative
|
|
||||||
@cum_percent_done = convert_to_cumulative_array(@actions_completion_time_array, @actions_completion_time.count(:all))
|
|
||||||
|
|
||||||
render :layout => false
|
|
||||||
end
|
|
||||||
|
|
||||||
def actions_running_time_data
|
|
||||||
@actions_running_time = current_user.todos.not_completed.select("created_at").reorder("created_at DESC")
|
|
||||||
|
|
||||||
# convert to array and fill in non-existing weeks with 0
|
|
||||||
@max_weeks = difference_in_weeks(@today, @actions_running_time.last.created_at)
|
|
||||||
@actions_running_per_week_array = convert_to_weeks_from_today_array(@actions_running_time, @max_weeks+1, :created_at)
|
|
||||||
|
|
||||||
# cut off chart at 52 weeks = one year
|
|
||||||
@count = [52, @max_weeks].min
|
|
||||||
|
|
||||||
# convert to new array to hold max @cut_off elems + 1 for sum of actions after @cut_off
|
|
||||||
@actions_running_time_array = cut_off_array_with_sum(@actions_running_per_week_array, @count)
|
|
||||||
@max_actions = @actions_running_time_array.max
|
|
||||||
|
|
||||||
# get percentage done cumulative
|
|
||||||
@cum_percent_done = convert_to_cumulative_array(@actions_running_time_array, @actions_running_time.count )
|
|
||||||
|
|
||||||
render :layout => false
|
|
||||||
end
|
|
||||||
|
|
||||||
def actions_visible_running_time_data
|
|
||||||
# running means
|
|
||||||
# - not completed (completed_at must be null)
|
|
||||||
# visible means
|
|
||||||
# - actions not part of a hidden project
|
|
||||||
# - actions not part of a hidden context
|
|
||||||
# - actions not deferred (show_from must be null)
|
|
||||||
# - actions not pending/blocked
|
|
||||||
|
|
||||||
@actions_running_time = current_user.todos.not_completed.not_hidden.not_deferred_or_blocked.
|
|
||||||
select("todos.created_at").
|
|
||||||
reorder("todos.created_at DESC")
|
|
||||||
|
|
||||||
@max_weeks = difference_in_weeks(@today, @actions_running_time.last.created_at)
|
|
||||||
@actions_running_per_week_array = convert_to_weeks_from_today_array(@actions_running_time, @max_weeks+1, :created_at)
|
|
||||||
|
|
||||||
# cut off chart at 52 weeks = one year
|
|
||||||
@count = [52, @max_weeks].min
|
|
||||||
|
|
||||||
# convert to new array to hold max @cut_off elems + 1 for sum of actions after @cut_off
|
|
||||||
@actions_running_time_array = cut_off_array_with_sum(@actions_running_per_week_array, @count)
|
|
||||||
@max_actions = @actions_running_time_array.max
|
|
||||||
|
|
||||||
# get percentage done cumulative
|
|
||||||
@cum_percent_done = convert_to_cumulative_array(@actions_running_time_array, @actions_running_time.count )
|
|
||||||
|
|
||||||
render :layout => false
|
|
||||||
end
|
|
||||||
|
|
||||||
def context_total_actions_data
|
|
||||||
actions = Stats::TopContextsQuery.new(current_user).result
|
|
||||||
|
|
||||||
@data = Stats::PieChartData.new(actions, t('stats.spread_of_actions_for_all_context'), 70)
|
|
||||||
|
|
||||||
render :pie_chart_data, :layout => false
|
|
||||||
end
|
|
||||||
|
|
||||||
def context_running_actions_data
|
def context_running_actions_data
|
||||||
actions = Stats::TopContextsQuery.new(current_user, :running => true).result
|
actions = Stats::TopContextsQuery.new(current_user, :running => true).result
|
||||||
@data = Stats::PieChartData.new(actions, t('stats.spread_of_running_actions_for_visible_contexts'), 60)
|
@data = Stats::PieChartData.new(actions, t('stats.spread_of_running_actions_for_visible_contexts'), 60)
|
||||||
|
|
@ -298,84 +170,4 @@ class StatsController < ApplicationController
|
||||||
def put_events_into_month_buckets(records, array_size, date_method_on_todo)
|
def put_events_into_month_buckets(records, array_size, date_method_on_todo)
|
||||||
convert_to_array(records.select { |x| x.send(date_method_on_todo) }, array_size) { |r| [difference_in_months(@today, r.send(date_method_on_todo))]}
|
convert_to_array(records.select { |x| x.send(date_method_on_todo) }, array_size) { |r| [difference_in_months(@today, r.send(date_method_on_todo))]}
|
||||||
end
|
end
|
||||||
|
|
||||||
def convert_to_days_from_today_array(records, array_size, date_method_on_todo)
|
|
||||||
return convert_to_array(records, array_size){ |r| [difference_in_days(@today, r.send(date_method_on_todo))]}
|
|
||||||
end
|
|
||||||
|
|
||||||
def convert_to_weeks_from_today_array(records, array_size, date_method_on_todo)
|
|
||||||
return convert_to_array(records, array_size) { |r| [difference_in_weeks(@today, r.send(date_method_on_todo))]}
|
|
||||||
end
|
|
||||||
|
|
||||||
def convert_to_weeks_running_array(records, array_size)
|
|
||||||
return convert_to_array(records, array_size) { |r| [difference_in_weeks(r.completed_at, r.created_at)]}
|
|
||||||
end
|
|
||||||
|
|
||||||
def convert_to_weeks_running_from_today_array(records, array_size)
|
|
||||||
return convert_to_array(records, array_size) { |r| week_indexes_of(r) }
|
|
||||||
end
|
|
||||||
|
|
||||||
def week_indexes_of(record)
|
|
||||||
a = []
|
|
||||||
start_week = difference_in_weeks(@today, record.created_at)
|
|
||||||
end_week = record.completed_at ? difference_in_weeks(@today, record.completed_at) : 0
|
|
||||||
end_week.upto(start_week) { |i| a << i };
|
|
||||||
return a
|
|
||||||
end
|
|
||||||
|
|
||||||
# returns a new array containing all elems of array up to cut_off and
|
|
||||||
# adds the sum of the rest of array to the last elem
|
|
||||||
def cut_off_array_with_sum(array, cut_off)
|
|
||||||
# +1 to hold sum of rest
|
|
||||||
a = Array.new(cut_off+1){|i| array[i]||0}
|
|
||||||
# add rest of array to last elem
|
|
||||||
a[cut_off] += array.inject(:+) - a.inject(:+)
|
|
||||||
return a
|
|
||||||
end
|
|
||||||
|
|
||||||
def cut_off_array(array, cut_off)
|
|
||||||
return Array.new(cut_off){|i| array[i]||0}
|
|
||||||
end
|
|
||||||
|
|
||||||
def convert_to_cumulative_array(array, max)
|
|
||||||
# calculate fractions
|
|
||||||
a = Array.new(array.size){|i| array[i]*100.0/max}
|
|
||||||
# make cumulative
|
|
||||||
1.upto(array.size-1){ |i| a[i] += a[i-1] }
|
|
||||||
return a
|
|
||||||
end
|
|
||||||
|
|
||||||
# assumes date1 > date2
|
|
||||||
# this results in the number of months before the month of date1, not taking days into account, so diff of 31-dec and 1-jan is 1 month!
|
|
||||||
def difference_in_months(date1, date2)
|
|
||||||
return (date1.utc.year - date2.utc.year)*12 + (date1.utc.month - date2.utc.month)
|
|
||||||
end
|
|
||||||
|
|
||||||
# assumes date1 > date2
|
|
||||||
def difference_in_days(date1, date2)
|
|
||||||
return ((date1.utc.at_midnight-date2.utc.at_midnight)/SECONDS_PER_DAY).to_i
|
|
||||||
end
|
|
||||||
|
|
||||||
# assumes date1 > date2
|
|
||||||
def difference_in_weeks(date1, date2)
|
|
||||||
return difference_in_days(date1, date2) / 7
|
|
||||||
end
|
|
||||||
|
|
||||||
def three_month_avg(set, i)
|
|
||||||
(set.fetch(i){ 0 } + set.fetch(i+1){ 0 } + set.fetch(i+2){ 0 }) / 3.0
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_three_month_avg(set,upper_bound)
|
|
||||||
(0..upper_bound-1).map { |i| three_month_avg(set, i) }
|
|
||||||
end
|
|
||||||
|
|
||||||
# sets "null" on first column and - if necessary - cleans up last two columns, which may have insufficient data
|
|
||||||
def compute_running_avg_array(set, upper_bound)
|
|
||||||
result = set_three_month_avg(set, upper_bound)
|
|
||||||
result[upper_bound-1] = result[upper_bound-1] * 3 if upper_bound == set.length
|
|
||||||
result[upper_bound-2] = result[upper_bound-2] * 3 / 2 if upper_bound > 1 and upper_bound == set.length
|
|
||||||
result[0] = "null"
|
|
||||||
result
|
|
||||||
end # unsolved, not triggered, edge case for set.length == upper_bound + 1
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -34,23 +34,99 @@ module Stats
|
||||||
@sum_actions_created_last12months ||= new_since(one_year)
|
@sum_actions_created_last12months ||= new_since(one_year)
|
||||||
end
|
end
|
||||||
|
|
||||||
def completion_charts
|
def done_last12months_data
|
||||||
@completion_charts ||= %w{
|
# get actions created and completed in the past 12+3 months. +3 for running
|
||||||
actions_done_last30days_data
|
# - outermost set of entries needed for these calculations
|
||||||
actions_done_last12months_data
|
actions_last12months = @user.todos.created_or_completed_after(@cut_off_year_plus3).select("completed_at,created_at")
|
||||||
actions_completion_time_data
|
|
||||||
}.map do |action|
|
# convert to array and fill in non-existing months
|
||||||
Stats::Chart.new(action)
|
@actions_done_last12months_array = put_events_into_month_buckets(actions_last12months, 13, :completed_at)
|
||||||
end
|
@actions_created_last12months_array = put_events_into_month_buckets(actions_last12months, 13, :created_at)
|
||||||
|
|
||||||
|
# find max for graph in both arrays
|
||||||
|
@max = (@actions_done_last12months_array + @actions_created_last12months_array).max
|
||||||
|
|
||||||
|
# find running avg
|
||||||
|
done_in_last_15_months = put_events_into_month_buckets(actions_last12months, 16, :completed_at)
|
||||||
|
created_in_last_15_months = put_events_into_month_buckets(actions_last12months, 16, :created_at)
|
||||||
|
|
||||||
|
@actions_done_avg_last12months_array = compute_running_avg_array(done_in_last_15_months, 13)
|
||||||
|
@actions_created_avg_last12months_array = compute_running_avg_array(created_in_last_15_months, 13)
|
||||||
|
|
||||||
|
# interpolate avg for current month.
|
||||||
|
@interpolated_actions_created_this_month = interpolate_avg_for_current_month(@actions_created_last12months_array)
|
||||||
|
@interpolated_actions_done_this_month = interpolate_avg_for_current_month(@actions_done_last12months_array)
|
||||||
|
|
||||||
|
@created_count_array = Array.new(13, actions_last12months.created_after(@cut_off_year).count(:all)/12.0)
|
||||||
|
@done_count_array = Array.new(13, actions_last12months.completed_after(@cut_off_year).count(:all)/12.0)
|
||||||
|
|
||||||
|
return {
|
||||||
|
datasets: [
|
||||||
|
{label: "Avg created", data: @created_count_array.map { |total| [total] }, type: "line"},
|
||||||
|
{label: "Avg completed", data: @done_count_array.map { |total| [total] }, type: "line"},
|
||||||
|
{label: "3 months avg completed", data: @actions_done_avg_last12months_array.map { |total| [total] }, type: "line"},
|
||||||
|
{label: "3 months avg created", data: @actions_created_avg_last12months_array.map { |total| [total] }, type: "line"},
|
||||||
|
{label: "Created", data: @actions_created_last12months_array.map { |total| [total] } },
|
||||||
|
{label: "Completed", data: @actions_done_last12months_array.map { |total| [total] } }
|
||||||
|
],
|
||||||
|
labels: @actions_done_avg_last12months_array.each_with_index.map { |total, month| [month] }
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def timing_charts
|
def done_last30days_data
|
||||||
@timing_charts ||= %w{
|
# get actions created and completed in the past 30 days.
|
||||||
actions_visible_running_time_data
|
@actions_done_last30days = @user.todos.completed_after(@cut_off_30days).select("completed_at")
|
||||||
actions_running_time_data
|
@actions_created_last30days = @user.todos.created_after(@cut_off_30days).select("created_at")
|
||||||
}.map do |action|
|
|
||||||
Stats::Chart.new(action)
|
# convert to array. 30+1 to have 30 complete days and one current day [0]
|
||||||
end
|
@actions_done_last30days_array = convert_to_days_from_today_array(@actions_done_last30days, 31, :completed_at)
|
||||||
|
@actions_created_last30days_array = convert_to_days_from_today_array(@actions_created_last30days, 31, :created_at)
|
||||||
|
|
||||||
|
# find max for graph in both hashes
|
||||||
|
@max = [@actions_done_last30days_array.max, @actions_created_last30days_array.max].max
|
||||||
|
|
||||||
|
created_count_array = Array.new(30){ |i| @actions_created_last30days.size/30.0 }
|
||||||
|
done_count_array = Array.new(30){ |i| @actions_done_last30days.size/30.0 }
|
||||||
|
# TODO: make the strftime i18n proof
|
||||||
|
# TODO: Fix this, broke during transition from Flash-based stats.
|
||||||
|
# time_labels = Array.new(30){ |i| l(Time.zone.now-i.days, :format => :stats) }
|
||||||
|
|
||||||
|
return {
|
||||||
|
datasets: [
|
||||||
|
{label: "Avg created", data: created_count_array.map { |total| [total] }, type: "line"},
|
||||||
|
{label: "Avg completed", data: done_count_array.map { |total| [total] }, type: "line"},
|
||||||
|
{label: "Created", data: @actions_created_last30days_array.map { |total| [total] } },
|
||||||
|
{label: "Completed", data: @actions_done_last30days_array.map { |total| [total] } }
|
||||||
|
],
|
||||||
|
# labels: time_labels
|
||||||
|
labels: @actions_done_last30days_array.each_with_index.map { |total, days| [days] }
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def completion_time_data
|
||||||
|
@actions_completion_time = @user.todos.completed.select("completed_at, created_at").reorder("completed_at DESC" )
|
||||||
|
|
||||||
|
# convert to array and fill in non-existing weeks with 0
|
||||||
|
@max_weeks = @actions_completion_time.last ? difference_in_weeks(@today, @actions_completion_time.last.completed_at) : 1
|
||||||
|
@actions_completed_per_week_array = convert_to_weeks_running_array(@actions_completion_time, @max_weeks+1)
|
||||||
|
|
||||||
|
# stop the chart after 10 weeks
|
||||||
|
@count = [10, @max_weeks].min
|
||||||
|
|
||||||
|
# convert to new array to hold max @cut_off elems + 1 for sum of actions after @cut_off
|
||||||
|
@actions_completion_time_array = cut_off_array_with_sum(@actions_completed_per_week_array, @count)
|
||||||
|
@max_actions = @actions_completion_time_array.max
|
||||||
|
|
||||||
|
# get percentage done cumulative
|
||||||
|
@cum_percent_done = convert_to_cumulative_array(@actions_completion_time_array, @actions_completion_time.count(:all))
|
||||||
|
|
||||||
|
return {
|
||||||
|
datasets: [
|
||||||
|
{label: "Percentage", data: @cum_percent_done.map { |total| [total] }, type: "line"},
|
||||||
|
{label: "Actions", data: @actions_completion_time_array.map { |total| [total] } }
|
||||||
|
],
|
||||||
|
labels: @actions_completion_time_array.each_with_index.map { |total, week| [week] }
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def running_time_data
|
def running_time_data
|
||||||
|
|
@ -70,10 +146,48 @@ module Stats
|
||||||
# get percentage done cumulative
|
# get percentage done cumulative
|
||||||
@cum_percent_done = convert_to_cumulative_array(@actions_running_time_array, @actions_running_time.count )
|
@cum_percent_done = convert_to_cumulative_array(@actions_running_time_array, @actions_running_time.count )
|
||||||
|
|
||||||
return [
|
return {
|
||||||
{name: "Percentage", data: @cum_percent_done.each_with_index.map { |total, week| [week, total] } , type: "line"},
|
datasets: [
|
||||||
{name: "Actions", data: @actions_running_time_array.each_with_index.map { |total, week| [week, total] } }
|
{label: "Percentage", data: @cum_percent_done.map { |total| [total] }, type: "line"},
|
||||||
]
|
{label: "Actions", data: @actions_running_time_array.map { |total| [total] } }
|
||||||
|
],
|
||||||
|
labels: @actions_running_time_array.each_with_index.map { |total, week| [week] }
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def visible_running_time_data
|
||||||
|
# running means
|
||||||
|
# - not completed (completed_at must be null)
|
||||||
|
# visible means
|
||||||
|
# - actions not part of a hidden project
|
||||||
|
# - actions not part of a hidden context
|
||||||
|
# - actions not deferred (show_from must be null)
|
||||||
|
# - actions not pending/blocked
|
||||||
|
|
||||||
|
@actions_running_time = @user.todos.not_completed.not_hidden.not_deferred_or_blocked.
|
||||||
|
select("todos.created_at").
|
||||||
|
reorder("todos.created_at DESC")
|
||||||
|
|
||||||
|
@max_weeks = difference_in_weeks(@today, @actions_running_time.last.created_at)
|
||||||
|
@actions_running_per_week_array = convert_to_weeks_from_today_array(@actions_running_time, @max_weeks+1, :created_at)
|
||||||
|
|
||||||
|
# cut off chart at 52 weeks = one year
|
||||||
|
@count = [52, @max_weeks].min
|
||||||
|
|
||||||
|
# convert to new array to hold max @cut_off elems + 1 for sum of actions after @cut_off
|
||||||
|
@actions_running_time_array = cut_off_array_with_sum(@actions_running_per_week_array, @count)
|
||||||
|
@max_actions = @actions_running_time_array.max
|
||||||
|
|
||||||
|
# get percentage done cumulative
|
||||||
|
@cum_percent_done = convert_to_cumulative_array(@actions_running_time_array, @actions_running_time.count )
|
||||||
|
|
||||||
|
return {
|
||||||
|
datasets: [
|
||||||
|
{label: "Percentage", data: @cum_percent_done.map { |total| [total] }, type: "line"},
|
||||||
|
{label: "Actions", data: @actions_running_time_array.map { |total| [total] } }
|
||||||
|
],
|
||||||
|
labels: @actions_running_time_array.each_with_index.map { |total, week| [week] }
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def open_per_week_data
|
def open_per_week_data
|
||||||
|
|
@ -89,7 +203,12 @@ module Stats
|
||||||
@actions_open_per_week_array = convert_to_weeks_running_from_today_array(@actions_started, @max_weeks+1)
|
@actions_open_per_week_array = convert_to_weeks_running_from_today_array(@actions_started, @max_weeks+1)
|
||||||
@actions_open_per_week_array = cut_off_array(@actions_open_per_week_array, @count)
|
@actions_open_per_week_array = cut_off_array(@actions_open_per_week_array, @count)
|
||||||
|
|
||||||
return @actions_open_per_week_array.each_with_index.map { |total, week| [week, total] }
|
return {
|
||||||
|
datasets: [
|
||||||
|
{label: "Actions", data: @actions_open_per_week_array.map { |total| [total] } }
|
||||||
|
],
|
||||||
|
labels: @actions_open_per_week_array.each_with_index.map { |total, week| [week] }
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def day_of_week_all_data
|
def day_of_week_all_data
|
||||||
|
|
@ -202,14 +321,12 @@ module Stats
|
||||||
@completed ||= user.todos.completed.select("completed_at, created_at")
|
@completed ||= user.todos.completed.select("completed_at, created_at")
|
||||||
end
|
end
|
||||||
|
|
||||||
# assumes date1 > date2
|
def interpolate_avg_for_current_month(set)
|
||||||
def difference_in_days(date1, date2)
|
(set[0]*(1/percent_of_month) + set[1] + set[2]) / 3.0
|
||||||
return ((date1.utc.at_midnight-date2.utc.at_midnight)/SECONDS_PER_DAY).to_i
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# assumes date1 > date2
|
def percent_of_month
|
||||||
def difference_in_weeks(date1, date2)
|
Time.zone.now.day / Time.zone.now.end_of_month.day.to_f
|
||||||
return difference_in_days(date1, date2) / 7
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# uses the supplied block to determine array of indexes in hash
|
# uses the supplied block to determine array of indexes in hash
|
||||||
|
|
@ -220,12 +337,24 @@ module Stats
|
||||||
a
|
a
|
||||||
end
|
end
|
||||||
|
|
||||||
def convert_to_weeks_running_from_today_array(records, array_size)
|
def put_events_into_month_buckets(records, array_size, date_method_on_todo)
|
||||||
return convert_to_array(records, array_size) { |r| week_indexes_of(r) }
|
convert_to_array(records.select { |x| x.send(date_method_on_todo) }, array_size) { |r| [difference_in_months(@today, r.send(date_method_on_todo))]}
|
||||||
end
|
end
|
||||||
|
|
||||||
def cut_off_array(array, cut_off)
|
def convert_to_days_from_today_array(records, array_size, date_method_on_todo)
|
||||||
return Array.new(cut_off){|i| array[i]||0}
|
return convert_to_array(records, array_size){ |r| [difference_in_days(@today, r.send(date_method_on_todo))]}
|
||||||
|
end
|
||||||
|
|
||||||
|
def convert_to_weeks_from_today_array(records, array_size, date_method_on_todo)
|
||||||
|
return convert_to_array(records, array_size) { |r| [difference_in_weeks(@today, r.send(date_method_on_todo))]}
|
||||||
|
end
|
||||||
|
|
||||||
|
def convert_to_weeks_running_array(records, array_size)
|
||||||
|
return convert_to_array(records, array_size) { |r| [difference_in_weeks(r.completed_at, r.created_at)]}
|
||||||
|
end
|
||||||
|
|
||||||
|
def convert_to_weeks_running_from_today_array(records, array_size)
|
||||||
|
return convert_to_array(records, array_size) { |r| week_indexes_of(r) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def week_indexes_of(record)
|
def week_indexes_of(record)
|
||||||
|
|
@ -236,10 +365,6 @@ module Stats
|
||||||
return a
|
return a
|
||||||
end
|
end
|
||||||
|
|
||||||
def convert_to_weeks_from_today_array(records, array_size, date_method_on_todo)
|
|
||||||
return convert_to_array(records, array_size) { |r| [difference_in_weeks(@today, r.send(date_method_on_todo))]}
|
|
||||||
end
|
|
||||||
|
|
||||||
def cut_off_array_with_sum(array, cut_off)
|
def cut_off_array_with_sum(array, cut_off)
|
||||||
# +1 to hold sum of rest
|
# +1 to hold sum of rest
|
||||||
a = Array.new(cut_off+1){|i| array[i]||0}
|
a = Array.new(cut_off+1){|i| array[i]||0}
|
||||||
|
|
@ -248,6 +373,10 @@ module Stats
|
||||||
return a
|
return a
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cut_off_array(array, cut_off)
|
||||||
|
return Array.new(cut_off){|i| array[i]||0}
|
||||||
|
end
|
||||||
|
|
||||||
def convert_to_cumulative_array(array, max)
|
def convert_to_cumulative_array(array, max)
|
||||||
# calculate fractions
|
# calculate fractions
|
||||||
a = Array.new(array.size){|i| array[i]*100.0/max}
|
a = Array.new(array.size){|i| array[i]*100.0/max}
|
||||||
|
|
@ -256,5 +385,34 @@ module Stats
|
||||||
return a
|
return a
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def difference_in_months(date1, date2)
|
||||||
|
return (date1.utc.year - date2.utc.year)*12 + (date1.utc.month - date2.utc.month)
|
||||||
|
end
|
||||||
|
|
||||||
|
# assumes date1 > date2
|
||||||
|
def difference_in_days(date1, date2)
|
||||||
|
return ((date1.utc.at_midnight-date2.utc.at_midnight)/SECONDS_PER_DAY).to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
# assumes date1 > date2
|
||||||
|
def difference_in_weeks(date1, date2)
|
||||||
|
return difference_in_days(date1, date2) / 7
|
||||||
|
end
|
||||||
|
|
||||||
|
def three_month_avg(set, i)
|
||||||
|
(set.fetch(i){ 0 } + set.fetch(i+1){ 0 } + set.fetch(i+2){ 0 }) / 3.0
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_three_month_avg(set,upper_bound)
|
||||||
|
(0..upper_bound-1).map { |i| three_month_avg(set, i) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def compute_running_avg_array(set, upper_bound)
|
||||||
|
result = set_three_month_avg(set, upper_bound)
|
||||||
|
result[upper_bound-1] = result[upper_bound-1] * 3 if upper_bound == set.length
|
||||||
|
result[upper_bound-2] = result[upper_bound-2] * 3 / 2 if upper_bound > 1 and upper_bound == set.length
|
||||||
|
result[0] = "null"
|
||||||
|
result
|
||||||
|
end # unsolved, not triggered, edge case for set.length == upper_bound + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -12,36 +12,35 @@ options = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<p><%= t('stats.actions_actions_avg_created_30days', :count => (actions.created_last30days*10.0/30.0).round/10.0 )%>
|
<p><%= t('stats.actions_actions_avg_created_30days', :count => (actions.created_last30days*10.0/30.0).round/10.0 )%>
|
||||||
<%= t('stats.actions_avg_completed_30days', :count => (actions.done_last30days*10.0/30.0).round/10.0 )%>
|
<%= t('stats.actions_avg_completed_30days', :count => (actions.done_last30days*10.0/30.0).round/10.0 )%>
|
||||||
<%= t('stats.actions_avg_created', :count => (actions.created_last12months*10.0/12.0).round/10.0 )%>
|
<%= t('stats.actions_avg_created', :count => (actions.created_last12months*10.0/12.0).round/10.0 )%>
|
||||||
<%= t('stats.actions_avg_completed', :count => (actions.done_last12months*10.0/12.0).round/10.0 )%></p>
|
<%= t('stats.actions_avg_completed', :count => (actions.done_last12months*10.0/12.0).round/10.0 )%></p>
|
||||||
|
|
||||||
<% actions.completion_charts.each do |chart| %><%=
|
<%= bar_chart actions.done_last30days_data, options.merge({'title': {'display': true, 'text': 'Actions in the last 30 days'}}) %>
|
||||||
render :partial => 'chart', :locals => {:chart => chart}
|
|
||||||
-%><% end %>
|
<%= bar_chart actions.done_last12months_data, options.merge({'title': {'display': true, 'text': 'Actions in the last 12 months'}}) %>
|
||||||
|
|
||||||
|
<%= bar_chart actions.completion_time_data, options.merge({'title': {'display': true, 'text': 'Completion time (all completed actions)'}}) %>
|
||||||
|
|
||||||
<br style="clear:both">
|
<br style="clear:both">
|
||||||
|
|
||||||
<% actions.timing_charts.each do |chart| %><%=
|
|
||||||
render :partial => 'chart', :locals => {:chart => chart}
|
|
||||||
-%><% end %>
|
|
||||||
|
|
||||||
<%
|
<%
|
||||||
Rails.logger.info actions.running_time_data
|
# TODO: There should be separate scales for percentage and amount of tasks so that the max of both is in the top of the chart.
|
||||||
%>
|
%>
|
||||||
|
<%= bar_chart actions.visible_running_time_data, options.merge({'title': {'display': true, 'text': 'Current running time of incomplete visible actions'}}) %>
|
||||||
|
|
||||||
<%= bar_chart actions.running_time_data, library: { :series => { 0 => {type: "line"} } }, title: "Current running time of all incomplete actions" %>
|
<%= bar_chart actions.running_time_data, options.merge({'title': {'display': true, 'text': 'Current running time of all incomplete actions'}}) %>
|
||||||
|
|
||||||
<br style="clear:both">
|
<br style="clear:both">
|
||||||
|
|
||||||
<%= bar_chart actions.open_per_week_data, options.merge({scales: {yAxes: [{ scaleLabel: { display: true, labelString: 'Weeks ago'}}]}, 'title': {'display': true, 'text': 'Active (visible and hidden) next actions per week'}}) %>
|
<%= bar_chart actions.open_per_week_data, options.merge({scales: {yAxes: [{ scaleLabel: { display: true, labelString: 'Weeks ago'}}]}, 'title': {'display': true, 'text': 'Active (visible and hidden) next actions per week'}}) %>
|
||||||
|
|
||||||
<%= bar_chart actions.day_of_week_all_data, options.merge({'title': {'display': true, 'text': 'Day of week (all actions)'}}) %>
|
<%= bar_chart actions.day_of_week_all_data, options.merge({'title': {'display': true, 'text': 'Day of week (all actions)'}}) %>
|
||||||
|
|
||||||
<%= bar_chart actions.day_of_week_30days_data, options.merge({'title': {'display': true, 'text': 'Day of week (past 30 days)'}}) %>
|
<%= bar_chart actions.day_of_week_30days_data, options.merge({'title': {'display': true, 'text': 'Day of week (past 30 days)'}}) %>
|
||||||
|
|
||||||
|
<br style="clear:both">
|
||||||
|
|
||||||
<%= bar_chart actions.time_of_day_all_data, options.merge({'title': {'display': true, 'text': 'Time of day (all actions)'}}) %>
|
<%= bar_chart actions.time_of_day_all_data, options.merge({'title': {'display': true, 'text': 'Time of day (all actions)'}}) %>
|
||||||
|
|
||||||
<%= bar_chart actions.time_of_day_30days_data, options.merge({'title': {'display': true, 'text': 'Time of day (last 30 days)'}}) %>
|
<%= bar_chart actions.time_of_day_30days_data, options.merge({'title': {'display': true, 'text': 'Time of day (last 30 days)'}}) %>
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@ Stats::TopContextsQuery.new(current_user, :running => true).result.map { |contex
|
||||||
%>
|
%>
|
||||||
<%= pie_chart data, options.merge({'title': {'display': true, 'text': 'Spread of actions for visible contexts'}}) %>
|
<%= pie_chart data, options.merge({'title': {'display': true, 'text': 'Spread of actions for visible contexts'}}) %>
|
||||||
|
|
||||||
|
<br style="clear:both">
|
||||||
|
|
||||||
<%= render :partial => 'contexts_list', :locals => {:contexts => contexts.actions, :key => 'contexts'} -%>
|
<%= render :partial => 'contexts_list', :locals => {:contexts => contexts.actions, :key => 'contexts'} -%>
|
||||||
|
|
||||||
<%= render :partial => 'contexts_list', :locals => {:contexts => contexts.running_actions, :key => 'visible_contexts_with_incomplete_actions'} -%>
|
<%= render :partial => 'contexts_list', :locals => {:contexts => contexts.running_actions, :key => 'visible_contexts_with_incomplete_actions'} -%>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue