示例#1
0
def get_route_schedule():
    """
    Pulls general schedule info for a specified route and date
    Returns:
        date specified
        route specified
        inbound, outbound dataframes as json
        list of stops
        mean, mode intervals between stops fou route
    Expects date as string: YYYY-MM-DD
    Expects route as string
    """
    route_id = request.args.get('route_id', default='1')
    day = request.args.get('day', default=(date.today() - timedelta(days=1)))

    sched = Schedule(route_id, day, creds)

    tables = {
        'date': day,
        'route': sched.route_id,
        'inbound': sched.inbound_table.to_json(),
        'outbound': sched.outbound_table.to_json(),
        'stops': sched.list_stops(),
        'intervals': {
            'mean': sched.mean_interval,
            'mode': sched.common_interval
        }
    }

    return json.dumps(tables, sort_keys=False, default=str)
示例#2
0
def test_change_record_data():
    start_datetime = datetime.datetime(year=2020, month=1, day=1)
    schedule = Schedule(start_datetime, duration=3600)

    _range = DateTimeRange(start_datetime,
                           start_datetime + datetime.timedelta(minutes=1))
    assert schedule.add_record('OLD TYPE', _range)

    assert len(schedule.records) == 1
    assert 'data' in schedule.records[-1]
    assert schedule.records[-1]['data'] is None

    existed_record = schedule.records[-1]

    new_range = DateTimeRange(start_datetime,
                              start_datetime + datetime.timedelta(minutes=2))
    new_record = {
        'type': 'NEW TYPE',
        'range': new_range,
        'data': {
            'key': 'val'
        }
    }
    assert schedule.change_record(existed_record, new_record)

    assert 'data' in schedule.records[-1]
    assert schedule.records[-1]['data'] == {'key': 'val'}
def test_get_records_empty_schedule():
    start_datetime = datetime.datetime(year=2020, month=1, day=1)
    schedule = Schedule(start_datetime, duration=3600)

    _range = DateTimeRange(start_datetime,
                           start_datetime + datetime.timedelta(minutes=1))
    records = schedule.get_records_in_range(_range)
    assert records == []
示例#4
0
def test_simple_add_to_schedule_no_duration_and_no_range(caplog):
    caplog.set_level(logging.INFO)
    start_datetime = datetime.datetime(year=2020, month=1, day=1)
    schedule = Schedule(start_datetime)

    _range = DateTimeRange(start_datetime,
                           start_datetime + datetime.timedelta(minutes=1))
    assert not schedule.add_record('Test_type', _range)
    assert len(schedule.records) == 0
def main():
    """Main entry point for schedule module."""
    # Setup parser and arguments
    parser = argparse.ArgumentParser(description='Schedule batch jobs')
    parser.add_argument("-p","--profile", help="Profile.",default=None)
    parser.add_argument("-r","--region", help="Region.",default=None)
    parser.add_argument("-q","--queue", help="Queue Name.",default=None)
    parser.add_argument("-j","--job", help="Job Definition.",default=None)
    args = parser.parse_args()

    # Setup scheduler object and call run
    scheduler = Schedule(profile=args.profile,region=args.region)
    scheduler.run(queue=args.queue,jobdef=args.job)
示例#6
0
def test_simple_add_to_schedule_duration():
    start_datetime = datetime.datetime(year=2020, month=1, day=1)
    schedule = Schedule(start_datetime, duration=3600)

    _range = DateTimeRange(start_datetime,
                           start_datetime + datetime.timedelta(minutes=1))
    assert schedule.add_record('Test_type', _range)
    assert len(schedule.records) == 1

    _range = DateTimeRange(start_datetime + datetime.timedelta(minutes=1),
                           start_datetime + datetime.timedelta(minutes=2))
    assert schedule.add_record('Test_type', _range)
    assert len(schedule.records) == 2
