Skip to content

Commit

Permalink
Merge pull request #98 from ElemarJR/graph_on_forecast_2025
Browse files Browse the repository at this point in the history
Graph on forecast 2025
  • Loading branch information
ElemarJR authored Jan 10, 2025
2 parents 61dfd9d + 305c450 commit e693821
Show file tree
Hide file tree
Showing 4 changed files with 474 additions and 151 deletions.
4 changes: 4 additions & 0 deletions backend/api/src/analytics/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,10 @@ type YearlyForecastByMonth {
expectedHandsOnFee: Float!
expectedSquadFee: Float!
actual: Float!
actualConsultingFee: Float!
actualConsultingPreFee: Float!
actualHandsOnFee: Float!
actualSquadFee: Float!
}

# In Consulting
Expand Down
159 changes: 27 additions & 132 deletions backend/api/src/analytics/yearly_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def resolve_yearly_forecast(_, info, year=None):
# discount = month_actual
actual += month_actual

by_month.append({

month = {
"month": m,
"goal": goal,
"working_days": len(get_working_days_in_month(y, m)),
Expand All @@ -59,7 +59,31 @@ def resolve_yearly_forecast(_, info, year=None):
"expected_hands_on_fee": forecast_doi["by_kind"]["hands_on"]['totals'].in_analysis,
"expected_consulting_pre_fee": forecast_doi["by_kind"]["consulting_pre"]['totals'].in_analysis,
"actual": month_actual
})
}

if y < current_year or (y == current_year and m < current_month):
month_actual = {
"actual_consulting_fee": forecast["by_kind"]["consulting"]['totals'].in_analysis,
"actual_squad_fee": forecast["by_kind"]["squad"]['totals'].in_analysis,
"actual_hands_on_fee": forecast["by_kind"]["hands_on"]['totals'].in_analysis,
"actual_consulting_pre_fee": forecast["by_kind"]["consulting_pre"]['totals'].in_analysis
}
elif y == current_year and m == current_month:
month_actual = {
"actual_consulting_fee": forecast_doi["by_kind"]["consulting"]['totals'].in_analysis,
"actual_squad_fee": forecast_doi["by_kind"]["squad"]['totals'].in_analysis,
"actual_hands_on_fee": forecast_doi["by_kind"]["hands_on"]['totals'].in_analysis,
"actual_consulting_pre_fee": forecast_doi["by_kind"]["consulting_pre"]['totals'].in_analysis
}
else:
month_actual = {
"actual_consulting_fee": 0,
"actual_squad_fee": 0,
"actual_hands_on_fee": 0,
"actual_consulting_pre_fee": 0
}

by_month.append(month | month_actual)

main_goal -= discount

Expand Down Expand Up @@ -87,132 +111,3 @@ def resolve_yearly_forecast(_, info, year=None):
"realized_working_days": realized_working_days
}


# def get_expected_regular_consulting_revenue(year, month):

# result = 0

# cases = [
# case
# for case in globals.omni_models.cases.get_all().values()
# if case.is_active
# ]

# for case in cases:
# wah = case.weekly_approved_hours

# if not wah:
# continue

# project_ = None
# for project_info in case.tracker_info:
# if project_info.kind == 'consulting' and project_info.rate and project_info.rate.rate:
# project_ = project_info
# break

# if not project_:
# continue

# working_days_in_month = get_working_days_in_month(year, month)
# days_in_month = calendar.monthrange(year, month)[1]

# hours_in_month = 0
# daily_approved_hours = wah / 5

# due_on = project_.due_on.date() if project_ and project_.due_on else case.end_of_contract

# for day in range(1, days_in_month + 1):
# date = datetime(year, month, day)

# if case.start_of_contract and date.date() < case.start_of_contract:
# continue

# if due_on and date.date() > due_on:
# break

# if date in working_days_in_month:
# hours_in_month += daily_approved_hours

# result += hours_in_month * (project_.rate.rate / 100)

# return result

# def get_expected_pre_contracted_revenue(year, month):

# cases = [
# case
# for case in globals.omni_models.cases.get_all().values()
# if case.is_active
# ]

# consulting_pre = 0
# hands_on = 0
# squad = 0

# for case in cases:
# start = case.start_of_contract # .replace(day=1)
# if start is None:
# start = datetime(year, month, 1)
# else:
# start = start.replace(day=1)

# end = case.end_of_contract
# if end is None:
# end = datetime(year, month, calendar.monthrange(year, month)[1])

# in_contract = start.year <= year <= end.year
# if in_contract and year == start.year:
# in_contract = month >= start.month

# if in_contract and year == end.year:
# in_contract = month <= end.month

# if not in_contract:
# continue

# for project_info in case.tracker_info:
# if project_info.billing and project_info.billing.fee and project_info.billing.fee != 0:
# if project_info.budget and project_info.budget.period == 'general':
# if start.year == end.year:
# number_of_months = end.month - start.month + 1
# else:
# months_on_start_year = 12 - start.month + 1
# months_on_end_year = end.month
# if end.year - start.year > 1:
# number_of_months = months_on_start_year + months_on_end_year + (end.year - start.year - 1) * 12
# else:
# number_of_months = months_on_start_year + months_on_end_year

# fee = project_info.billing.fee / 100 / number_of_months

# if project_info.kind == 'consulting':
# consulting_pre += fee
# elif project_info.kind == 'squad':
# squad += fee
# else: # hands_on
# hands_on += fee

# else:
# fee = project_info.billing.fee / 100
# date_of_interest = datetime(year, month, 5)

# if project_info.created_at > date_of_interest:
# fee = 0

# if project_info.due_on and (project_info.due_on.date() if hasattr(project_info.due_on, 'date') else project_info.due_on) < (date_of_interest.date() if hasattr(date_of_interest, 'date') else date_of_interest):
# fee = 0

# if project_info.kind == 'consulting':
# consulting_pre += fee
# elif project_info.kind == 'squad':
# squad += fee
# else: # hands_on
# hands_on += fee


# return {
# "consulting_pre": consulting_pre,
# "hands_on": hands_on,
# "squad": squad
# }

Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def process_project(date_of_interest: date, case: Case, project, timesheet_df: p
)

if should_do_pro_rata:
fee = fee * (calendar.monthrange(date_of_interest.year, date_of_interest.month)[1] / date_of_interest.day)
fee = fee * (case.end_of_contract.day / calendar.monthrange(date_of_interest.year, date_of_interest.month)[1])

result = {
"kind": project.kind,
Expand Down
Loading

0 comments on commit e693821

Please sign in to comment.