Ticket #12296: 0006-Watchlist-Add-Oldest-with-Limits-strategy.patch
| File 0006-Watchlist-Add-Oldest-with-Limits-strategy.patch, 10.5 KB (added by , 12 years ago) |
|---|
-
mythtv/programs/mythfrontend/globalsettings.cpp
From 406927325e6c879f157bc10c63a18be82acf6e9c Mon Sep 17 00:00:00 2001 From: Roger Siddons <dizygotheca@ntlworld.com> Date: Tue, 7 Oct 2014 11:16:54 +0100 Subject: [PATCH 6/6] Watchlist: Add 'Oldest with Limits' strategy diff --git a/mythtv/programs/mythfrontend/globalsettings.cpp b/mythtv/programs/mythfrontend/globalsettings.cpp index 7818a9e..822327d 100644
a b static HostComboBox *PlaybackWLStrategy() 3262 3262 3263 3263 gc->setLabel(PlaybackSettings::tr("Sort method")); 3264 3264 gc->addSelection(PlaybackSettings::tr("Classic", "Watchlist"), "Classic"); 3265 gc->setHelpText(PlaybackSettings::tr("The watchlist ordering method. " 3266 "Classic keeps up-to-date with current " 3267 "TV.")); 3265 gc->addSelection(PlaybackSettings::tr( 3266 "Limited Oldest", "Watchlist"), "LimitedOldest"); 3267 gc->setHelpText(PlaybackSettings::tr( 3268 "The watchlist ordering method. 'Classic' keeps you " 3269 "up-to-date with current TV. 'Limited Oldest' shows " 3270 "oldest->newest whilst highlighting new or popular " 3271 "titles, and relegating ignored ones.")); 3268 3272 return gc; 3269 3273 } 3270 3274 … … static HostSpinBox *PlaybackWLBlackOut() 3303 3307 return gs; 3304 3308 } 3305 3309 3310 static HostSpinBox *PlaybackWLRecentLimit() 3311 { 3312 HostSpinBox *gs = new HostSpinBox("PlaybackWLRecentLimit", 0, 168, 6, true); 3313 3314 gs->setLabel(WatchListSettings::tr("Hours to keep at top")); 3315 3316 gs->setValue(6); 3317 3318 gs->setHelpText(WatchListSettings::tr( 3319 "Titles are promoted to the top if:- " 3320 "they are new titles younger than this interval, " 3321 "or they are watched (on average) within this interval. " 3322 "0 disables this behaviour.")); 3323 return gs; 3324 } 3325 3326 static HostSpinBox *PlaybackWLOldLimit() 3327 { 3328 HostSpinBox *gs = new HostSpinBox("PlaybackWLOldLimit", 7, 3650, 7, true); 3329 3330 gs->setLabel(WatchListSettings::tr("Days before relegating to bottom")); 3331 3332 gs->setValue(28); 3333 3334 gs->setHelpText(WatchListSettings::tr( 3335 "Titles are moved to the bottom when they:- " 3336 "are older than this interval, and " 3337 "have not been watched (on average) within this interval. " 3338 "Use a high value to reduce this behaviour.")); 3339 3340 return gs; 3341 } 3342 3306 3343 WatchListStrategy::WatchListStrategy() : 3307 3344 TriggeredConfigurationGroup(false, false, true, true) 3308 3345 { … … WatchListStrategy::WatchListStrategy() : 3316 3353 classic->addChild(PlaybackWLBlackOut()); 3317 3354 3318 3355 addTarget("Classic", classic); 3356 3357 ConfigurationGroup* oldest = new VerticalConfigurationGroup(false,false); 3358 3359 oldest->addChild(PlaybackWLRecentLimit()); 3360 oldest->addChild(PlaybackWLOldLimit()); 3361 3362 addTarget("LimitedOldest", oldest); 3319 3363 }; 3320 3364 3321 3365 WatchListSettings::WatchListSettings() : -
mythtv/programs/mythfrontend/playbackbox.cpp
diff --git a/mythtv/programs/mythfrontend/playbackbox.cpp b/mythtv/programs/mythfrontend/playbackbox.cpp index eff3d85..a7136d2 100644
a b PlaybackBox::PlaybackBox(MythScreenStack *parent, QString name, 434 434 int pbOrder = gCoreContext->GetNumSetting("PlayBoxOrdering", 1); 435 435 // Split out sort order modes, wacky order for backward compatibility 436 436 m_listOrder = (pbOrder >> 1) ^ (m_allOrder = pbOrder & 1); 437 m_watchListStart = gCoreContext->GetNumSetting("PlaybackWLStart", 0);437 m_watchListStart = gCoreContext->GetNumSetting("PlaybackWLStart", 0); 438 438 439 m_watchListAutoExpire= gCoreContext->GetNumSetting("PlaybackWLAutoExpire", 0); 440 m_watchListMaxAge = gCoreContext->GetNumSetting("PlaybackWLMaxAge", 60); 441 m_watchListBlackOut = gCoreContext->GetNumSetting("PlaybackWLBlackOut", 2); 439 m_watchListAutoExpire = gCoreContext->GetNumSetting("PlaybackWLAutoExpire", 0); 440 m_watchListMaxAge = gCoreContext->GetNumSetting("PlaybackWLMaxAge", 60); 441 m_watchListBlackOut = gCoreContext->GetNumSetting("PlaybackWLBlackOut", 2); 442 m_watchListRecentLimit= gCoreContext->GetNumSetting("PlaybackWLRecentLimit", 2); 443 m_watchListOldLimit = gCoreContext->GetNumSetting("PlaybackWLOldLimit", 30); 442 444 m_watchListStrategy = gCoreContext->GetSetting("WatchListOrder", "Classic"); 443 445 444 446 bool displayCat = gCoreContext->GetNumSetting("DisplayRecGroupIsCategory", 0); … … void PlaybackBox::OrderByClassicStrategy(TitleMap& selections, ProgramOrder& ord 1780 1782 } 1781 1783 } 1782 1784 1785 void PlaybackBox::OrderByOldestStrategy(TitleMap& selections, ProgramOrder& ordered) 1786 { 1787 QDateTime now = MythDate::current(); 1788 1789 QMap<int, int> avgDelay; 1790 QMap<int, QDateTime> lastDelete; 1791 1792 MSqlQuery query(MSqlQuery::InitCon()); 1793 query.prepare("SELECT recordid, avg_delay, last_delete FROM record;"); 1794 1795 if (query.exec()) 1796 { 1797 while (query.next()) 1798 { 1799 int recid = query.value(0).toInt(); 1800 avgDelay[recid] = query.value(1).toInt(); 1801 lastDelete[recid] = query.value(2).toDateTime(); 1802 } 1803 } 1804 1805 TitleMap::iterator it = selections.begin(); 1806 while (it != selections.end()) 1807 { 1808 ProgramInfo* p = it.value(); 1809 int recid = p->GetRecordingRuleID(); 1810 bool knownRule = avgDelay.contains(recid); 1811 1812 // use priority as primary key in top 32 bits: 1813 // 0 = bottom, 1 = middle, 2 = top 1814 // use age in secs as a secondary key in low 32 bits to ensure equal 1815 // scores are ordered oldest first. Copes with progs up to 136 yrs old 1816 score_type score = p->GetScheduledStartTime().secsTo(now); 1817 1818 // put new recordings or those from rules that are watched quickly, at the top 1819 int ageInHours = p->GetScheduledEndTime().secsTo(now) / 3600; 1820 if (ageInHours <= m_watchListRecentLimit 1821 || (knownRule && avgDelay[recid] <= m_watchListRecentLimit)) 1822 { 1823 score |= 0x0200000000; 1824 1825 LOG(VB_GUI, LOG_DEBUG, 1826 QString("Watchlist: Top: %1 - '%2' was recorded %3 hrs " 1827 "ago & being watched after %4 hrs") 1828 .arg(score, 11) 1829 .arg(p->GetTitle()) 1830 .arg(ageInHours) 1831 .arg(avgDelay[recid])); 1832 } 1833 // recordings go to middle if not yet old enough 1834 else if (ageInHours / 24 <= m_watchListOldLimit) 1835 { 1836 score |= 0x0100000000; 1837 1838 LOG(VB_GUI, LOG_DEBUG, 1839 QString("Watchlist: Middle:%1 - '%2' was recorded %3 hrs ago") 1840 .arg(score, 11) 1841 .arg(p->GetTitle()) 1842 .arg(ageInHours)); 1843 } 1844 // or a previous episode for the rule was deleted recently 1845 else if (knownRule) 1846 { 1847 QDateTime deleted = MythDate::as_utc(lastDelete[recid]); 1848 if (deleted.isValid() 1849 && deleted.secsTo(now) / 3600 / 24 <= m_watchListOldLimit) 1850 { 1851 score |= 0x0100000000; 1852 1853 LOG(VB_GUI, LOG_DEBUG, 1854 QString("Watchlist: Middle:%1 - '%2' was watched %3 days ago") 1855 .arg(score, 11) 1856 .arg(p->GetTitle()) 1857 .arg(deleted.secsTo(now) / 3600 / 24)); 1858 } 1859 } 1860 else 1861 LOG(VB_GUI, LOG_DEBUG, 1862 QString("Watchlist: Bottom:%1 - '%2' is %3 hrs old") 1863 .arg(score, 11) 1864 .arg(p->GetTitle()) 1865 .arg(ageInHours)); 1866 1867 ordered.insert(score, p); 1868 1869 ++it; 1870 } 1871 } 1872 1783 1873 bool PlaybackBox::UpdateUILists(void) 1784 1874 { 1785 1875 m_isFilling = true; … … bool PlaybackBox::UpdateUILists(void) 1973 2063 else if (p->IsWatched()) 1974 2064 { 1975 2065 LOG(VB_GUI, LOG_DEBUG, 1976 QString("Watchlist: Watched - %1 %2 (%3x%4)")2066 QString("Watchlist: Watched - %1 %2 (%3x%4)") 1977 2067 .arg(MythDate::toString(p->GetScheduledStartTime(), 1978 2068 Qt::ISODate)) 1979 2069 .arg(p->GetTitle()) … … bool PlaybackBox::UpdateUILists(void) 2010 2100 watchEpisode[title] = p; 2011 2101 2012 2102 LOG(VB_GUI, LOG_DEBUG, 2013 QString("Watchlist: Replace - %1 %2 (%3x%4) "2103 QString("Watchlist: Replace - %1 %2 (%3x%4) " 2014 2104 "succeeding %5 (%6x%7)") 2015 2105 .arg(MythDate::toString(p->GetScheduledStartTime(), 2016 2106 Qt::ISODate)) … … bool PlaybackBox::UpdateUILists(void) 2118 2208 2119 2209 OrderByClassicStrategy(watchEpisode, watchList); 2120 2210 2211 else if (m_watchListStrategy == "LimitedOldest") 2212 2213 OrderByOldestStrategy(watchEpisode, watchList); 2214 2121 2215 // populate watchlist group; 2122 2216 // duplicate keys will appear in reverse alphabetic order 2123 2217 foreach (ProgramInfo* wp, watchList) -
mythtv/programs/mythfrontend/playbackbox.h
diff --git a/mythtv/programs/mythfrontend/playbackbox.h b/mythtv/programs/mythfrontend/playbackbox.h index 1266509..b1b5844 100644
a b class PlaybackBox : public ScheduleCommon 267 267 typedef QMap<QString, ProgramInfo*> TitleMap; // progs keyed by title 268 268 269 269 void OrderByClassicStrategy(TitleMap& selections, ProgramOrder &ordered); 270 void OrderByOldestStrategy(TitleMap& selections, ProgramOrder &ordered); 270 271 271 272 bool UpdateUILists(void); 272 273 void UpdateUIGroupList(const QStringList &groupPreferences); … … class PlaybackBox : public ScheduleCommon 369 370 int m_watchListMaxAge; 370 371 /// adjust exclusion of a title from the Watch List after a delete 371 372 int m_watchListBlackOut; 373 /// recordings younger than this (hrs) go to the top 374 int m_watchListRecentLimit; 375 /// recordings older than this got to the bottom 376 int m_watchListOldLimit; 372 377 /// strategy for ordering the watchlist 373 378 QString m_watchListStrategy; 374 379 /// allOrder controls the ordering of the "All Programs" list