def test_get_records_wrong_range():
    start_datetime = datetime.datetime(year=2020, month=1, day=1)
    schedule = Schedule(start_datetime, duration=3600)

    range_1 = DateTimeRange(start_datetime,
                            start_datetime + datetime.timedelta(minutes=1))
    schedule.add_record('TYPE_1', range_1)

    range_2 = DateTimeRange(start_datetime + datetime.timedelta(minutes=1),
                            start_datetime + datetime.timedelta(minutes=2))
    schedule.add_record('TYPE_1', range_2)

    assert len(schedule.records) == 2

    required_range = DateTimeRange(
        start_datetime + datetime.timedelta(minutes=3),
        start_datetime + datetime.timedelta(minutes=4))

    records = schedule.get_records_in_range(required_range)
    assert len(records) == 0

    required_range = DateTimeRange(
        start_datetime + datetime.timedelta(minutes=2),
        start_datetime + datetime.timedelta(minutes=3))
    records = schedule.get_records_in_range(required_range)
    assert len(records) == 0
示例#8
0
def test_change_record_type():
    start_datetime = datetime.datetime(year=2020, month=1, day=1)
    schedule = Schedule(start_datetime, duration=3600)

    _range = DateTimeRange(start_datetime,
                           start_datetime + datetime.timedelta(minutes=1))
    assert schedule.add_record('OLD TYPE', _range)

    assert len(schedule.records) == 1
    existed_record = schedule.records[-1]
    assert 'type' in existed_record
    assert existed_record['type'] == 'OLD TYPE'
    new_record = {'type': 'NEW TYPE', 'range': _range, 'data': None}
    assert schedule.change_record(existed_record, new_record)

    assert 'type' in schedule.records[-1]
    assert schedule.records[-1]['type'] == 'NEW TYPE'
def createScheduleSubscribeCallback(client, userdata, message):
    log.info("----------  createScheduleSubscribeCallback ---------------")
    log.info("Topic : " + str(message.topic))
    log.info("Message: " + str(message.payload))
    log.info("-------------------------------")

    # take action and set the schedule
    request = SetScheduleRequest(message.payload)
    schedule = Schedule(request.plantPort, request.scheduledDuration,
                        request.scheduledFrequency, request.scheduledStartTime)
    scheduler.setSchedule(schedule)
示例#10
0
    def parse(self, html: str) -> Schedule:
        row_pattern = re.compile(
            r"<tr.*?>\s*(?P<cells><td.*?>.+?</td>)\s*</tr>", re.S)
        cell_pattern = re.compile(r"<td.*?>\s*(?P<content>.*?)\s*</td>", re.S)
        time_pattern = re.compile(
            r"(?P<start>\d{1,2}[:.]\d{2}).(?P<end>\d{1,2}[:.]\d{2})")
        rows: iter = row_pattern.finditer(html)
        # day_info (first table cell): weekday; date; timing_type (split by \xa0)
        day_info: list[str] = self.strip_tags(
            cell_pattern.search(
                next(rows).group("cells")).group()).split('\xa0')
        schedule = Schedule(datetime.strptime(day_info[1], "%d.%m.%Y"),
                            '\xa0'.join(day_info[2:]))
        grades_added: bool = False

        for row in rows:
            cells = cell_pattern.findall(row.group("cells"))

            # first column contains only lesson numbers - no need to go through it
            # second (i=1) contains lesson timeslots, need a special treatment for it
            for i in range(1, len(cells)):
                cell_text = self.strip_tags(cells[i])
                if grades_added:
                    if i == 1:
                        timeslot = time_pattern.search(cell_text).groupdict()
                        schedule.add_timeslot(timeslot["start"],
                                              timeslot["end"])
                    else:
                        schedule.add_by_index(i - 2, cell_text)
                else:
                    if i != 1:
                        # adding the grades using the first (second) table row
                        schedule.add_grade(cell_text)

            grades_added = True

        schedule.trim_empty()
        return schedule
示例#11
0
def test_change_wrong_record():
    start_datetime = datetime.datetime(year=2020, month=1, day=1)
    schedule = Schedule(start_datetime, duration=3600)

    _range = DateTimeRange(start_datetime,
                           start_datetime + datetime.timedelta(minutes=1))
    assert schedule.add_record('OLD TYPE', _range)

    not_existed_record = copy.deepcopy(schedule.records[-1])

    new_range = DateTimeRange(start_datetime,
                              start_datetime + datetime.timedelta(minutes=2))
    not_existed_record['range'] = new_range
    new_record = {
        'type': 'NEW TYPE',
        'range': new_range,
        'data': {
            'key': 'val'
        }
    }
    assert not schedule.change_record(not_existed_record, new_record)

    assert 'data' in schedule.records[-1]
    assert schedule.records[-1]['data'] is None
