Skip to content

Commit

Permalink
rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
danilogomes committed Nov 7, 2023
1 parent 265e155 commit 2162734
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 46 deletions.
13 changes: 7 additions & 6 deletions app/graphql/types/demand_efforts_list_type.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# frozen_string_literal: true

module Types
class DemandEffortsListType < BaseObject
field :demand_efforts, [Types::DemandEffortType], null: true
field :efforts_value_sum, Float, null: true
field :demand_efforts_count, Int, null: true
end
class DemandEffortsListType < BaseObject
field :demand_efforts, [Types::DemandEffortType], null: true
field :demand_efforts_count, Int, null: true
field :efforts_value_sum, Float, null: true
end
end

2 changes: 1 addition & 1 deletion app/graphql/types/team_member_consolidation_list_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ module Types
class TeamMemberConsolidationListType < BaseObject
field :team_member_consolidations, [Types::TeamMemberConsolidationType], null: true
end
end
end
4 changes: 3 additions & 1 deletion app/graphql/types/team_member_consolidation_type.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

module Types
class TeamMemberConsolidationType < BaseObject
field :consolidation_date, GraphQL::Types::ISO8601Date, null: false
field :value_per_hour_performed, Float, null: false
end
end
end
4 changes: 2 additions & 2 deletions app/graphql/types/team_members_hourly_rate_list_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Types
class TeamMembersHourlyRateListType < BaseObject
field :team_members_hourly_rate, [Types::TeamMembersHourlyRateType], null: true
field :team_members_hourly_rate, [Types::TeamMembersHourlyRateType], null: true
end
end
end
2 changes: 2 additions & 0 deletions app/graphql/types/team_members_hourly_rate_type.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Types
class TeamMembersHourlyRateType < BaseObject
field :period_date, GraphQL::Types::ISO8601Date, null: true
Expand Down
20 changes: 10 additions & 10 deletions app/graphql/types/teams/membership_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@ class MembershipType < Types::BaseObject
field :team_id, Integer, null: false
field :team_member_id, Integer, null: false
field :team_member_name, String, null: false
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false
field :team_members_hourly_rate_list, [Types::TeamMembersHourlyRateType], null: true
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false

def member_role_description
I18n.t("activerecord.attributes.membership.enums.member_role.#{object.member_role}")
end

def team_members_hourly_rate_list
if object.monthly_payment != 0 && object.team_member.billable?
tmhrl = []
(1..7).reverse_each do |date|
tmhrl << {'value_per_hour_performed' => (calculate_hours_per_month(object.monthly_payment, object.effort_in_period(Date.today.ago(date.month).beginning_of_month, Date.today.ago(date.month).end_of_month))), 'period_date' => Date.today.ago(date.month).end_of_month }
end
tmhrl
def team_members_hourly_rate_list
return unless object.monthly_payment != 0 && object.team_member.billable?

tmhrl = []
(1..7).reverse_each do |date|
tmhrl << { 'value_per_hour_performed' => calculate_hours_per_month(object.monthly_payment, object.effort_in_period(Time.zone.today.ago(date.month).beginning_of_month, Time.zone.today.ago(date.month).end_of_month)), 'period_date' => Time.zone.today.ago(date.month).end_of_month }
end
tmhrl
end

def calculate_hours_per_month(sallary, month_hours)
result = sallary / (month_hours.nonzero? || 1)
if result.infinite? || result > 2000.00
0.0
else
(result.to_f).round(2)
result.to_f.round(2)
end
end
end
Expand Down
19 changes: 9 additions & 10 deletions app/graphql/types/teams/team_member_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ class TeamMemberType < Types::BaseObject
field :billable, Boolean, null: false
field :demand_efforts, [Types::DemandEffortType], null: true do
argument :from_date, GraphQL::Types::ISO8601Date, required: false
argument :page_number, Integer, required: false
argument :until_date, GraphQL::Types::ISO8601Date, required: false
end
field :demand_efforts_list, Types::DemandEffortsListType, null: true do
argument :from_date, GraphQL::Types::ISO8601Date, required: false
argument :page_number, Integer, required: false
argument :until_date, GraphQL::Types::ISO8601Date, required: false
end
field :end_date, GraphQL::Types::ISO8601Date, null: true
field :hours_per_month, Int, null: false
Expand All @@ -19,11 +24,6 @@ class TeamMemberType < Types::BaseObject
field :start_date, GraphQL::Types::ISO8601Date, null: true
field :teams, [Types::Teams::TeamType], null: true
field :user, Types::UserType, null: true
field :demand_efforts_list, Types::DemandEffortsListType, null: true do
argument :from_date, GraphQL::Types::ISO8601Date, required: false
argument :until_date, GraphQL::Types::ISO8601Date, required: false
argument :page_number, Integer, required: false
end

field :demands, [Types::DemandType] do
argument :limit, Int, required: false
Expand Down Expand Up @@ -68,8 +68,7 @@ class TeamMemberType < Types::BaseObject

