コード例 #1
0
ファイル: routes.py プロジェクト: simonsan/GardenPi
def powerschedulejob2(id):
    zone2_with_conflict = ''
    job2_with_conflict = ''
    zone = f'power{id}'
    log.debug(f'powerschedulejob2() called with powerzone: {zone}')
    form = PowerJob2Form()
    job2_jobid = (neptune.get_schedule_by_zone_job(zone, '2')[0][0])
    job2_enabled = (neptune.get_schedule_by_zone_job(zone, '2')[0][3])
    job2_start_time = (neptune.get_schedule_by_zone_job(zone, '2')[0][4])
    job2_duration = (neptune.get_schedule_by_zone_job(zone, '2')[0][6])
    job2_monday = (neptune.get_schedule_by_zone_job(zone, '2')[0][8])
    job2_tuesday = (neptune.get_schedule_by_zone_job(zone, '2')[0][9])
    job2_wednesday = (neptune.get_schedule_by_zone_job(zone, '2')[0][10])
    job2_thursday = (neptune.get_schedule_by_zone_job(zone, '2')[0][11])
    job2_friday = (neptune.get_schedule_by_zone_job(zone, '2')[0][12])
    job2_saturday = (neptune.get_schedule_by_zone_job(zone, '2')[0][13])
    job2_sunday = (neptune.get_schedule_by_zone_job(zone, '2')[0][14])
    form.start_hour_job2.data = str(job2_start_time.hour)
    form.start_minute_job2.data = str(job2_start_time.minute)
    form.duration_job2.data = str(job2_duration)
    form.monday_job2.data = job2_monday
    form.tuesday_job2.data = job2_tuesday
    form.wednesday_job2.data = job2_wednesday
    form.thursday_job2.data = job2_thursday
    form.friday_job2.data = job2_friday
    form.saturday_job2.data = job2_saturday
    form.sunday_job2.data = job2_sunday

    if form.validate_on_submit():
        # Uodate job start/stop times and duration based on form input
        job2_new_start_hour = request.form['start_hour_job2']
        job2_new_start_minute = request.form['start_minute_job2']
        job2_new_start_time = datetime.strptime(
            job2_new_start_hour + ':' + job2_new_start_minute + ':00',
            '%H:%M:%S').time()
        job2_new_duration = int(request.form['duration_job2'])
        job2_delta = timedelta(minutes=job2_new_duration)
        job2_new_stoptime = (
            (datetime.combine(date(1, 1, 1), job2_new_start_time) +
             job2_delta).time())

        jobs2 = [('monday_job2', 2, 'monday'), ('tuesday_job2', 2, 'tuesday'),
                 ('wednesday_job2', 2, 'wednesday'),
                 ('thursday_job2', 2, 'thursday'), ('friday_job2', 2,
                                                    'friday'),
                 ('saturday_job2', 2, 'saturday'),
                 ('sunday_job2', 2, 'sunday')]

        #Update selected days of week based on job
        for job in jobs2:
            jobfield = job[0]
            jobnumber = job[1]
            dayofjob = job[2]
            value = bool(request.form.get(jobfield, False))
            neptune.update_day(zone, jobnumber, dayofjob, value)

        # Verify power jobs for this power outlet do not overlap each other.
        job2_time_conflict = sa_check_power_zone_times_conflict(
            zone, job2_new_start_time, job2_new_stoptime, job2_jobid)
        if job2_time_conflict:
            #zone2_with_conflict = sa_check_zone_times_jobid(job2_new_start_time, job2_new_stoptime)[0][1]
            #job2_with_conflict = sa_check_zone_times_jobid(job2_new_start_time, job2_new_stoptime)[0][2]
            flash(f'Schedule Conflict with - Job: 1', 'error')
            return render_template('powerschedule2_error.html', id=id)
        else:
            flash("Schedule Updated", "success")
            neptune.update_job_start_time(zone, '2', job2_new_start_time)
            neptune.update_job_stop_time(zone, '2', job2_new_stoptime)
            neptune.update_job_duration(zone, '2', job2_new_duration)

        return redirect(url_for('powerschedulejob2', id=id))

    else:
        print("Validation Failed")
        print(form.errors)
    return render_template('powerschedulejob2.html',
                           form=form,
                           job2_enabled=job2_enabled,
                           id=id)
