Skip to content

Instantly share code, notes, and snippets.

@solidiquis
Created October 20, 2019 23:06
Show Gist options
  • Save solidiquis/3d02206aeef9a626ed0c83a25092e704 to your computer and use it in GitHub Desktop.
Save solidiquis/3d02206aeef9a626ed0c83a25092e704 to your computer and use it in GitHub Desktop.
Priority
#!/usr/bin/env python3
from prioritize import MaxHeapq
import code
class Task:
tasks = []
def __init__(self, *args, **kwargs):
self.description = kwargs["description"]
self.duration = str(kwargs["duration"]) + " min"
self.multitask = kwargs["multitask"]
self.dependencies = kwargs["dependencies"]
self.status = kwargs["status"]
self.id = self.assign_id() if self.tasks else 1
self.tasks.append(self)
def priority(self, priority_score=100):
return priority_score - len(self.get_total_dependencies())
def get_total_dependencies(self):
if len(self.dependencies) == 0:
return set()
#soft + hard dependencies
total_dependencies = set(self.dependencies)
for dependency_id in self.dependencies:
dependency = self.find_by_id(dependency_id)
total_dependencies |= dependency.get_total_dependencies()
return total_dependencies
def get_number_of_dependencies(self):
return len(self.dependencies)
def has_dependencies(self):
return False if len(self.dependencies) == 0 else True
def assign_id(self):
return self.last().id + 1
@classmethod
def find_by_id(cls, id):
for i in cls.tasks:
if i.id == id:
return i
else:
print(f"Task with ID: {id} does not exist.")
return None
@classmethod
def last(cls):
return cls.tasks[-1]
golden1 = Task(
description="Walk around lake",
duration=20,
multitask=True,
dependencies=[],
status="NOT-YET-STARTED"
)
golden2 = Task(
description="Buy museum tickets",
duration=3,
multitask=False,
dependencies=[golden1.id],
status="NOT-YET-STARTED"
)
golden3 = Task(
description="Explore museum",
duration=30,
multitask=True,
dependencies=[golden1.id, golden2.id],
status="NOT-YET-STARTED"
)
#Discover music
music1 = Task(
description="Research music",
duration=5,
multitask=False,
dependencies=[],
status="NOT-YET-STARTED"
)
music2 = Task(
description="Choose songs",
duration=10,
multitask=False,
dependencies=[music1.id],
status="NOT-YET-STARTED"
)
music3 = Task(
description="Create playlist",
duration=10,
multitask=False,
dependencies=[music1.id, music2.id],
status="NOT-YET-STARTED"
)
music4 = Task(
description="Listen songs",
duration=100,
multitask=True,
dependencies=[music1.id, music2.id, music3.id],
status="NOT-YET-STARTED"
)
#Castro St
castro1 = Task(
description="Take bus",
duration=30,
multitask=True,
dependencies=[],
status="NOT-YET-STARTED"
)
castro2 = Task(
description="Walk on Castro",
duration=30,
multitask=True,
dependencies=[castro1.id],
status="NOT-YET-STARTED"
)
castro3 = Task(
description="Buy snacks",
duration=10,
multitask=True,
dependencies=[castro1.id],
status="NOT-YET-STARTED"
)
castro4 = Task(
description="Theatre",
duration=120,
multitask=False,
dependencies=[castro1.id, castro2.id],
status="NOT-YET-STARTED"
)
#Corona heights
corona1 = Task(
description="Decide route",
duration=5,
multitask=False,
dependencies=[],
status="NOT-YET-STARTED"
)
corona2 = Task(
description="Get to trail",
duration=5,
multitask=False,
dependencies=[castro1.id, castro2.id, castro3.id, castro4.id],
status="NOT-YET-STARTED"
)
corona3 = Task(
description="Walk trail",
duration=60,
multitask=True,
dependencies=[corona2.id],
status="NOT-YET-STARTED"
)
corona4 = Task(
description="Drink Water",
duration=10,
multitask=True,
dependencies=[corona2.id],
status="NOT-YET-STARTED"
)
corona5 = Task(
description="Go for meal",
duration=30,
multitask=True,
dependencies=[corona3.id, corona4.id],
status="NOT-YET-STARTED"
)
#Financial Districr
financial1 = Task(
description="Eat meal",
duration=40,
multitask=True,
dependencies=[corona5.id],
status="NOT-YET-STARTED"
)
financial2 = Task(
description="Discover skyscrapers",
duration=40,
multitask=True,
dependencies=[financial1.id],
status="NOT-YET-STARTED"
)
financial3 = Task(
description="Research skyscrapers story",
duration=10,
multitask=False,
dependencies=[financial1.id],
status="NOT-YET-STARTED"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment