Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Challenge: Workload Analyzer | Optimizing Freelance Business with Python
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Python for Freelancers

bookChallenge: Workload Analyzer

Analyzing and optimizing your freelance workload can help prevent burnout and ensure you meet your deadlines without overcommitting. By building a Python program to examine your weekly workload, you can spot weeks where you have taken on too much work and identify ways to balance your schedule more effectively. This approach allows you to make informed decisions about rescheduling projects and managing your time.

To begin, consider a set of hardcoded project data that includes project names, deadlines (as week numbers), and estimated hours required for each project. With this data, you can calculate the total hours of work scheduled for each week. If any week exceeds 40 hours, the program will highlight it and suggest which projects could be moved to another week to distribute the workload more evenly. Finally, the program will output a clear summary for each week, showing the workload and any recommendations for rescheduling.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
# Hardcoded project workload data projects = [ {"name": "Website Redesign", "deadline_week": 1, "estimated_hours": 18}, {"name": "Mobile App", "deadline_week": 1, "estimated_hours": 25}, {"name": "Logo Design", "deadline_week": 2, "estimated_hours": 10}, {"name": "SEO Audit", "deadline_week": 2, "estimated_hours": 12}, {"name": "Content Writing", "deadline_week": 2, "estimated_hours": 20}, {"name": "Data Analysis", "deadline_week": 3, "estimated_hours": 15}, {"name": "Social Media Campaign", "deadline_week": 3, "estimated_hours": 30}, {"name": "Consultation", "deadline_week": 4, "estimated_hours": 8}, {"name": "Bug Fixing", "deadline_week": 4, "estimated_hours": 12}, {"name": "Presentation Prep", "deadline_week": 4, "estimated_hours": 10}, ] # Calculate weekly workload from collections import defaultdict weekly_hours = defaultdict(list) for project in projects: weekly_hours[project["deadline_week"]].append(project) # Analyze workload and suggest rescheduling MAX_WEEKLY_HOURS = 40 summary = {} for week in sorted(weekly_hours): projects_in_week = weekly_hours[week] total_hours = sum(p["estimated_hours"] for p in projects_in_week) summary[week] = { "total_hours": total_hours, "projects": [p["name"] for p in projects_in_week], "overloaded": total_hours > MAX_WEEKLY_HOURS, "reschedule_suggestions": [], } if total_hours > MAX_WEEKLY_HOURS: # Suggest rescheduling: move lowest-priority projects (by hours) until under 40 sorted_projects = sorted(projects_in_week, key=lambda p: p["estimated_hours"], reverse=True) temp_hours = total_hours suggestions = [] for p in sorted_projects: if temp_hours <= MAX_WEEKLY_HOURS: break suggestions.append(p["name"]) temp_hours -= p["estimated_hours"] summary[week]["reschedule_suggestions"] = suggestions # Output summary for week in sorted(summary): print(f"Week {week}:") print(f" Total scheduled hours: {summary[week]['total_hours']}") print(f" Projects: {', '.join(summary[week]['projects'])}") if summary[week]["overloaded"]: print(" Warning: Over 40 hours scheduled!") print(" Suggest rescheduling these projects to balance workload:") print(f" {', '.join(summary[week]['reschedule_suggestions'])}") else: print(" Workload is balanced.") print()
copy
Note
Definition

Definition: In this context, a "week" is simply a numbered period (such as week 1, week 2, etc.), not tied to calendar dates. This makes it easier to test and adapt the analysis for your own scheduling needs.

Tarefa

Swipe to start coding

Write a Python program that:

  • Uses hardcoded data for at least five projects, each with a project name, deadline week, and estimated hours.
  • Calculates total scheduled hours for each week.
  • Identifies any week with more than 40 hours of work.
  • Suggests which projects in overloaded weeks could be rescheduled to balance the workload.
  • Outputs a summary for each week, including any rescheduling suggestions.

Solução

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 3
single

single

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Suggested prompts:

Can you explain how the rescheduling suggestions are determined?

