Fix some bugs in the creation of the start/stop timers

This commit is contained in:
jrlambs 2017-04-07 23:55:50 -04:00
parent 2b21bf05cf
commit 763d455aa3
2 changed files with 42 additions and 20 deletions

View File

@ -34,6 +34,7 @@ import com.moparisthebest.rcrdit.tuner.Tuners;
import com.moparisthebest.rcrdit.xmltv.Channel; import com.moparisthebest.rcrdit.xmltv.Channel;
import com.moparisthebest.rcrdit.xmltv.Program; import com.moparisthebest.rcrdit.xmltv.Program;
import com.moparisthebest.rcrdit.xmltv.Tv; import com.moparisthebest.rcrdit.xmltv.Tv;
import jersey.repackaged.com.google.common.collect.Lists;
import net.fortuna.ical4j.data.CalendarOutputter; import net.fortuna.ical4j.data.CalendarOutputter;
import net.fortuna.ical4j.model.Calendar; import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.DateTime; import net.fortuna.ical4j.model.DateTime;
@ -85,7 +86,7 @@ import org.glassfish.jersey.jackson.JacksonFeature;
public class RcrdIt extends ResourceConfig implements AutoCloseable { public class RcrdIt extends ResourceConfig implements AutoCloseable {
// for testing, should be null normally // for testing, should be null normally
private static final LocalDateTime fakeTime = null;//LocalDateTime.of(2017, 3, 11, 0, 0); private static final LocalDateTime fakeTime = LocalDateTime.of(2017, 4, 6, 22, 31);
private static final Logger log = LoggerFactory.getLogger(RcrdIt.class); private static final Logger log = LoggerFactory.getLogger(RcrdIt.class);
@ -426,7 +427,9 @@ public class RcrdIt extends ResourceConfig implements AutoCloseable {
final Program program = schedule.getPrograms().get(x); final Program program = schedule.getPrograms().get(x);
if(program.getAutoRec() != null) { if(program.getAutoRec() != null) {
// wanted to record // wanted to record
final List<StartStop> startStops = program.getStartStops(); final List<StartStop> startStops = program.getStartStops();
if(startStops.isEmpty()) { if(startStops.isEmpty()) {
// whole thing skipped... // whole thing skipped...
addMeeting(calendar, tz, program.getStart(), program.getStop(), program, md, true); addMeeting(calendar, tz, program.getStart(), program.getStop(), program, md, true);
@ -441,16 +444,23 @@ public class RcrdIt extends ResourceConfig implements AutoCloseable {
final StartStop second = startStops.get(++index); final StartStop second = startStops.get(++index);
if(startStops.size() == 2 && first.getInstant().equals(program.getStart()) && second.getInstant().equals(program.getStop())) { if(startStops.size() == 2 && first.getInstant().equals(program.getStart()) && second.getInstant().equals(program.getStop())) {
// whole thing recorded... // whole thing recorded...
Program toStop = first.getToStop();
addMeeting(calendar, tz, program.getStart(), program.getStop(), program, md, false); addMeeting(calendar, tz, program.getStart(), program.getStop(), program, md, false);
final RecordingTask rt = new RecordingTask(program, program.getStart()); RecordingTask rt = null;
if(toStop != null){
rt = new RecordingTask(toStop, program, program.getStart());
}else {
rt = new RecordingTask(program, program.getStart());
}
startTimers.add(rt); startTimers.add(rt);
continue; continue;
} }
if(first.isStart()) { if(first.isStart()) {
if(first.getInstant().equals(program.getStart())) { //Travis, uncomment me if I'm still needed
//if(first.getInstant().equals(program.getStart())) {
// not started at start time, skipped first part of program // not started at start time, skipped first part of program
addMeeting(calendar, tz, program.getStart(), first.getInstant(), program, md, true); //addMeeting(calendar, tz, program.getStart(), first.getInstant(), program, md, true);
} //}
Program toStop = null; Program toStop = null;
Instant start = null, stop = null, lastStop = null; Instant start = null, stop = null, lastStop = null;
for(final StartStop ss : program.getStartStops()) { for(final StartStop ss : program.getStartStops()) {
@ -473,6 +483,17 @@ public class RcrdIt extends ResourceConfig implements AutoCloseable {
start = stop = null; start = stop = null;
} }
} }
if(lastStop != null) { // todo: check if lastStop and start are the same, but shouldn't happen?
addMeeting(calendar, tz, lastStop, start, program, md, true);
}
if(start != null && stop != null) {
addMeeting(calendar, tz, start, stop, program, md, false);
final RecordingTask rt = new RecordingTask(toStop, program, start);
startTimers.add(rt);
}
} else { } else {
log.error("holy shit should never happen, bad scheduler?"); log.error("holy shit should never happen, bad scheduler?");
throw new RuntimeException("holy shit should never happen, bad scheduler?"); throw new RuntimeException("holy shit should never happen, bad scheduler?");
@ -483,7 +504,8 @@ public class RcrdIt extends ResourceConfig implements AutoCloseable {
log.debug("new import done.\n\n------\n\n"); log.debug("new import done.\n\n------\n\n");
try (FileOutputStream fout = new FileOutputStream("startTimers.txt")) { try (FileOutputStream fout = new FileOutputStream("startTimers.txt")) {
for(TimerTask tt : startTimers) { List<TimerTask> tmpTimers = Lists.reverse(startTimers);
for(TimerTask tt : tmpTimers) {
fout.write(tt.toString().getBytes(UTF_8)); fout.write(tt.toString().getBytes(UTF_8));
fout.write('\n'); fout.write('\n');
} }

View File

@ -64,17 +64,13 @@ public class PartialScheduler implements Scheduler {
} }
} }
// schedule top 2 (numTuners), record stuff about rest, schedule only if not already recording ouch? // schedule top 2 (numTuners), record stuff about rest, schedule only if not already recording ouch?
if (!programAutoRecs.isEmpty()) {
programAutoRecs.sort(Program::compareTo);
// start and stop are same minute and second
final Instant finalCursor = cursor;
// it already ended, and stopped itself, just remove it, for both currentRecs and skippedRecs // it already ended, and stopped itself, just remove it, for both currentRecs and skippedRecs
//recs.keySet().removeIf(c -> c.getProgram().getStop().isBefore(finalCursor)); //recs.keySet().removeIf(c -> c.getProgram().getStop().isBefore(finalCursor));
for (final Iterator<Map.Entry<Program, Instant>> it = currentRecs.entrySet().iterator(); it.hasNext(); ) { for (final Iterator<Map.Entry<Program, Instant>> it = currentRecs.entrySet().iterator(); it.hasNext(); ) {
final Map.Entry<Program, Instant> entry = it.next(); final Map.Entry<Program, Instant> entry = it.next();
final Program prog = entry.getKey(); final Program prog = entry.getKey();
if (!prog.getStop().isAfter(finalCursor)) { if (!prog.getStop().isAfter(cursor)) {
//if(prog.getStop().isBefore(finalCursor)) { //if(prog.getStop().isBefore(finalCursor)) {
final Instant start = entry.getValue(); final Instant start = entry.getValue();
prog.addStartStop(new StartStop(prog.getStop(), false)); prog.addStartStop(new StartStop(prog.getStop(), false));
@ -82,6 +78,10 @@ public class PartialScheduler implements Scheduler {
} }
} }
if (!programAutoRecs.isEmpty()) {
programAutoRecs.sort(Program::compareTo);
final Instant finalCursor = cursor;
// look at highest programAutoRecs up to the number of tuners // look at highest programAutoRecs up to the number of tuners
for (int x = 0; x < Math.min(programAutoRecs.size(), numTuners); ++x) { for (int x = 0; x < Math.min(programAutoRecs.size(), numTuners); ++x) {
final Program programAutoRec = programAutoRecs.get(x); final Program programAutoRec = programAutoRecs.get(x);