コード例 #2
0
ファイル: routes.py プロジェクト: simonsan/GardenPi
def schedulejob1(id):
    zone1_with_conflict = ''
    job1_with_conflict = ''
    zone = f'zone{id}'
    log.debug(f'schedulejob1() called with zone: {zone}')
    form = Job1Form()
    job1_jobid = (neptune.get_schedule_by_zone_job(zone, '1')[0][0])
    job1_enabled = (neptune.get_schedule_by_zone_job(zone, '1')[0][3])
    job1_start_time = (neptune.get_schedule_by_zone_job(zone, '1')[0][4])
    job1_duration = (neptune.get_schedule_by_zone_job(zone, '1')[0][6])
    job1_monday = (neptune.get_schedule_by_zone_job(zone, '1')[0][8])
    job1_tuesday = (neptune.get_schedule_by_zone_job(zone, '1')[0][9])
    job1_wednesday = (neptune.get_schedule_by_zone_job(zone, '1')[0][10])
    job1_thursday = (neptune.get_schedule_by_zone_job(zone, '1')[0][11])
    job1_friday = (neptune.get_schedule_by_zone_job(zone, '1')[0][12])
    job1_saturday = (neptune.get_schedule_by_zone_job(zone, '1')[0][13])
    job1_sunday = (neptune.get_schedule_by_zone_job(zone, '1')[0][14])
    form.start_hour_job1.data = str(job1_start_time.hour)
    form.start_minute_job1.data = str(job1_start_time.minute)
    form.duration_job1.data = str(job1_duration)
    form.monday_job1.data = job1_monday
    form.tuesday_job1.data = job1_tuesday
    form.wednesday_job1.data = job1_wednesday
    form.thursday_job1.data = job1_thursday
    form.friday_job1.data = job1_friday
    form.saturday_job1.data = job1_saturday
    form.sunday_job1.data = job1_sunday

    if form.validate_on_submit():
        # Uodate job start/stop times and duration based on form input
        job1_new_start_hour = request.form['start_hour_job1']
        job1_new_start_minute = request.form['start_minute_job1']
        job1_new_start_time = datetime.strptime(
            job1_new_start_hour + ':' + job1_new_start_minute + ':00',
            '%H:%M:%S').time()
        job1_new_duration = int(request.form['duration_job1'])
        job1_delta = timedelta(minutes=job1_new_duration)
        job1_new_stoptime = (
            (datetime.combine(date(1, 1, 1), job1_new_start_time) +
             job1_delta).time())

        jobs1 = [('monday_job1', 1, 'monday'), ('tuesday_job1', 1, 'tuesday'),
                 ('wednesday_job1', 1, 'wednesday'),
                 ('thursday_job1', 1, 'thursday'), ('friday_job1', 1,
                                                    'friday'),
                 ('saturday_job1', 1, 'saturday'),
                 ('sunday_job1', 1, 'sunday')]

        #Update selected days of week based on job
        for job in jobs1:
            jobfield = job[0]
            jobnumber = job[1]
            dayofjob = job[2]
            value = bool(request.form.get(jobfield, False))
            neptune.update_day(zone, jobnumber, dayofjob, value)

        # Since we can only run one zone at a time, verify here that there are no conflicting jobs.
        job1_time_conflict = sa_check_zone_times_conflict(
            job1_new_start_time, job1_new_stoptime, job1_jobid)
        if job1_time_conflict:
            zone1_with_conflict = sa_check_zone_times_jobid(
                job1_new_start_time, job1_new_stoptime)[0][1]
            job1_with_conflict = sa_check_zone_times_jobid(
                job1_new_start_time, job1_new_stoptime)[0][2]
            flash(
                f'Schedule Conflict with {zone1_with_conflict} - Job: {job1_with_conflict}',
                'error')
            return render_template('schedule1_error.html', id=id)
        else:
            flash("Schedule Updated", "success")
            neptune.update_job_start_time(zone, '1', job1_new_start_time)
            neptune.update_job_stop_time(zone, '1', job1_new_stoptime)
            neptune.update_job_duration(zone, '1', job1_new_duration)
        return redirect(url_for('schedulejob1', id=id))

    else:
        print("Page Refresh")
        print(form.errors)
    return render_template('schedulejob1.html',
                           form=form,
                           job1_enabled=job1_enabled,
                           id=id)