示例#12
0
	def mutateSchedule(schedule):
		"""! randomly modifies a schedule and returns the changed version
			:param schedule: schedule to be mutated
			:type schedule: Schedule
			:return: modified schedule
			"""
		assert isinstance(schedule, Schedule)
		newSchedule = deepcopy(schedule)
		newSchedule.id = Schedule.getNextID()
		newSchedule.fitness = None
		assert isinstance(newSchedule, Schedule)

		for index, task in enumerate(newSchedule.tasks):
			if randint(0, 100) >= Mutator.percentageChange:
				continue
			Mutator.mutateTask(newSchedule.getTask(index))

		newSchedule.setCleanTime()
		return newSchedule
示例#13
0
def test_failed_add_to_schedule_range():
    start_datetime = datetime.datetime(year=2020, month=1, day=1)
    end_datetime = start_datetime + datetime.timedelta(hours=1)
    schedule = Schedule(start_datetime, duration=60)

    _range = DateTimeRange(start_datetime + datetime.timedelta(minutes=2),
                           start_datetime + datetime.timedelta(minutes=3))
    assert not schedule.add_record('Test_type', _range)
    assert len(schedule.records) == 0

    _range = DateTimeRange(start_datetime + datetime.timedelta(minutes=1),
                           start_datetime + datetime.timedelta(minutes=2))
    assert not schedule.add_record('Test_type', _range)
    assert len(schedule.records) == 0

    _range = DateTimeRange(start_datetime - datetime.timedelta(minutes=1),
                           start_datetime + datetime.timedelta(minutes=2))
    assert not schedule.add_record('Test_type', _range)
    assert len(schedule.records) == 0

    _range = DateTimeRange(start_datetime - datetime.timedelta(minutes=1),
                           start_datetime + datetime.timedelta(seconds=2))
    assert not schedule.add_record('Test_type', _range)
    assert len(schedule.records) == 0
示例#14
0
def test_get_ranges_without_duration():
    start_datetime = datetime.datetime(year=2020, month=1, day=1)
    end_datetime = start_datetime + datetime.timedelta(hours=1)
    schedule = Schedule(start_datetime, end_dt=end_datetime)

    assert [DateTimeRange(start_datetime,
                          end_datetime)] == schedule.get_free_ranges(3600)
    assert [] == schedule.get_free_ranges(7200)

    range_1 = DateTimeRange(start_datetime + datetime.timedelta(seconds=1),
                            start_datetime + datetime.timedelta(minutes=1))
    assert schedule.add_record('SOME TYPE', range_1)
    assert [] == schedule.get_free_ranges(7200)
    expected_free_ranges = \
        [
            DateTimeRange(start_datetime, range_1.start_datetime),
            DateTimeRange(range_1.end_datetime, end_datetime)
        ]
    assert expected_free_ranges == schedule.get_free_ranges()

    range_2 = DateTimeRange(start_datetime + datetime.timedelta(minutes=10),
                            start_datetime + datetime.timedelta(minutes=11))
    assert schedule.add_record('SOME TYPE', range_2)

    expected_free_ranges = \
        [
            DateTimeRange(start_datetime, range_1.start_datetime),
            DateTimeRange(range_1.end_datetime, range_2.start_datetime),
            DateTimeRange(range_2.end_datetime, end_datetime),
        ]
    assert expected_free_ranges == schedule.get_free_ranges()

    range_3 = DateTimeRange(start_datetime + datetime.timedelta(minutes=50),
                            end_datetime)
    assert schedule.add_record('SOME TYPE', range_3)

    expected_free_ranges = \
        [
            DateTimeRange(start_datetime, range_1.start_datetime),
            DateTimeRange(range_1.end_datetime, range_2.start_datetime),
            DateTimeRange(range_2.end_datetime, range_3.start_datetime),
        ]
    assert expected_free_ranges == schedule.get_free_ranges()