mirror of
https://github.com/System-End/hackatime.git
synced 2026-04-20 00:35:22 +00:00
Namespace hackatime records
This commit is contained in:
parent
cd9941bd10
commit
954c5d5bde
11 changed files with 29 additions and 24 deletions
|
|
@ -28,7 +28,7 @@ class StaticPagesController < ApplicationController
|
|||
def activity_graph
|
||||
return unless current_user
|
||||
|
||||
@daily_durations = Heartbeat
|
||||
@daily_durations = Hackatime::Heartbeat
|
||||
.where(user_id: current_user.slack_uid, time: 365.days.ago..)
|
||||
.group(Arel.sql("DATE_TRUNC('day', time)"))
|
||||
.duration_seconds
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ class LeaderboardUpdateJob < ApplicationJob
|
|||
|
||||
ActiveRecord::Base.transaction do
|
||||
valid_user_ids.each_slice(BATCH_SIZE) do |batch_user_ids|
|
||||
entries_data = Heartbeat.where(user_id: batch_user_ids)
|
||||
.where(time: parsed_date.all_day)
|
||||
.group(:user_id)
|
||||
.duration_seconds
|
||||
entries_data = Hackatime::Heartbeat.where(user_id: batch_user_ids)
|
||||
.where(time: parsed_date.all_day)
|
||||
.group(:user_id)
|
||||
.duration_seconds
|
||||
|
||||
entries_data = entries_data.map do |user_id, total_seconds|
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ class SailorsLogPollForChangesJob < ApplicationJob
|
|||
def perform
|
||||
puts "performing SailorsLogPollForChangesJob"
|
||||
# get all users who've coded in the last minute
|
||||
users_who_coded = Heartbeat.where("created_at > ?", 1.minutes.ago).distinct.pluck(:user_id)
|
||||
users_who_coded = Hackatime::Heartbeat.where("created_at > ?", 1.minutes.ago)
|
||||
.where(time: 1.minutes.ago..)
|
||||
.distinct.pluck(:user_id)
|
||||
|
||||
puts "users_who_coded: #{users_who_coded}"
|
||||
|
||||
|
|
@ -19,7 +21,10 @@ class SailorsLogPollForChangesJob < ApplicationJob
|
|||
|
||||
logs.each do |log|
|
||||
# get all projects for the user with duration
|
||||
new_project_times = Heartbeat.where(user_id: log.slack_uid).group(:project).duration_seconds
|
||||
new_project_times = Hackatime::Heartbeat.where(user_id: log.slack_uid)
|
||||
.group(:project)
|
||||
.duration_seconds
|
||||
|
||||
new_project_times.each do |project, new_project_duration|
|
||||
next if project.blank?
|
||||
if new_project_duration > (log.projects_summary[project] || 0) + 1.hour
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
class Heartbeat < WakatimeRecord
|
||||
class Hackatime::Heartbeat < HackatimeRecord
|
||||
TIMEOUT_DURATION = 2.minutes
|
||||
|
||||
def self.cached_recent_count
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
class ProjectLabel < WakatimeRecord
|
||||
class Hackatime::ProjectLabel < HackatimeRecord
|
||||
self.table_name = "project_labels"
|
||||
|
||||
has_many :heartbeats,
|
||||
->(project) { where(user_id: project.user_id) },
|
||||
foreign_key: :project,
|
||||
primary_key: :project_key,
|
||||
class_name: "Heartbeat"
|
||||
class_name: "Hackatime::Heartbeat"
|
||||
|
||||
belongs_to :user,
|
||||
foreign_key: :user_id,
|
||||
3
app/models/hackatime/user.rb
Normal file
3
app/models/hackatime/user.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
class Hackatime::User < HackatimeRecord
|
||||
self.table_name = "users"
|
||||
end
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
class WakatimeRecord < ApplicationRecord
|
||||
class HackatimeRecord < ApplicationRecord
|
||||
self.abstract_class = true
|
||||
connects_to database: { reading: :wakatime, writing: :wakatime }
|
||||
end
|
||||
|
|
@ -37,17 +37,17 @@ class SailorsLogLeaderboard < ApplicationRecord
|
|||
.pluck(:slack_uid)
|
||||
|
||||
# Get all durations for users in channel
|
||||
user_durations = Heartbeat.where(user_id: users_in_channel)
|
||||
.today
|
||||
.group(:user_id)
|
||||
.duration_seconds
|
||||
user_durations = Hackatime::Heartbeat.where(user_id: users_in_channel)
|
||||
.today
|
||||
.group(:user_id)
|
||||
.duration_seconds
|
||||
|
||||
# Sort and take top 10 users
|
||||
top_user_ids = user_durations.sort_by { |_, duration| -duration }.first(10).map(&:first)
|
||||
|
||||
# Now get detailed project info only for top 10 users
|
||||
top_user_ids.map do |user_id|
|
||||
user_heartbeats = Heartbeat.where(user_id: user_id).today
|
||||
user_heartbeats = Hackatime::Heartbeat.where(user_id: user_id).today
|
||||
|
||||
# Get most common language per project using ActiveRecord
|
||||
most_common_languages = user_heartbeats
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ class User < ApplicationRecord
|
|||
has_many :heartbeats,
|
||||
foreign_key: :user_id,
|
||||
primary_key: :slack_uid,
|
||||
class_name: "Heartbeat"
|
||||
class_name: "Hackatime::Heartbeat"
|
||||
|
||||
has_many :project_labels,
|
||||
foreign_key: :user_id,
|
||||
primary_key: :slack_uid,
|
||||
class_name: "ProjectLabel"
|
||||
class_name: "Hackatime::ProjectLabel"
|
||||
|
||||
def admin?
|
||||
is_admin
|
||||
|
|
@ -47,8 +47,8 @@ class User < ApplicationRecord
|
|||
|
||||
current_project = heartbeats.order(time: :desc).first&.project
|
||||
current_project_heartbeats = heartbeats.today.where(project: current_project)
|
||||
current_project_duration = Heartbeat.duration_seconds(current_project_heartbeats)
|
||||
current_project_duration_formatted = Heartbeat.duration_simple(current_project_heartbeats)
|
||||
current_project_duration = Hackatime::Heartbeat.duration_seconds(current_project_heartbeats)
|
||||
current_project_duration_formatted = Hackatime::Heartbeat.duration_simple(current_project_heartbeats)
|
||||
|
||||
# for 0 duration, don't set a status
|
||||
return if current_project_duration.zero?
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
class WakatimeUser < WakatimeRecord
|
||||
self.table_name = "users"
|
||||
end
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
<p>
|
||||
Build <%= link_to Rails.application.config.git_version, Rails.application.config.commit_link %>
|
||||
from <%= time_ago_in_words(Rails.application.config.server_start_time) %> ago.
|
||||
<%= pluralize(Heartbeat.cached_recent_count, 'heartbeat') %> in the last 24 hours.
|
||||
<%= pluralize(Hackatime::Heartbeat.cached_recent_count, 'heartbeat') %> in the last 24 hours.
|
||||
(DB: <%= pluralize(QueryCount::Counter.counter, "query") %>, <%= QueryCount::Counter.counter_cache %> cached)
|
||||
(CACHE: <%= cache_stats[:hits] %> hits, <%= cache_stats[:misses] %> misses)
|
||||
</p>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue