mirror of
https://github.com/SrIzan10/hc-harbor.git
synced 2026-05-01 10:45:21 +00:00
Revert "fix: use WakatimeService without filters and consistent time ranges f…"
This commit is contained in:
@@ -61,10 +61,25 @@ class Api::V1::StatsController < ApplicationController
|
||||
service_params[:scope] = scope if scope.present?
|
||||
|
||||
if params[:total_seconds] == "true"
|
||||
service_params[:boundary_aware] = params[:boundary_aware] == "true"
|
||||
query = @user.heartbeats
|
||||
.coding_only
|
||||
.with_valid_timestamps
|
||||
.where(time: start_date..end_date)
|
||||
|
||||
summary = WakatimeService.new(**service_params).generate_summary
|
||||
return render json: { total_seconds: summary[:total_seconds] }
|
||||
if params[:filter_by_project].present?
|
||||
filter_by_project = params[:filter_by_project].split(",")
|
||||
query = query.where(project: filter_by_project)
|
||||
end
|
||||
|
||||
# do the boundary thingie if requested
|
||||
use_boundary_aware = params[:boundary_aware] == "true"
|
||||
total_seconds = if use_boundary_aware
|
||||
Heartbeat.duration_seconds_boundary_aware(query, start_date.to_f, end_date.to_f) || 0
|
||||
else
|
||||
query.duration_seconds || 0
|
||||
end
|
||||
|
||||
return render json: { total_seconds: total_seconds }
|
||||
end
|
||||
|
||||
summary = WakatimeService.new(**service_params).generate_summary
|
||||
|
||||
@@ -1,24 +1,18 @@
|
||||
include ApplicationHelper
|
||||
|
||||
class WakatimeService
|
||||
def initialize(user: nil, specific_filters: [], allow_cache: true, limit: 10, start_date: nil, end_date: nil, scope: nil, boundary_aware: false)
|
||||
def initialize(user: nil, specific_filters: [], allow_cache: true, limit: 10, start_date: nil, end_date: nil, scope: nil)
|
||||
@scope = scope || Heartbeat.all
|
||||
@user = user
|
||||
@boundary_aware = boundary_aware
|
||||
|
||||
@start_date = convert_to_unix_timestamp(start_date)
|
||||
@end_date = convert_to_unix_timestamp(end_date)
|
||||
|
||||
# apply with_valid_timestamps filter if no custom scope provided-- this is copied from query in stats_controller
|
||||
if scope.nil?
|
||||
@scope = @scope.with_valid_timestamps
|
||||
end
|
||||
|
||||
# Default to 1 year ago if no start_date provided or if no data exists
|
||||
@start_date = @start_date || @scope.minimum(:time) || 1.year.ago.to_i
|
||||
@end_date = @end_date || @scope.maximum(:time) || Time.current.to_i
|
||||
|
||||
@scope = @scope.where(time: @start_date..@end_date)
|
||||
@scope = @scope.where("time >= ? AND time < ?", @start_date, @end_date)
|
||||
|
||||
@limit = limit
|
||||
@limit = nil if @limit&.zero?
|
||||
@@ -47,14 +41,7 @@ class WakatimeService
|
||||
summary[:range] = "all_time"
|
||||
summary[:human_readable_range] = "All Time"
|
||||
|
||||
@total_seconds = if @boundary_aware
|
||||
result = Heartbeat.duration_seconds_boundary_aware(@scope, @start_date, @end_date) || 0
|
||||
result
|
||||
else
|
||||
result = @scope.duration_seconds || 0
|
||||
result
|
||||
end
|
||||
|
||||
@total_seconds = @scope.duration_seconds || 0
|
||||
summary[:total_seconds] = @total_seconds
|
||||
|
||||
@total_days = (@end_time - @start_time) / 86400
|
||||
|
||||
Reference in New Issue
Block a user