#1153: Fix whitespace issues caused by Vim misconfiguration

This commit is contained in:
Jyri-Petteri Paloposki 2019-05-19 16:51:26 +03:00
parent 0b326e17d8
commit f9370a9a4a
3 changed files with 118 additions and 118 deletions

View file

@ -38,39 +38,39 @@ module Stats
# get actions created and completed in the past 12+3 months. +3 for running
# - outermost set of entries needed for these calculations
actions_last12months = @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.
# FIXME: These should also be used.
@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: I18n.t('stats.labels.avg_created'), data: @created_count_array.map { |total| [total] }, type: "line"},
{label: I18n.t('stats.labels.avg_completed'), data: @done_count_array.map { |total| [total] }, type: "line"},
{label: I18n.t('stats.labels.month_avg_completed', :months => 3), data: @actions_done_avg_last12months_array.map { |total| [total] }, type: "line"},
{label: I18n.t('stats.labels.month_avg_created', :months => 3), data: @actions_created_avg_last12months_array.map { |total| [total] }, type: "line"},
{label: I18n.t('stats.labels.created'), data: @actions_created_last12months_array.map { |total| [total] } },
{label: I18n.t('stats.labels.completed'), data: @actions_done_last12months_array.map { |total| [total] } },
],
labels: array_of_month_labels(@done_count_array.size),
datasets: [
{label: I18n.t('stats.labels.avg_created'), data: @created_count_array.map { |total| [total] }, type: "line"},
{label: I18n.t('stats.labels.avg_completed'), data: @done_count_array.map { |total| [total] }, type: "line"},
{label: I18n.t('stats.labels.month_avg_completed', :months => 3), data: @actions_done_avg_last12months_array.map { |total| [total] }, type: "line"},
{label: I18n.t('stats.labels.month_avg_created', :months => 3), data: @actions_created_avg_last12months_array.map { |total| [total] }, type: "line"},
{label: I18n.t('stats.labels.created'), data: @actions_created_last12months_array.map { |total| [total] } },
{label: I18n.t('stats.labels.completed'), data: @actions_done_last12months_array.map { |total| [total] } },
],
labels: array_of_month_labels(@done_count_array.size),
}
end
@ -78,7 +78,7 @@ module Stats
# get actions created and completed in the past 30 days.
@actions_done_last30days = @user.todos.completed_after(@cut_off_30days).select("completed_at")
@actions_created_last30days = @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)
@ -90,67 +90,67 @@ module Stats
done_count_array = Array.new(30){ |i| @actions_done_last30days.size/30.0 }
# TODO: make the strftime i18n proof
time_labels = Array.new(30){ |i| I18n.l(Time.zone.now-i.days, :format => :stats) }
return {
datasets: [
{label: I18n.t('stats.labels.avg_created'), data: created_count_array.map { |total| [total] }, type: "line"},
{label: I18n.t('stats.labels.completed'), data: done_count_array.map { |total| [total] }, type: "line"},
{label: I18n.t('stats.labels.created'), data: @actions_created_last30days_array.map { |total| [total] } },
{label: I18n.t('stats.labels.completed'), data: @actions_done_last30days_array.map { |total| [total] } },
],
labels: time_labels,
datasets: [
{label: I18n.t('stats.labels.avg_created'), data: created_count_array.map { |total| [total] }, type: "line"},
{label: I18n.t('stats.labels.completed'), data: done_count_array.map { |total| [total] }, type: "line"},
{label: I18n.t('stats.labels.created'), data: @actions_created_last30days_array.map { |total| [total] } },
{label: I18n.t('stats.labels.completed'), data: @actions_done_last30days_array.map { |total| [total] } },
],
labels: time_labels,
}
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: I18n.t('stats.legend.percentage'), data: @cum_percent_done.map { |total| [total] }, type: "line"},
{label: I18n.t('stats.legend.actions'), data: @actions_completion_time_array.map { |total| [total] } },
],
labels: @actions_completion_time_array.each_with_index.map { |total, week| [week] },
datasets: [
{label: I18n.t('stats.legend.percentage'), data: @cum_percent_done.map { |total| [total] }, type: "line"},
{label: I18n.t('stats.legend.actions'), data: @actions_completion_time_array.map { |total| [total] } },
],
labels: @actions_completion_time_array.each_with_index.map { |total, week| [week] },
}
end
def running_time_data
@actions_running_time = @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 )
return {
datasets: [
{label: I18n.t('stats.running_time_all_legend.percentage'), data: @cum_percent_done.map { |total| [total] }, type: "line"},
{label: I18n.t('stats.running_time_all_legend.actions'), data: @actions_running_time_array.map { |total| [total] } },
],
labels: @actions_running_time_array.each_with_index.map { |total, week| [week] },
datasets: [
{label: I18n.t('stats.running_time_all_legend.percentage'), data: @cum_percent_done.map { |total| [total] }, type: "line"},
{label: I18n.t('stats.running_time_all_legend.actions'), data: @actions_running_time_array.map { |total| [total] } },
],
labels: @actions_running_time_array.each_with_index.map { |total, week| [week] },
}
end
@ -162,30 +162,30 @@ module Stats
# - 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: I18n.t('stats.running_time_legend.percentage'), data: @cum_percent_done.map { |total| [total] }, type: "line"},
{label: I18n.t('stats.running_time_legend.actions'), data: @actions_running_time_array.map { |total| [total] } },
],
labels: @actions_running_time_array.each_with_index.map { |total, week| [week] },
datasets: [
{label: I18n.t('stats.running_time_legend.percentage'), data: @cum_percent_done.map { |total| [total] }, type: "line"},
{label: I18n.t('stats.running_time_legend.actions'), data: @actions_running_time_array.map { |total| [total] } },
],
labels: @actions_running_time_array.each_with_index.map { |total, week| [week] },
}
end
@ -193,106 +193,106 @@ module Stats
@actions_started = @user.todos.created_after(@today-53.weeks).
select("todos.created_at, todos.completed_at").
reorder("todos.created_at DESC")
@max_weeks = difference_in_weeks(@today, @actions_started.last.created_at)
# cut off chart at 52 weeks = one year
@count = [52, @max_weeks].min
@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)
return {
datasets: [
datasets: [
{label: I18n.t('stats.open_per_week_legend.actions'), data: @actions_open_per_week_array.map { |total| [total] } },
],
labels: @actions_open_per_week_array.each_with_index.map { |total, week| [week] },
],
labels: @actions_open_per_week_array.each_with_index.map { |total, week| [week] },
}
end
def day_of_week_all_data
@actions_creation_day = @user.todos.select("created_at")
@actions_completion_day = @user.todos.completed.select("completed_at")
# convert to array and fill in non-existing days
@actions_creation_day_array = Array.new(7) { |i| 0}
@actions_creation_day.each { |t| @actions_creation_day_array[ t.created_at.wday ] += 1 }
@actions_creation_day.each { |t| @actions_creation_day_array[ t.created_at.wday ] += 1 }
@max = @actions_creation_day_array.max
# convert to array and fill in non-existing days
@actions_completion_day_array = Array.new(7) { |i| 0}
@actions_completion_day.each { |t| @actions_completion_day_array[ t.completed_at.wday ] += 1 }
@actions_completion_day.each { |t| @actions_completion_day_array[ t.completed_at.wday ] += 1 }
return {
datasets: [
datasets: [
{label: I18n.t('stats.labels.created'), data: @actions_creation_day_array.map { |total| [total] } },
{label: I18n.t('stats.labels.completed'), data: @actions_completion_day_array.map { |total| [total] } },
],
labels: I18n.t('date.day_names'),
{label: I18n.t('stats.labels.completed'), data: @actions_completion_day_array.map { |total| [total] } },
],
labels: I18n.t('date.day_names'),
}
end
def day_of_week_30days_data
@actions_creation_day = @user.todos.created_after(@cut_off_month).select("created_at")
@actions_completion_day = @user.todos.completed_after(@cut_off_month).select("completed_at")
# convert to hash to be able to fill in non-existing days
@max=0
@actions_creation_day_array = Array.new(7) { |i| 0}
@actions_creation_day.each { |r| @actions_creation_day_array[ r.created_at.wday ] += 1 }
# convert to hash to be able to fill in non-existing days
@actions_completion_day_array = Array.new(7) { |i| 0}
@actions_completion_day.each { |r| @actions_completion_day_array[r.completed_at.wday] += 1 }
return {
datasets: [
{label: I18n.t('stats.labels.created'), data: @actions_creation_day_array.map { |total| [total] } },
{label: I18n.t('stats.labels.completed'), data: @actions_completion_day_array.map { |total| [total] } },
],
labels: I18n.t('date.day_names'),
datasets: [
{label: I18n.t('stats.labels.created'), data: @actions_creation_day_array.map { |total| [total] } },
{label: I18n.t('stats.labels.completed'), data: @actions_completion_day_array.map { |total| [total] } },
],
labels: I18n.t('date.day_names'),
}
end
def time_of_day_all_data
@actions_creation_hour = @user.todos.select("created_at")
@actions_completion_hour = @user.todos.completed.select("completed_at")
# convert to hash to be able to fill in non-existing days
@actions_creation_hour_array = Array.new(24) { |i| 0}
@actions_creation_hour.each{|r| @actions_creation_hour_array[r.created_at.hour] += 1 }
@actions_creation_hour.each{|r| @actions_creation_hour_array[r.created_at.hour] += 1 }
# convert to hash to be able to fill in non-existing days
@actions_completion_hour_array = Array.new(24) { |i| 0}
@actions_completion_hour.each{|r| @actions_completion_hour_array[r.completed_at.hour] += 1 }
@actions_completion_hour.each{|r| @actions_completion_hour_array[r.completed_at.hour] += 1 }
return {
datasets: [
{label: I18n.t('stats.labels.created'), data: @actions_creation_hour_array.map { |total| [total] } },
{label: I18n.t('stats.labels.completed'), data: @actions_completion_hour_array.map { |total| [total] } },
],
labels: @actions_creation_hour_array.each_with_index.map { |total, hour| [hour] },
datasets: [
{label: I18n.t('stats.labels.created'), data: @actions_creation_hour_array.map { |total| [total] } },
{label: I18n.t('stats.labels.completed'), data: @actions_completion_hour_array.map { |total| [total] } },
],
labels: @actions_creation_hour_array.each_with_index.map { |total, hour| [hour] },
}
end
def time_of_day_30days_data
@actions_creation_hour = @user.todos.created_after(@cut_off_month).select("created_at")
@actions_completion_hour = @user.todos.completed_after(@cut_off_month).select("completed_at")
# convert to hash to be able to fill in non-existing days
@actions_creation_hour_array = Array.new(24) { |i| 0}
@actions_creation_hour.each{|r| @actions_creation_hour_array[r.created_at.hour] += 1 }
@actions_creation_hour.each{|r| @actions_creation_hour_array[r.created_at.hour] += 1 }
# convert to hash to be able to fill in non-existing days
@actions_completion_hour_array = Array.new(24) { |i| 0}
@actions_completion_hour.each{|r| @actions_completion_hour_array[r.completed_at.hour] += 1 }
@actions_completion_hour.each{|r| @actions_completion_hour_array[r.completed_at.hour] += 1 }
return {
datasets: [
{label: I18n.t('stats.labels.created'), data: @actions_creation_hour_array.map { |total| [total] } },
{label: I18n.t('stats.labels.completed'), data: @actions_completion_hour_array.map { |total| [total] } },
],
labels: @actions_creation_hour_array.each_with_index.map { |total, hour| [hour] },
datasets: [
{label: I18n.t('stats.labels.created'), data: @actions_creation_hour_array.map { |total| [total] } },
{label: I18n.t('stats.labels.completed'), data: @actions_completion_hour_array.map { |total| [total] } },
],
labels: @actions_creation_hour_array.each_with_index.map { |total, hour| [hour] },
}
end
@ -333,7 +333,7 @@ module Stats
records.each { |r| (yield r).each { |i| a[i] += 1 if a[i] } }
a
end
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))]}
end
@ -390,7 +390,7 @@ module Stats
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
@ -415,7 +415,7 @@ module Stats
def month_label(i)
I18n.t('date.month_names')[ (Time.zone.now.mon - i -1 ) % 12 + 1 ]
end
def array_of_month_labels(count)
Array.new(count) { |i| month_label(i) }
end

View file

@ -1,15 +1,15 @@
<%= render :partial => 'time_to_complete', :locals => {:ttc => actions.ttc} -%>
<%
options = {
width: "400px",
height: "400px",
maintainAspectRatio: false,
responsive: false,
plugins: {
colorschemes: {
scheme: 'brewer.Paired12',
},
},
width: "400px",
height: "400px",
maintainAspectRatio: false,
responsive: false,
plugins: {
colorschemes: {
scheme: 'brewer.Paired12',
},
},
}
%>
<p><%= t('stats.actions_actions_avg_created_30days', :count => (actions.created_last30days*10.0/30.0).round/10.0 )%>

View file

@ -13,15 +13,15 @@ Stats::TopContextsQuery.new(current_user).result.map { |context|
data[:ids].append(context.id)
}
options = {
width: "400px",
height: "400px",
maintainAspectRatio: false,
responsive: false,
plugins: {
colorschemes: {
scheme: 'brewer.Paired12',
},
},
width: "400px",
height: "400px",
maintainAspectRatio: false,
responsive: false,
plugins: {
colorschemes: {
scheme: 'brewer.Paired12',
},
},
}
%>
<% #TODO: Move data handling to model. Show value as percentage %>