def test_value_init(self):
        """Test valued Shift object creation"""

        # 1. Create valued claim object
        myshift = shift.Shift(number=10, month=11, day=1)

        # 2. Make sure it has the specified values
        self.assertEqual(myshift.number, 10)
        self.assertEqual(myshift.month, 11)
        self.assertEqual(myshift.day, 1)
        self.assertEqual(myshift.falls, 0)
        self.assertEqual(myshift.wakes, 0)
        self.assertEqual(len(myshift.minutes), 0)

        # 3. Check methods
        self.assertEqual(myshift.asleep(), 0)
        self.assertEqual(
            str(myshift), '11-01  #0010  '
            '............................................................')
        myshift.add_fall(falls=5)
        myshift.add_wake(wakes=25)
        myshift.add_fall(falls=30)
        myshift.add_wake(wakes=55)
        self.assertEqual(myshift.asleep(), 20 + 25)
        self.assertEqual(
            str(myshift), '11-01  #0010  '
            '.....####################.....#########################.....')
    def test_text_init(self):
        """Test text Shift object creation"""

        # 1. Create text shift object
        myshift = shift.Shift(text='[1518-11-01 23:58] Guard #99 begins shift')

        # 2. Make sure it has the specified values
        self.assertEqual(myshift.number, 99)
        self.assertEqual(myshift.month, 11)
        self.assertEqual(myshift.day, 2)
        self.assertEqual(myshift.falls, 0)
        self.assertEqual(myshift.wakes, 0)
        self.assertEqual(len(myshift.minutes), 0)

        # 3. Check methods
        self.assertEqual(myshift.asleep(), 0)
        self.assertEqual(
            str(myshift), '11-02  #0099  '
            '............................................................')
        myshift.add_fall(text='[1518-11-02 00:40] falls asleep')
        myshift.add_wake(text='[1518-11-02 00:50] wakes up')
        self.assertEqual(myshift.asleep(), 10)
        self.assertEqual(
            str(myshift), '11-02  #0099  '
            '........................................##########..........')
    def test_often(self):
        """Test Shift object often function"""

        # 1. Create test shift object and record events
        myshift = shift.Shift(text='[1518-11-01 00:00] Guard #10 begins shift')
        myshift.add_fall(text='[1518-11-01 00:05] falls asleep')
        myshift.add_wake(text='[1518-11-01 00:25] wakes up')
        myshift.add_fall(text='[1518-11-01 00:30] falls asleep')
        myshift.add_wake(text='[1518-11-01 00:55] wakes up')
        myshift.add_fall(text='[1518-11-03 00:24] falls asleep')
        myshift.add_wake(text='[1518-11-03 00:29] wakes up')

        # 2. Make sure it has the specified values
        self.assertEqual(myshift.number, 10)
        self.assertEqual(myshift.month, 11)
        self.assertEqual(myshift.day, 3)
        self.assertEqual(myshift.falls, 0)
        self.assertEqual(myshift.wakes, 0)

        # 3. Check methods
        self.assertEqual(myshift.asleep(), 50)
        self.assertEqual(
            str(myshift), '11-03  #0010  '
            '.....########################.#########################.....')
        self.assertEqual(myshift.often(), (24, 2))
Example #4
0
def setWorkbook():
    if Sum[get_column_letter(mNum + 9) + '1'].value == 'Average':
        if mNum == 12:
            set_new_year()
        wb.create_sheet(index=mNum, title=TM[mNum])
        shift.Shift(Sum, Sum.max_column, Sum.max_row, mNum + 12).right()
    currentMonth = wb.get_sheet_by_name(TM[mNum])
    return currentMonth
def setWorkbook():
    '''Checks if this is first input of the month, and makes new sheet if so'''
    if Sum[get_column_letter(mNum+9) + '1'].value == 'Average':
        if mNum == 12: #mNum is current month expressed as a number. See Main
            set_new_year()
        wb.create_sheet(index = mNum, title = TM[mNum])
        shift.Shift(Sum, Sum.max_column, Sum.max_row, mNum+12).right()
    currentMonth = wb.get_sheet_by_name(TM[mNum])
    return currentMonth
Example #6
0
def categorize_meal_type(search):
    cate = ['Breakfast', 'Lunch', 'Dinner', 'Snack', 'Dessert']
    for i in range(4, bottom+1):
        if search == food['A'+str(i)].value:
            break
        else:
            continue
    r = i
    shift.Shift(food, food.max_column, bottom, r).down()
    return r
    def test_empty_init(self):
        """Test default Shift object creation"""

        # 1. Create default shift object
        myshift = shift.Shift()

        # 2. Make sure it has the default values
        self.assertEqual(myshift.number, 0)
        self.assertEqual(myshift.month, 1)
        self.assertEqual(myshift.day, 1)
        self.assertEqual(myshift.falls, 0)
        self.assertEqual(myshift.wakes, 0)
        self.assertEqual(len(myshift.minutes), 0)

        # 3. Check methods
        self.assertEqual(myshift.asleep(), 0)
        self.assertEqual(
            str(myshift), '01-01  #0000  '
            '............................................................')