What changes should I make if I want to use my own project data?

How can I adjust the maximum weekly hours limit in the program?

close

bookChallenge: Workload Analyzer

Deslize para mostrar o menu

Analyzing and optimizing your freelance workload can help prevent burnout and ensure you meet your deadlines without overcommitting. By building a Python program to examine your weekly workload, you can spot weeks where you have taken on too much work and identify ways to balance your schedule more effectively. This approach allows you to make informed decisions about rescheduling projects and managing your time.

To begin, consider a set of hardcoded project data that includes project names, deadlines (as week numbers), and estimated hours required for each project. With this data, you can calculate the total hours of work scheduled for each week. If any week exceeds 40 hours, the program will highlight it and suggest which projects could be moved to another week to distribute the workload more evenly. Finally, the program will output a clear summary for each week, showing the workload and any recommendations for rescheduling.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
# Hardcoded project workload data projects = [ {"name": "Website Redesign", "deadline_week": 1, "estimated_hours": 18}, {"name": "Mobile App", "deadline_week": 1, "estimated_hours": 25}, {"name": "Logo Design", "deadline_week": 2, "estimated_hours": 10}, {"name": "SEO Audit", "deadline_week": 2, "estimated_hours": 12}, {"name": "Content Writing", "deadline_week": 2, "estimated_hours": 20}, {"name": "Data Analysis", "deadline_week": 3, "estimated_hours": 15}, {"name": "Social Media Campaign", "deadline_week": 3, "estimated_hours": 30}, {"name": "Consultation", "deadline_week": 4, "estimated_hours": 8}, {"name": "Bug Fixing", "deadline_week": 4, "estimated_hours": 12}, {"name": "Presentation Prep", "deadline_week": 4, "estimated_hours": 10}, ] # Calculate weekly workload from collections import defaultdict weekly_hours = defaultdict(list) for project in projects: weekly_hours[project["deadline_week"]].append(project) # Analyze workload and suggest rescheduling MAX_WEEKLY_HOURS = 40 summary = {} for week in sorted(weekly_hours): projects_in_week = weekly_hours[week] total_hours = sum(p["estimated_hours"] for p in projects_in_week) summary[week] = { "total_hours": total_hours, "projects": [p["name"] for p in projects_in_week], "overloaded": total_hours > MAX_WEEKLY_HOURS, "reschedule_suggestions": [], } if total_hours > MAX_WEEKLY_HOURS: # Suggest rescheduling: move lowest-priority projects (by hours) until under 40 sorted_projects = sorted(projects_in_week, key=lambda p: p["estimated_hours"], reverse=True) temp_hours = total_hours suggestions = [] for p in sorted_projects: if temp_hours <= MAX_WEEKLY_HOURS: break suggestions.append(p["name"]) temp_hours -= p["estimated_hours"] summary[week]["reschedule_suggestions"] = suggestions # Output summary for week in sorted(summary): print(f"Week {week}:") print(f" Total scheduled hours: {summary[week]['total_hours']}") print(f" Projects: {', '.join(summary[week]['projects'])}") if summary[week]["overloaded"]: print(" Warning: Over 40 hours scheduled!") print(" Suggest rescheduling these projects to balance workload:") print(f" {', '.join(summary[week]['reschedule_suggestions'])}") else: print(" Workload is balanced.") print()
copy
Note
Definition

Definition: In this context, a "week" is simply a numbered period (such as week 1, week 2, etc.), not tied to calendar dates. This makes it easier to test and adapt the analysis for your own scheduling needs.

Tarefa

Swipe to start coding

Write a Python program that:

  • Uses hardcoded data for at least five projects, each with a project name, deadline week, and estimated hours.
  • Calculates total scheduled hours for each week.
  • Identifies any week with more than 40 hours of work.
  • Suggests which projects in overloaded weeks could be rescheduled to balance the workload.
  • Outputs a summary for each week, including any rescheduling suggestions.

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 3
single

single

some-alt