Example #1
0
 def __init__(self,
              sports,
              vbox=None,
              window=None,
              combovalue=None,
              combovalue2=None,
              main=None):
     TimeGraph.__init__(self, sports, vbox=vbox, window=window, main=main)
     self.combovalue = combovalue
     self.combovalue2 = combovalue2
     self.KEY_FORMAT = "%a"
Example #2
0
    def test_IncorporatingOverlap(self):
        tg = TimeGraph()
        tg.addTimeInterval("first", 500, 300)  # 200 - 500
        tg.addTimeInterval("second", 1000, 300)  # 700 - 1000
        tg.addTimeInterval("last", 1500, 900)  # 600 - 1500

        # Expected result: 0[first]300[second]600[last]1500

        self.assertEqual(tg.timeIntervals[0].startTimeInMinutes, 0,
                         "first interval start time wrong")
        self.assertEqual(tg.timeIntervals[0].endTimeInMinutes, 300,
                         "first interval end time wrong")
        self.assertEqual(
            tg.timeIntervals[0].name, "first",
            f"Wrong name at first interval: {tg.timeIntervals[0].name}")

        self.assertEqual(tg.timeIntervals[1].startTimeInMinutes, 300,
                         "second interval start time wrong")
        self.assertEqual(tg.timeIntervals[1].endTimeInMinutes, 600,
                         "second interval end time wrong")
        self.assertEqual(
            tg.timeIntervals[1].name, "second",
            f"Wrong name at second interval: {tg.timeIntervals[1].name}")

        self.assertEqual(tg.timeIntervals[2].startTimeInMinutes, 600,
                         "third interval start time wrong")
        self.assertEqual(tg.timeIntervals[2].endTimeInMinutes, 1500,
                         "third interval end time wrong")
        self.assertEqual(
            tg.timeIntervals[2].name, "last",
            f"Wrong name at third interval: {tg.timeIntervals[2].name}")
Example #3
0
    def test_equalOverlap(self):
        tg = TimeGraph()
        tg.addTimeInterval("first", 500, 300)  # 200 - 500
        tg.addTimeInterval("last", 1000, 300)  # 700 - 1000
        tg.addTimeInterval("middle", 1000, 200)  # 800 - 1000

        # Expected result: 200[first]500[middle]800[last]1000

        self.assertEqual(tg.timeIntervals[0].startTimeInMinutes, 200,
                         "first interval start time wrong")
        self.assertEqual(tg.timeIntervals[0].endTimeInMinutes, 500,
                         "first interval end time wrong")
        self.assertEqual(
            tg.timeIntervals[0].name, "first",
            f"Wrong name at first interval: {tg.timeIntervals[0].name}")

        self.assertEqual(tg.timeIntervals[1].startTimeInMinutes, 500,
                         "second interval start time wrong")
        self.assertEqual(tg.timeIntervals[1].endTimeInMinutes, 700,
                         "second interval end time wrong")
        self.assertEqual(
            tg.timeIntervals[1].name, "middle",
            f"Wrong name at second interval: {tg.timeIntervals[1].name}")

        self.assertEqual(tg.timeIntervals[2].startTimeInMinutes, 700,
                         "third interval start time wrong")
        self.assertEqual(tg.timeIntervals[2].endTimeInMinutes, 1000,
                         "third interval end time wrong")
        self.assertEqual(
            tg.timeIntervals[2].name, "last",
            f"Wrong name at third interval: {tg.timeIntervals[2].name}")
def buildHappyTimeGraph(tmpTasks: [Task], tmpDays: [Day],
                        start: arrow.Arrow) -> TimeGraph:
    # Build a timegraph for the tasks that have a deadline and aren't finished yet
    deadlineTasks = unfinishedDeadlineTasks(tmpTasks)
    deadlineTimeStampsInMinutes = {
        deadlineTask: getFreeTimeBetweenPoints(tmpDays, start,
                                               deadlineTask.deadline)
        for deadlineTask in deadlineTasks
    }

    timegraph = TimeGraph(
    )  # The TimeGraph calculates which times need to be reserved to ensure that no deadlines are missed, even with overlapping deadlines/TimeIntervals

    for deadlineTask in deadlineTasks:
        endTimeInMinutes = deadlineTimeStampsInMinutes[deadlineTask]
        durationInMinutes = deadlineTask.maxRemainingTime  # Takes into consideration already performed progress towards it

        if durationInMinutes == 0:  # Task is already completed
            continue
        name = deadlineTask.name
        # addTimeInterval will automatically make room for it in the TimeGraph by shifting itself or conflicting TimeIntervals to earlier points
        timegraph.addTimeInterval(name, endTimeInMinutes, durationInMinutes)

    return timegraph