Example #8
0
def guard_totals(args, input_lines):
    "Process all of the guard log data"

    # 1. Start knowing nothing
    guards = {}
    guard = None

    # 2. Loop through all of the shift log
    for line in input_lines:

        # 3. Process each type of line
        line_type = line.split()[2]
        if line_type == "Guard":

            # 3a. Guard: Start a new shift
            new_shift = shift.Shift(text=line)
            guard = new_shift.number

            # 3b. Guard: Record this guard if new
            if guard not in guards:
                guards[guard] = new_shift

        elif line_type == "falls":

            # 3c. falls: Record falling asleep
            guards[guard].add_fall(text=line)

        elif line_type == "wakes" in line:

            # 3d. wakes: Record minutes asleep
            guards[guard].add_wake(text=line)

    # 4. Return accumulated log data
    if args.verbose:
        print("%d different guards" % len(guards))
    return guards
Example #9
0
 def __init__(self, *args, **kwargs):
     import shift
     template_root = self.config['VIEWS_DIRECTORY'] or 'views'
     self._shift = shift.Shift(template_root=template_root)
     super(HobokenRenderMixin, self).__init__(*args, **kwargs)
def generatePathShifts(info):
    pathShifts = [[] for _ in range(info['nDays'])]
    """If a node p is inserted in a route t between i and j, let shiftp = travelip +
	waitp + visitp + travelpj - travelij denote the time cost added to the overall route time
	due to the insertion of p. The node p can be inserted in a route t between i and j
	if and only if startit + visiti + travelip + visitp <= closept and at the same time
	shiftp <= waitj + maxShiftj."""

    for node in info['nodes']:
        if info['inserted'][node.index] != -1:
            continue

        globalMinShift = shift.Shift(math.inf, math.inf, math.inf, -1, 0)

        i = 0
        for path in info['paths']:

            if not validateNodeForPath(node, i):
                continue

            localMinShift = shift.Shift(math.inf, math.inf, math.inf, -1, 0)

            clusterParameter = 1

            # We prefer that same cluster nodes are added preferably
            if node.cluster == i:
                clusterParameter = info['clusterParameter']

            for it in range(-1, len(path)):
                if it == -1:
                    zeroNode = info['nodes'][path[0]]

                    # Calculate shift by using wait time of first node, visit time, distance between node and second node
                    shiftVal = 0 + node.hours[i][0] + node.visit \
                    + info['costMatrix'][node.index][zeroNode.index]

                    # First condition that shift must be less than wait + maxShift of second node
                    if shiftVal > zeroNode.wait + zeroNode.maxShift:
                        continue

                    # Second condition if start time of the first node + visit time + travel time to second node
                    # must be less than closing hours - visit time of second node
                    if node.hours[i][0] + node.visit + zeroNode.visit \
                    + info['costMatrix'][node.index][zeroNode.index] > zeroNode.hours[i][1]:
                        continue

                    shiftVal /= clusterParameter
                    if shiftVal < localMinShift.val:
                        localMinShift = shift.Shift(it, i, shiftVal,
                                                    node.index, node.profit)
                        continue

                elif it == len(path) - 1:
                    finalNode = info['nodes'][path[it]]
                    waitp = node.hours[i][0] - (finalNode.reach + finalNode.visit + \
                     info['costMatrix'][finalNode.index][node.index]) \
                    if (finalNode.reach + finalNode.visit + \
                     info['costMatrix'][finalNode.index][node.index]) < node.hours[i][0] else 0

                    if node.hours[i][1] > 24 * 60 - 1:
                        continue

                    shiftVal = info['costMatrix'][finalNode.index][node.index] \
                    + waitp + node.visit

                    if (finalNode.reach + finalNode.visit \
                    + info['costMatrix'][finalNode.index][node.index] + node.visit) \
                    > node.hours[i][1]:
                        continue

                    shiftVal /= clusterParameter
                    if shiftVal < localMinShift.val:
                        localMinShift = shift.Shift(it, i, shiftVal,
                                                    node.index, node.profit)

                else:
                    prevNode = info['nodes'][path[it]]
                    nextNode = info['nodes'][path[it + 1]]

                    waitp = node.hours[i][0] - (prevNode.reach + prevNode.visit + \
                     info['costMatrix'][prevNode.index][node.index]) \
                    if (prevNode.reach + prevNode.visit + info['costMatrix'][prevNode.index][node.index]) < \
                    node.hours[i][0] else 0

                    shiftVal = info['costMatrix'][prevNode.index][node.index] + waitp + \
                    node.visit + info['costMatrix'][node.index][nextNode.index] - \
                    info['costMatrix'][prevNode.index][nextNode.index]

                    if shiftVal > nextNode.wait + nextNode.maxShift:
                        continue

                    if prevNode.reach + prevNode.visit + \
                    info['costMatrix'][prevNode.index][node.index] \
                    + node.visit > node.hours[i][1]:
                        continue

                    shiftVal /= clusterParameter
                    if shiftVal < localMinShift.val:
                        localMinShift = shift.Shift(it, i, shiftVal,
                                                    node.index, node.profit)

            if globalMinShift.val > localMinShift.val:
                globalMinShift = localMinShift
            i += 1

        if globalMinShift.val == math.inf:
            continue

        pathShifts[globalMinShift.path].append(globalMinShift)

    return pathShifts