From 671046fbeae778b7db1ee18034c32a1b10cdd407 Mon Sep 17 00:00:00 2001 From: randomdan Date: Sun, 19 Jan 2014 21:11:16 +0000 Subject: Minor fixes to scheduling --- p2pvr/lib/schedules.cpp | 4 ++-- p2pvr/lib/sql/Schedules_GetCandidates.sql | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/p2pvr/lib/schedules.cpp b/p2pvr/lib/schedules.cpp index bca7ddd..d13b231 100644 --- a/p2pvr/lib/schedules.cpp +++ b/p2pvr/lib/schedules.cpp @@ -240,7 +240,7 @@ class SumTimeToStart { inline void operator()(const ShowingPtr & s) const { if (s) { - total += (now - s->startTime).seconds(); + total += std::min((now - s->startTime).seconds(), 0); } } public: @@ -263,7 +263,7 @@ EpisodeGroup::Suggest(const Showings & showings) if (c >= score) { time_t stt; std::for_each(showings.begin(), showings.end(), SumTimeToStart(stt)); - if (stt < sumTimeToStart) { + if (stt < sumTimeToStart || (stt == sumTimeToStart && c > score)) { if (IsShowingListValid(showings)) { selected = showings; score = c; diff --git a/p2pvr/lib/sql/Schedules_GetCandidates.sql b/p2pvr/lib/sql/Schedules_GetCandidates.sql index f7ad997..8e8b15e 100644 --- a/p2pvr/lib/sql/Schedules_GetCandidates.sql +++ b/p2pvr/lib/sql/Schedules_GetCandidates.sql @@ -12,7 +12,7 @@ from ( and (s.eventid is null or s.eventid = e.eventid) and (s.search is null or event_tsvector(e) @@ plainto_tsquery(s.search)) and sv.serviceid = e.serviceid - and e.starttime > now() + and e.stoptime > now() and not exists ( select 1 from recorded r -- cgit v1.2.3