def demand_efforts(from_date: nil, until_date: nil, page_number: nil)
efforts = object.demand_efforts.to_dates(from_date, until_date).order(start_time_to_computation: :desc)
efforts_paginated = efforts.page(page_number).per(20)
demand_efforts = efforts_paginated
efforts.page(page_number).per(20)
end

def demands(status: 'ALL', type: 'ALL', limit: nil)
Expand All @@ -90,10 +89,10 @@ def team_member_consolidation_list
membership = object
tmcArray = []
(1..13).reverse_each do |i|
tmcArray << {'consolidation_date' => Date.today.ago(i.month).beginning_of_month, 'value_per_hour_performed' => (calculate_hours_per_month(membership.monthly_payment, membership.demand_efforts.to_dates(Date.today.ago(i.month).beginning_of_month, Date.today.ago(i.month).end_of_month).sum(&:effort_value).to_f))}
tmcArray << { 'consolidation_date' => Time.zone.today.ago(i.month).beginning_of_month, 'value_per_hour_performed' => calculate_hours_per_month(membership.monthly_payment, membership.demand_efforts.to_dates(Time.zone.today.ago(i.month).beginning_of_month, Time.zone.today.ago(i.month).end_of_month).sum(&:effort_value).to_f) }
end

tmcArray
tmcArray
end

def demand_efforts_list(from_date: nil, until_date: nil, page_number: nil)
Expand Down Expand Up @@ -214,7 +213,7 @@ def calculate_hours_per_month(sallary, month_hours)
if result.nan? || result.infinite?
0.0
else
(result.to_f).round(2)
result.to_f.round(2)
end
end
end
Expand Down
11 changes: 1 addition & 10 deletions app/services/team_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,7 @@ def compute_memberships_realized_hours(team, start_date, end_date)
private

def calculate_hours_per_month(sallary, month_hours)
if month_hours.zero?
result = 0.0
else
result = sallary / month_hours
if result.infinite? || result.nan?
0.0
else
result
end
end
result = month_hours.zero? ? 0.0 : sallary / month_hours
end