Example #5
0
    def test_complexTripleOverlap(self):
        tg = TimeGraph()
        tg.addTimeInterval("first", 500, 300)  # 200 - 500
        tg.addTimeInterval("third", 1000, 300)  # 700 - 1000
        tg.addTimeInterval("second", 800, 300)  # 500 - 800
        tg.addTimeInterval("last", 1050, 100)  # 950 - 1050

        # Expected result: 50[first]350[second]650[third]950[last]1050

        self.assertEqual(tg.timeIntervals[0].startTimeInMinutes, 50,
                         "first interval start time wrong")
        self.assertEqual(tg.timeIntervals[0].endTimeInMinutes, 350,
                         "first interval end time wrong")
        self.assertEqual(
            tg.timeIntervals[0].name, "first",
            f"Wrong name at first interval: {tg.timeIntervals[0].name}")

        self.assertEqual(tg.timeIntervals[1].startTimeInMinutes, 350,
                         "second interval start time wrong")
        self.assertEqual(tg.timeIntervals[1].endTimeInMinutes, 650,
                         "second interval end time wrong")
        self.assertEqual(
            tg.timeIntervals[1].name, "second",
            f"Wrong name at second interval: {tg.timeIntervals[1].name}")

        self.assertEqual(tg.timeIntervals[2].startTimeInMinutes, 650,
                         "third interval start time wrong")
        self.assertEqual(tg.timeIntervals[2].endTimeInMinutes, 950,
                         "third interval end time wrong")
        self.assertEqual(
            tg.timeIntervals[2].name, "third",
            f"Wrong name at third interval: {tg.timeIntervals[2].name}")

        self.assertEqual(tg.timeIntervals[3].startTimeInMinutes, 950,
                         "fourth interval start time wrong")
        self.assertEqual(tg.timeIntervals[3].endTimeInMinutes, 1050,
                         "fourth interval end time wrong")
        self.assertEqual(
            tg.timeIntervals[3].name, "last",
            f"Wrong name at fourth interval: {tg.timeIntervals[3].name}")
Example #6
0
    def test_impossibleOverlapException(self):
        tg = TimeGraph()
        tg.addTimeInterval("first", 500, 300)  # 200 - 500
        tg.addTimeInterval("second", 1000, 300)  # 700 - 1000

        self.assertRaises(Exception, tg.addTimeInterval, "impossible", 600,
                          600)
        self.assertRaises(Exception, tg.addTimeInterval, "impossible", 800,
                          600)
        self.assertRaises(Exception, tg.addTimeInterval, "impossible", 1150,
                          600)

        tg.addTimeInterval("possible", 1200, 600)

        # Expected 0[first]300[second]600[possible]1200

        self.assertEqual(tg.timeIntervals[0].startTimeInMinutes, 0,
                         "first interval start time wrong")
        self.assertEqual(tg.timeIntervals[0].endTimeInMinutes, 300,
                         "first interval end time wrong")
        self.assertEqual(
            tg.timeIntervals[0].name, "first",
            f"Wrong name at first interval: {tg.timeIntervals[0].name}")

        self.assertEqual(tg.timeIntervals[1].startTimeInMinutes, 300,
                         "second interval start time wrong")
        self.assertEqual(tg.timeIntervals[1].endTimeInMinutes, 600,
                         "second interval end time wrong")
        self.assertEqual(
            tg.timeIntervals[1].name, "second",
            f"Wrong name at second interval: {tg.timeIntervals[1].name}")

        self.assertEqual(tg.timeIntervals[2].startTimeInMinutes, 600,
                         "third interval start time wrong")
        self.assertEqual(tg.timeIntervals[2].endTimeInMinutes, 1200,
                         "third interval end time wrong")
        self.assertEqual(
            tg.timeIntervals[2].name, "possible",
            f"Wrong name at third interval: {tg.timeIntervals[2].name}")
Example #7
0
 def drawgraph(self, values):
     TimeGraph.drawgraph(self, values, x_func=self.getYears)
Example #8
0
 def drawgraph(self, values, date_ini):
     TimeGraph.drawgraph(self, values, x_func=lambda x: getDays(date_ini))
Example #9
0
 def drawgraph(self, values, daysInMonth):
     TimeGraph.drawgraph(
         self,
         values,
         x_func=lambda x: list(
             [u'%02d' % d for d in xrange(1, daysInMonth + 1)]))
Example #10
0
 def drawgraph(self,values):
     TimeGraph.drawgraph(self, values, x_func=self.getYears)
Example #11
0
	def __init__(self, sports, vbox = None, combovalue = None):
		TimeGraph.__init__(self, sports, vbox=vbox)
		self.combovalue = combovalue
Example #12
0
 def drawgraph(self, values):
     TimeGraph.drawgraph(
         self, values, x_func=lambda x: ["%02d" % m for m in xrange(1, 13)])
Example #13
0
 def drawgraph(self,values):
     TimeGraph.drawgraph(self, values, x_func=lambda x: ["%02d" % m for m in xrange(1,13)])
Example #14
0
 def drawgraph(self,values, daysInMonth):
     TimeGraph.drawgraph(self, values, x_func=lambda x: list([u'%02d' % d for d in xrange(1,daysInMonth+1)]))
Example #15
0
	def __init__(self, sports, vbox = None, window = None, combovalue = None, combovalue2 = None, main = None):
		TimeGraph.__init__(self, sports, vbox=vbox, window=window, main=main)
		self.combovalue = combovalue
		self.combovalue2 = combovalue2
		self.KEY_FORMAT = "%a"
Example #16
0
	def drawgraph(self,values, date_ini):
		TimeGraph.drawgraph(self, values, x_func=lambda x: getDays(date_ini))
Example #17
0
 def __init__(self, sports, vbox=None, combovalue=None):
     TimeGraph.__init__(self, sports, vbox=vbox)
     self.combovalue = combovalue