Skip to content

Commit

Permalink
feat: add graph in value per hour in team member
Browse files Browse the repository at this point in the history
  • Loading branch information
danilogomes committed Oct 10, 2023
1 parent 285bf0a commit ec70054
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ gem 'slack-notifier'
gem 'sprockets-rails', require: 'sprockets/railtie'
gem 'uglifier'
gem 'yui-compressor'
gem 'tzinfo-data'

group :test, :development do
gem 'bullet'
Expand All @@ -56,6 +55,8 @@ group :test, :development do
gem 'shoulda-matchers'
gem 'simplecov'
gem 'webmock'
#remover essa gem
gem 'debug'
end

group :development do
Expand Down
18 changes: 15 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ GEM
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
date (3.3.3)
debug (1.8.0)
irb (>= 1.5.0)
reline (>= 0.3.1)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
devise (4.9.2)
Expand Down Expand Up @@ -180,6 +183,10 @@ GEM
image_processing (1.12.2)
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.17, < 3)
io-console (0.6.0)
irb (1.8.1)
rdoc
reline (>= 0.3.8)
jira-ruby (2.3.0)
activesupport
atlassian-jwt
Expand Down Expand Up @@ -261,6 +268,8 @@ GEM
racc
path_expander (1.1.1)
pg (1.5.4)
psych (5.1.0)
stringio
public_suffix (5.0.3)
puma (6.4.0)
nio4r (~> 2.0)
Expand Down Expand Up @@ -323,12 +332,16 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rdoc (6.5.0)
psych (>= 4.0.0)
redis (4.8.1)
reek (6.1.4)
kwalify (~> 0.7.0)
parser (~> 3.2.0)
rainbow (>= 2.0, < 4.0)
regexp_parser (2.8.1)
reline (0.3.9)
io-console (~> 0.5)
require_all (3.0.0)
responders (3.1.0)
actionpack (>= 5.2)
Expand Down Expand Up @@ -435,6 +448,7 @@ GEM
ssrf_filter (1.1.2)
stackprof (0.2.25)
statsd-ruby (1.5.0)
stringio (3.0.8)
thor (1.2.2)
thread_safe (0.3.6)
timeout (0.4.0)
Expand All @@ -443,8 +457,6 @@ GEM
tty-which (0.5.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
tzinfo-data (1.2023.3)
tzinfo (>= 1.0.0)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
unf (0.1.4)
Expand Down Expand Up @@ -490,6 +502,7 @@ DEPENDENCIES
cloudinary
coffee-rails
database_cleaner
debug
devise
discard
fabrication
Expand Down Expand Up @@ -539,7 +552,6 @@ DEPENDENCIES
sprockets-rails
stackprof
traceroute
tzinfo-data
uglifier
web-console
webmock
Expand Down
7 changes: 7 additions & 0 deletions app/graphql/types/team_member_consolidation_list_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module Types
class TeamMemberConsolidationListType < BaseObject
field :team_member_consolidations, [Types::TeamMemberConsolidationType], null: true
end
end
6 changes: 6 additions & 0 deletions app/graphql/types/team_member_consolidation_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Types
class TeamMemberConsolidationType < BaseObject
field :consolidation_date, GraphQL::Types::ISO8601Date, null: false
field :value_per_hour_performed, Float, null: false
end
end
26 changes: 26 additions & 0 deletions app/graphql/types/teams/team_member_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class TeamMemberType < Types::BaseObject
argument :sort_direction, Types::Enums::SortDirection, required: false
end

field :team_member_consolidation_list, [Types::TeamMemberConsolidationType], null: true

field :average_pull_interval_data, Types::Charts::SimpleDateChartDataType, null: true
field :lead_time_control_chart_data, Types::Charts::ControlChartType, null: true
field :lead_time_histogram_chart_data, Types::Charts::LeadTimeHistogramDataType, null: true
Expand Down Expand Up @@ -84,6 +86,21 @@ def demands(status: 'ALL', type: 'ALL', limit: nil)
demands.limit(limit)
end

def team_member_consolidation_list
binding.break
consolidation_date = []
value_per_hour_performed = []
membership = object.memberships.active.last
tmcArray = []
(1..13).reverse_each do |i|
consolidation_date << Date.today.ago(i.month).beginning_of_month
value_per_hour_performed.push(calculate_hours_per_month(membership.monthly_payment, membership.effort_in_period(Date.today.ago(i.month).beginning_of_month, Date.today.ago(i.month).end_of_month)))
tmcArray << {'consolidation_date' => Date.today.ago(i.month).beginning_of_month, 'value_per_hour_performed' => (calculate_hours_per_month(membership.monthly_payment, membership.effort_in_period(Date.today.ago(i.month).beginning_of_month, Date.today.ago(i.month).end_of_month)))}
end

tmcArray
end

def demand_efforts_list(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(10)
Expand Down Expand Up @@ -196,6 +213,15 @@ def last_30_days_hash
end
accumulator
end

def calculate_hours_per_month(sallary, month_hours)
result = sallary / month_hours
if result.nan? || result.infinite?
0.0
else
(result.to_f).round(2)
end
end
end
end
end
35 changes: 35 additions & 0 deletions app/spa/src/components/TeamMemberDashboardCharts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { BarChart } from "./charts/BarChart"
import { ScatterChart } from "./charts/ScatterChart"
import { ChartGridItem } from "./charts/ChartGridItem"
import TeamMemberEffortDailyData from "../modules/teamMember/components/TeamMemberEffortDailyData"
import { LineChart } from "./charts/LineChart"
import { SliceTooltipProps } from "@nivo/line"
import LineChartTooltip from "./charts/tooltips/LineChartTooltip"

type TeamMemberDashboardChartsProps = {
teamMember: TeamMember
Expand Down Expand Up @@ -79,6 +82,21 @@ const TeamMemberDashboardCharts = ({
}
)

const lineChartData = [
{
id: teamMember.name,
data: teamMember.teamMemberConsolidationList? teamMember.teamMemberConsolidationList.map(
({ valuePerHourPerformed, consolidationDate }) => {

return {
x: String(consolidationDate || ''),
y: Number(valuePerHourPerformed || 0),
}
}
) : [],
},
]

return (
<Grid container spacing={2}>
{leadTimeHistogramChartData && (
Expand Down Expand Up @@ -140,6 +158,23 @@ const TeamMemberDashboardCharts = ({
/>
</ChartGridItem>
)}
{projectHoursData && (
<ChartGridItem title={t("charts.valuePerHour")}>
<LineChart
data={lineChartData}
axisLeftLegend={t("charts.valuePerHour")}
axisBottomLegend={t(
"charts.memberEffort_x_label"
)}
props={{
enableSlices: "x",
sliceTooltip: ({ slice }: SliceTooltipProps) => (
<LineChartTooltip slice={slice} />
),
}}
/>
</ChartGridItem>
)}
</Grid>
)
}
Expand Down
3 changes: 2 additions & 1 deletion app/spa/src/locales/coca/teamMembers.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@
"memberEffortDaily_legend_label": "Hours",
"throughput": "Throughput",
"averagePullInterval": "Average Pull Interval",
"hoursPerProject": "Hours per Project"
"hoursPerProject": "Hours per Project",
"valuePerHour": "Value Per Hour"
},
"general": {
"notFound": "Person not found."
Expand Down
3 changes: 2 additions & 1 deletion app/spa/src/locales/en/teamMembers.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@
"memberEffortDaily_legend_label": "Hours",
"throughput": "Throughput",
"averagePullInterval": "Average Pull Interval",
"hoursPerProject": "Hours per Project"
"hoursPerProject": "Hours per Project",
"valuePerHour": "Value Per Hour"
},
"general": {
"notFound": "Person not found."
Expand Down
3 changes: 2 additions & 1 deletion app/spa/src/locales/pt/teamMembers.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@
"memberEffortDaily_legend_label": "Horas",
"throughput": "Taxa de Transferência",
"averagePullInterval": "Intervalo Médio de Extração",
"hoursPerProject": "Horas por Projeto"
"hoursPerProject": "Horas por Projeto",
"valuePerHour": "Valor por hora"
},
"general": {
"notFound": "Pessoa não encontrada."
Expand Down
6 changes: 6 additions & 0 deletions app/spa/src/modules/teamMember/teamMember.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ type LeadTimesChartData = {
leadTimeP95?: number
}

type TeamMemberConsolidation = {
consolidationDate?: string
valuePerHourPerformed?: number
}

export type TeamMember = {
id: string
name: string
Expand Down Expand Up @@ -47,4 +52,5 @@ export type TeamMember = {
demandEffortsCount?: number
effortsValueSum?: number
}
teamMemberConsolidationList?: TeamMemberConsolidation[]
}
4 changes: 4 additions & 0 deletions app/spa/src/pages/TeamMembers/TeamMemberDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ const TEAM_MEMBER_QUERY = gql`
automaticUpdate
membershipEffortPercentage
}
teamMemberConsolidationList{
consolidationDate
valuePerHourPerformed
}
demandEffortsList(fromDate: $fromDate, untilDate: $untilDate, pageNumber: $pageNumber) {
demandEfforts{
id
Expand Down
7 changes: 6 additions & 1 deletion spec/graphql/types/query_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1780,7 +1780,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 @@ -1895,6 +1895,10 @@
yAxisProjectsNames
yAxisHours
}
teamMemberConsolidationList {
consolidationDate
valuePerHourPerformed
}
memberThroughputData(numberOfWeeks: 3)
}
})
Expand Down Expand Up @@ -2043,6 +2047,7 @@
'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)}],
'memberThroughputData' => [0, 0, 0, 2],
'demandEfforts' => [{
'finishTimeToComputation' => '2022-05-03T10:00:00-03:00'
Expand Down

0 comments on commit ec70054

Please sign in to comment.