def build_members_efficiency(efficiency_data)
Expand Down
12 changes: 6 additions & 6 deletions spec/graphql/types/query_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@
'teamConsolidationsWeekly' => [],
'teamMonthlyInvestment' => { 'xAxis' => ['2022-09-30'], 'yAxis' => [-4500.0] },
'teamMemberEfficiency' => { 'membersEfficiency' => [{ 'effortInMonth' => 0.0, 'membership' => { 'teamMemberName' => 'aaa' }, 'realizedMoneyInMonth' => 0.0 }, { 'effortInMonth' => 0.0, 'membership' => { 'teamMemberName' => 'ddd' }, 'realizedMoneyInMonth' => 0.0 }] },
'memberships' => [{ 'id' => other_membership.id.to_s, 'memberRoleDescription' => 'Cliente', "teamMembersHourlyRateList"=>[{"periodDate"=>"2022-02-28", "valuePerHourPerformed"=>2000.0}, {"periodDate"=>"2022-03-31", "valuePerHourPerformed"=>2000.0}, {"periodDate"=>"2022-04-30", "valuePerHourPerformed"=>2000.0}, {"periodDate"=>"2022-05-31", "valuePerHourPerformed"=>2000.0}, {"periodDate"=>"2022-06-30", "valuePerHourPerformed"=>2000.0}, {"periodDate"=>"2022-07-31", "valuePerHourPerformed"=>2000.0}, {"periodDate"=>"2022-08-31", "valuePerHourPerformed"=>2000.0}] },
{ 'id' => membership.id.to_s, 'memberRoleDescription' => 'Desenvolvedor', "teamMembersHourlyRateList"=>[{"periodDate"=>"2022-02-28", "valuePerHourPerformed"=>0.0}, {"periodDate"=>"2022-03-31", "valuePerHourPerformed"=>0.0}, {"periodDate"=>"2022-04-30", "valuePerHourPerformed"=>0.0}, {"periodDate"=>"2022-05-31", "valuePerHourPerformed"=>0.0}, {"periodDate"=>"2022-06-30", "valuePerHourPerformed"=>0.0}, {"periodDate"=>"2022-07-31", "valuePerHourPerformed"=>0.0}, {"periodDate"=>"2022-08-31", "valuePerHourPerformed"=>0.0}]}],
'memberships' => [{ 'id' => other_membership.id.to_s, 'memberRoleDescription' => 'Cliente', 'teamMembersHourlyRateList' => [{ 'periodDate' => '2022-02-28', 'valuePerHourPerformed' => 2000.0 }, { 'periodDate' => '2022-03-31', 'valuePerHourPerformed' => 2000.0 }, { 'periodDate' => '2022-04-30', 'valuePerHourPerformed' => 2000.0 }, { 'periodDate' => '2022-05-31', 'valuePerHourPerformed' => 2000.0 }, { 'periodDate' => '2022-06-30', 'valuePerHourPerformed' => 2000.0 }, { 'periodDate' => '2022-07-31', 'valuePerHourPerformed' => 2000.0 }, { 'periodDate' => '2022-08-31', 'valuePerHourPerformed' => 2000.0 }] },
{ 'id' => membership.id.to_s, 'memberRoleDescription' => 'Desenvolvedor', 'teamMembersHourlyRateList' => [{ 'periodDate' => '2022-02-28', 'valuePerHourPerformed' => 0.0 }, { 'periodDate' => '2022-03-31', 'valuePerHourPerformed' => 0.0 }, { 'periodDate' => '2022-04-30', 'valuePerHourPerformed' => 0.0 }, { 'periodDate' => '2022-05-31', 'valuePerHourPerformed' => 0.0 }, { 'periodDate' => '2022-06-30', 'valuePerHourPerformed' => 0.0 }, { 'periodDate' => '2022-07-31', 'valuePerHourPerformed' => 0.0 }, { 'periodDate' => '2022-08-31', 'valuePerHourPerformed' => 0.0 }] }],
'lastReplenishingConsolidations' => [
{
'id' => replenishing_consolidation.id.to_s,
Expand Down Expand Up @@ -1785,7 +1785,7 @@
Fabricate :demand_effort, demand: demand_finished, item_assignment: first_assignment, start_time_to_computation: 2.days.from_now, effort_value: 100
Fabricate :demand_effort, demand: demand_finished, item_assignment: first_assignment, start_time_to_computation: 2.days.from_now, effort_value: 70
Fabricate :demand_effort, demand: demand_finished, item_assignment: first_assignment, start_time_to_computation: 2.months.ago, effort_value: 100

query =
%(query {
me {
Expand Down Expand Up @@ -2052,14 +2052,14 @@
'yAxisHours' => [170.0],
'yAxisProjectsNames' => [project.name]
},
'teamMemberConsolidationList' => [{"consolidationDate"=>"2021-04-01", "valuePerHourPerformed"=>0.0}, {"consolidationDate"=>"2021-05-01", "valuePerHourPerformed"=>0.0}, {"consolidationDate"=>"2021-06-01", "valuePerHourPerformed"=>0.0}, {"consolidationDate"=>"2021-07-01", "valuePerHourPerformed"=>0.0}, {"consolidationDate"=>"2021-08-01", "valuePerHourPerformed"=>0.0}, {"consolidationDate"=>"2021-09-01", "valuePerHourPerformed"=>0.0}, {"consolidationDate"=>"2021-10-01", "valuePerHourPerformed"=>0.0}, {"consolidationDate"=>"2021-11-01", "valuePerHourPerformed"=>0.0}, {"consolidationDate"=>"2021-12-01", "valuePerHourPerformed"=>0.0}, {"consolidationDate"=>"2022-01-01", "valuePerHourPerformed"=>0.0}, {"consolidationDate"=>"2022-02-01", "valuePerHourPerformed"=>0.0}, {"consolidationDate"=>"2022-03-01", "valuePerHourPerformed"=>(team_member.monthly_payment.to_f/100)}, {"consolidationDate"=>"2022-04-01", "valuePerHourPerformed"=>(team_member.monthly_payment.to_f/100)}],
'teamMemberConsolidationList' => [{ 'consolidationDate' => '2021-04-01', 'valuePerHourPerformed' => 0.0 }, { 'consolidationDate' => '2021-05-01', 'valuePerHourPerformed' => 0.0 }, { 'consolidationDate' => '2021-06-01', 'valuePerHourPerformed' => 0.0 }, { 'consolidationDate' => '2021-07-01', 'valuePerHourPerformed' => 0.0 }, { 'consolidationDate' => '2021-08-01', 'valuePerHourPerformed' => 0.0 }, { 'consolidationDate' => '2021-09-01', 'valuePerHourPerformed' => 0.0 }, { 'consolidationDate' => '2021-10-01', 'valuePerHourPerformed' => 0.0 }, { 'consolidationDate' => '2021-11-01', 'valuePerHourPerformed' => 0.0 }, { 'consolidationDate' => '2021-12-01', 'valuePerHourPerformed' => 0.0 }, { 'consolidationDate' => '2022-01-01', 'valuePerHourPerformed' => 0.0 }, { 'consolidationDate' => '2022-02-01', 'valuePerHourPerformed' => 0.0 }, { 'consolidationDate' => '2022-03-01', 'valuePerHourPerformed' => (team_member.monthly_payment.to_f / 100) }, { 'consolidationDate' => '2022-04-01', 'valuePerHourPerformed' => (team_member.monthly_payment.to_f / 100) }],
'memberThroughputData' => [0, 0, 0, 2],
'demandEfforts' => [{
'finishTimeToComputation' => '2022-05-03T10:00:00-03:00'
}],
'demandEffortsList' => {
'demandEffortsCount' => 1
}
'demandEffortsCount' => 1
}
})
end
end
Expand Down

0 comments on commit 2162734

Please sign in to comment.