Skip to content

Commit

Permalink
fix analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiomagalhaes committed Nov 9, 2023
1 parent 8d67687 commit abfd667
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
42 changes: 32 additions & 10 deletions app/utils/analytics/time_entries_analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,38 @@ def initialize(statement_of_work, start_date, end_date)
end

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/MethodLength
def data
# Initialize the hashes to accumulate hours for each user
worked_hash = Hash.new(0)
missing_hash = Hash.new(0)
vacation_hash = Hash.new(0)
sick_leave_hash = Hash.new(0)
over_delivered_hash = Hash.new(0)

# Iterate over assignments to sum the hours for each user
assignments.each do |assignment|
user_name = assignment.user.name
worked_hash[user_name] += clean_worked_hours(assignment)
missing_hash[user_name] += missing_hours(assignment)
vacation_hash[user_name] += vacation_hours(assignment)
sick_leave_hash[user_name] += sick_leave_hours(assignment)
over_delivered_hash[user_name] += over_delivered_hours(assignment)
end

# Create the labels and datasets from the accumulated hashes
{
labels: users.map(&:name),
labels: worked_hash.keys,
datasets: [
{ label: 'Worked', data: assignments.map(&method(:clean_worked_hours)) },
{ label: 'Missing', data: assignments.map(&method(:missing_hours)) },
{ label: 'Paid time off', data: assignments.map(&method(:vacation_hours)) },
{ label: 'Sick leave', data: assignments.map(&method(:sick_leave_hours)) },
{ label: 'Over delivered', data: assignments.map(&method(:over_delivered_hours)) }
{ label: 'Worked', data: worked_hash.values },
{ label: 'Missing', data: missing_hash.values },
{ label: 'Paid time off', data: vacation_hash.values },
{ label: 'Sick leave', data: sick_leave_hash.values },
{ label: 'Over delivered', data: over_delivered_hash.values }
]
}
end
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/AbcSize

def assignments
Expand Down Expand Up @@ -49,10 +69,11 @@ def clean_worked_hours(assignment)
end

def worked_hours(assignment)
statement = @statement_of_work || StatementOfWork.active_in_period(@start_date, @end_date)

time_entries = TimeEntry.where(statement_of_work: statement, date: @start_date..@end_date,
user: assignment.user)
time_entries = TimeEntry.where(
statement_of_work: assignment.requirement.statement_of_work,
date: @start_date..@end_date,
user: assignment.user
)

time_entries.sum(&:hours)
end
Expand All @@ -61,6 +82,7 @@ def expected_hours(assignment)
days = ([@start_date, assignment.start_date].max..[@end_date, assignment.end_date].min).count do |d|
!d.sunday? && !d.saturday?
end

days * assignment.coverage * 8
end

Expand Down
2 changes: 0 additions & 2 deletions bin/pull_prod_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ docker exec -it backstage-db psql -U postgres -c 'DROP DATABASE IF EXISTS backst
docker exec -it backstage-db psql -U postgres -c "CREATE DATABASE backstage_development"
docker exec -it backstage-db psql -U postgres backstage_development -c "CREATE SCHEMA IF NOT EXISTS heroku_ext AUTHORIZATION postgres"
docker exec -it backstage-db pg_restore --no-owner -U postgres -d backstage_development -1 ./app/latest.dump
docker exec -it prod-backstage-api rails db:create
docker exec -it prod-backstage-api rails db:migrate
sh bin/dev

0 comments on commit abfd667

Please sign in to comment.