Skip to content

Instantly share code, notes, and snippets.

@sausheong
Last active January 3, 2020 14:29
Show Gist options
  • Select an option

  • Save sausheong/be275dd86b71ae0444a788f660c3c1be to your computer and use it in GitHub Desktop.

Select an option

Save sausheong/be275dd86b71ae0444a788f660c3c1be to your computer and use it in GitHub Desktop.
# Tallies up the results from running the simulation. Calculates:
# 1. percentage of completed tasks
# 2. percentage of important tasks completed
# 3. percentage of tasks completed in time
def tally(completed_tasks, all_tasks):
# percentage of tasks completed
completed = len(completed_tasks)/len(all_tasks)
# set the 75th percentile of all tasks based on weight
# as the important tasks
percentile = round(0.75 * len(all_tasks))
important_tasks = sorted(all_tasks, key=lambda x: x.weight)[percentile:len(all_tasks)]
# count how many important tasks have been completed
overlap = 0
for t in important_tasks:
if t in completed_tasks:
overlap += 1
# the weight is the percentage of important tasks completed
if len(important_tasks) > 0:
important = overlap/len(important_tasks)
else:
important = 0
# percentage of tasks that are completed in time
intime_tasks = []
for task in completed_tasks:
if task.done <= task.due:
intime_tasks.append(task)
intime = len(intime_tasks)/len(all_tasks)
return (completed, important, intime)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment