Skip to content

Commit

Permalink
fix: fixed hour value for team member
Browse files Browse the repository at this point in the history
  • Loading branch information
celsoMartins committed Dec 6, 2023
1 parent 1e82309 commit fc5ba62
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Types
module Teams
class MembershipHourValueChartDataType < Types::BaseObject
class MemberHourValueChartDataType < Types::BaseObject
field :date, GraphQL::Types::ISO8601Date
field :hour_value_expected, Float
field :hour_value_realized, Float
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
module Types
module Teams
class MembershipHourValueChartListType < Types::BaseObject
field :member_hour_value_chart_data, [Types::Teams::MemberHourValueChartDataType]
field :membership, Types::Teams::MembershipType
field :membership_hour_value_chart_data, [Types::Teams::MembershipHourValueChartDataType]
end
end
end
10 changes: 10 additions & 0 deletions app/graphql/types/teams/team_member_hour_value_chart_list_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

module Types
module Teams
class TeamMemberHourValueChartListType < Types::BaseObject
field :member_hour_value_chart_data, [Types::Teams::MemberHourValueChartDataType]
field :team, Types::Teams::TeamType
end
end
end
63 changes: 36 additions & 27 deletions app/graphql/types/teams/team_member_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,52 @@ class TeamMemberType < Types::BaseObject
argument :page_number, Integer, required: false
argument :until_date, GraphQL::Types::ISO8601Date, required: false
end
field :demand_largest_lead_time, Types::DemandType, null: true
field :demand_lead_time_p80, Float, null: true
field :demand_shortest_lead_time, Types::DemandType, null: true
field :demands, [Types::DemandType] do
argument :limit, Int, required: false
argument :status, Types::Enums::DemandStatusesType, required: false
argument :type, String, required: false
end
field :end_date, GraphQL::Types::ISO8601Date, null: true
field :first_delivery, Types::DemandType, null: true
field :first_demand_delivery, Types::DemandType, null: true
field :hours_per_month, Int, null: false
field :id, ID, null: false
field :jira_account_id, String, null: true
field :jira_account_user_email, String, null: true
field :monthly_payment, Float, null: true
field :name, String, null: false
field :start_date, GraphQL::Types::ISO8601Date, null: true
field :teams, [Types::Teams::TeamType], null: true
field :user, Types::UserType, null: true

field :demands, [Types::DemandType] do
argument :limit, Int, required: false
argument :status, Types::Enums::DemandStatusesType, required: false
argument :type, String, required: false
end

field :projects_list, Types::ProjectsListType, null: true do
argument :order_field, String, required: true
argument :page_number, Int, required: false
argument :per_page, Int, required: false
argument :sort_direction, Types::Enums::SortDirection, required: false
end
field :start_date, GraphQL::Types::ISO8601Date, null: true
field :teams, [Types::Teams::TeamType], null: true
field :user, Types::UserType, null: true

field :demand_largest_lead_time, Types::DemandType, null: true
field :demand_shortest_lead_time, Types::DemandType, null: true
field :first_demand_delivery, Types::DemandType, null: true

field :demand_lead_time_p80, Float, null: true
field :first_delivery, Types::DemandType, null: true

field :average_pull_interval_data, Types::Charts::SimpleDateChartDataType, null: true
field :demand_blocks_list, Types::DemandBlocksListType, null: true do
argument :order_field, String, required: true
argument :page_number, Int, required: false
argument :per_page, Int, required: false
argument :sort_direction, Types::Enums::SortDirection, required: false
end

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
field :member_effort_daily_data, Types::Charts::SimpleDateChartDataType, null: true
field :member_effort_data, Types::Charts::SimpleDateChartDataType, null: true

field :member_throughput_data, [Int], null: true do
argument :number_of_weeks, Int, required: false
end

field :project_hours_data, Types::Charts::ProjectHoursChartDataType, null: true
field :team_member_hour_value_chart_list, [Types::Teams::TeamMemberHourValueChartListType], null: true do
argument :end_date, GraphQL::Types::ISO8601Date, required: false
argument :start_date, GraphQL::Types::ISO8601Date, required: false
end

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)
Expand Down Expand Up @@ -164,6 +161,24 @@ def project_hours_data
{ x_axis: team_chart_adapter.x_axis_hours_per_project, y_axis_projects_names: team_chart_adapter.y_axis_hours_per_project.pluck(:name), y_axis_hours: team_chart_adapter.y_axis_hours_per_project.pluck(:data).flatten }
end

def team_member_hour_value_chart_list(start_date: 6.months.ago, end_date: Time.zone.now)
months = TimeService.instance.months_between_of(start_date, end_date)

member_hour_value_list = []
object.teams.each do |team|
member_hour_value_chart_data = []
months.each do |month|
membership = object.memberships.active_for_date(month).find_by(team: team)
next if membership.blank?

member_hour_value_chart_data.push({ date: month, hour_value_expected: membership.expected_hour_value(month), hour_value_realized: membership.realized_hour_value(month) })
end
member_hour_value_list.push({ team: team, member_hour_value_chart_data: member_hour_value_chart_data })
end

member_hour_value_list
end

private

def operations_dashboards
Expand Down Expand Up @@ -197,12 +212,6 @@ def last_30_days_hash
end
accumulator
end

def compute_hours_per_month(monthly_payment, monthly_hours)
return monthly_payment if monthly_hours.zero?

monthly_payment / monthly_hours
end
end
end
end
12 changes: 6 additions & 6 deletions app/graphql/types/teams/team_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TeamType < Types::BaseObject
field :lead_time_p80, Float, null: true
field :lead_time_p95, Float, null: true
field :max_work_in_progress, Int, null: false
field :membership_hour_value_chart_list_type, [Types::Teams::MembershipHourValueChartListType] do
field :membership_hour_value_chart_list, [Types::Teams::MembershipHourValueChartListType] do
argument :end_date, GraphQL::Types::ISO8601Date, required: false
argument :start_date, GraphQL::Types::ISO8601Date, required: false
end
Expand Down Expand Up @@ -145,7 +145,7 @@ def team_consolidations_weekly(start_date: 6.months.ago, end_date: Time.zone.tod
weekly_team_consolidations = object.team_consolidations.weekly_data.order(:consolidation_date)

consolidations = Consolidations::TeamConsolidation
.where(id: weekly_team_consolidations.map(&:id) + [last_consolidation&.id])
.where(id: weekly_team_consolidations.map(&:id) + [last_consolidation&.id])
consolidations = consolidations.where('consolidation_date >= :limit_date', limit_date: start_date) if start_date.present?
consolidations = consolidations.where('consolidation_date <= :limit_date', limit_date: end_date) if end_date.present?
consolidations.order(:consolidation_date)
Expand All @@ -170,16 +170,16 @@ def team_member_efficiency(month: Time.zone.today.month, year: Time.zone.today.y
TeamService.instance.compute_memberships_realized_hours(object, start_date, end_date)
end

def membership_hour_value_chart_list_type(start_date: 6.months.ago, end_date: Time.zone.now)
def membership_hour_value_chart_list(start_date: 6.months.ago, end_date: Time.zone.now)
months = TimeService.instance.months_between_of(start_date, end_date)

memberships_hour_value_list = []
object.memberships.active.billable_member.each do |membership|
membership_hour_value_chart_data = []
member_hour_value_chart_data = []
months.each do |month|
membership_hour_value_chart_data.push({ date: month, hour_value_expected: membership.expected_hour_value(month), hour_value_realized: membership.realized_hour_value(month) })
member_hour_value_chart_data.push({ date: month, hour_value_expected: membership.expected_hour_value(month), hour_value_realized: membership.realized_hour_value(month) })
end
memberships_hour_value_list.push({ membership: membership, membership_hour_value_chart_data: membership_hour_value_chart_data })
memberships_hour_value_list.push({ membership: membership, member_hour_value_chart_data: member_hour_value_chart_data })
end

memberships_hour_value_list
Expand Down
26 changes: 13 additions & 13 deletions app/spa/src/components/TeamMemberDashboardCharts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,21 @@ const TeamMemberDashboardCharts = ({
}
)

const lineChartData = [
{
id: teamMember.name,
data: teamMember.teamMemberConsolidationList
? teamMember.teamMemberConsolidationList.map(
({ valuePerHourPerformed, consolidationDate }) => {
const lineChartTeamMemberHourValueData =
teamMember?.teamMemberHourValueChartList?.map((teamMemberHourValueList) => {
return {
id: teamMemberHourValueList.team?.name ?? "",
data:
teamMemberHourValueList.memberHourValueChartData?.map(
(memberHourValueChartData) => {
return {
x: String(consolidationDate || ""),
y: Number(valuePerHourPerformed || 0),
x: String(memberHourValueChartData.date || ""),
y: String(memberHourValueChartData.hourValueRealized || 0),
}
}
)
: [],
},
]
) ?? [],
}
}) ?? []

return (
<Grid container spacing={2}>
Expand Down Expand Up @@ -162,7 +162,7 @@ const TeamMemberDashboardCharts = ({
{projectHoursData && (
<ChartGridItem title={t("charts.valuePerHour")}>
<LineChart
data={lineChartData}
data={lineChartTeamMemberHourValueData}
axisLeftLegend={t("charts.valuePerHour")}
axisBottomLegend={t("charts.memberEffort_x_label")}
props={{
Expand Down
4 changes: 2 additions & 2 deletions app/spa/src/modules/team/team.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ export type MembershipEfficiencyData = {

type MembershipHourValueChartList = {
membership?: Membership
membershipHourValueChartData?: MembershipHourValueChartData[]
memberHourValueChartData?: MemberHourValueChartData[]
}

type MembershipHourValueChartData = {
export type MemberHourValueChartData = {
date?: string
hourValueExpected?: number
hourValueRealized?: number
Expand Down
8 changes: 7 additions & 1 deletion app/spa/src/modules/teamMember/teamMember.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Demand, DemandBlocksList } from "../demand/demand.types"
import { ProjectsList } from "../project/project.types"
import { Team } from "../team/team.types"
import { MemberHourValueChartData, Team } from "../team/team.types"
import User from "../user/user.types"
import { ChartAxisData, KeyValueData } from "../charts/charts.types"
import { DemandEffort } from "../demandEffort/demandEffort.types"
Expand Down Expand Up @@ -43,6 +43,12 @@ export type TeamMember = {
}
demandEfforts?: DemandEffort[]
demandEffortsList?: DemandEffortsList
teamMemberHourValueChartList?: TeamMemberHourValueChartList[]
}

type TeamMemberHourValueChartList = {
team?: Team
memberHourValueChartData?: MemberHourValueChartData[]
}

type DemandEffortsList = {
Expand Down
11 changes: 11 additions & 0 deletions app/spa/src/pages/TeamMembers/TeamMemberDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ const TEAM_MEMBER_QUERY = gql`
demandEffortsCount
effortsValueSum
}
teamMemberHourValueChartList {
team {
id
name
}
memberHourValueChartData {
date
hourValueRealized
}
}
}
}
`
Expand Down
14 changes: 7 additions & 7 deletions app/spa/src/pages/Teams/TeamDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const TEAM_DASHBOARD_QUERY = gql`
id
teamMemberName
}
membershipHourValueChartData {
memberHourValueChartData {
date
hourValueRealized
}
Expand Down Expand Up @@ -215,16 +215,16 @@ const TeamDashboard = () => {
},
]

const lineChartMembershipData =
const lineChartMembershipHourValueData =
team?.membershipHourValueChartList?.map((membershipHourValueList) => {
return {
id: membershipHourValueList.membership?.teamMemberName ?? "",
data:
membershipHourValueList.membershipHourValueChartData?.map(
(membershipHourValueChartData) => {
membershipHourValueList.memberHourValueChartData?.map(
(memberHourValueChartData) => {
return {
x: String(membershipHourValueChartData.date || ""),
y: String(membershipHourValueChartData.hourValueRealized || 0),
x: String(memberHourValueChartData.date || ""),
y: String(memberHourValueChartData.hourValueRealized || 0),
}
}
) ?? [],
Expand Down Expand Up @@ -344,7 +344,7 @@ const TeamDashboard = () => {

<ChartGridItem title={t("charts.hoursPerPeriodMemberships")}>
<LineChart
data={lineChartMembershipData}
data={lineChartMembershipHourValueData}
axisLeftLegend={t("charts.valueInReal")}
props={{
enableSlices: "x",
Expand Down
Loading

0 comments on commit fc5ba62

Please sign in to comment.