Ticket #12296: 0006-Watchlist-Add-Oldest-with-Limits-strategy.patch

File 0006-Watchlist-Add-Oldest-with-Limits-strategy.patch, 10.5 KB (added by Roger Siddons <dizygotheca@…>, 6 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() 
    32623262
    32633263    gc->setLabel(PlaybackSettings::tr("Sort method"));
    32643264    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."));
    32683272    return gc;
    32693273}
    32703274
    static HostSpinBox *PlaybackWLBlackOut() 
    33033307    return gs;
    33043308}
    33053309
     3310static 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
     3326static 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
    33063343WatchListStrategy::WatchListStrategy() :
    33073344    TriggeredConfigurationGroup(false, false, true, true)
    33083345{
    WatchListStrategy::WatchListStrategy() : 
    33163353     classic->addChild(PlaybackWLBlackOut());
    33173354
    33183355     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);
    33193363};
    33203364
    33213365WatchListSettings::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, 
    434434    int pbOrder        = gCoreContext->GetNumSetting("PlayBoxOrdering", 1);
    435435    // Split out sort order modes, wacky order for backward compatibility
    436436    m_listOrder = (pbOrder >> 1) ^ (m_allOrder = pbOrder & 1);
    437     m_watchListStart     = gCoreContext->GetNumSetting("PlaybackWLStart", 0);
     437    m_watchListStart      = gCoreContext->GetNumSetting("PlaybackWLStart", 0);
    438438
    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);
    442444    m_watchListStrategy   = gCoreContext->GetSetting("WatchListOrder", "Classic");
    443445
    444446    bool displayCat  = gCoreContext->GetNumSetting("DisplayRecGroupIsCategory", 0);
    void PlaybackBox::OrderByClassicStrategy(TitleMap& selections, ProgramOrder& ord 
    17801782    }
    17811783}
    17821784
     1785void 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
    17831873bool PlaybackBox::UpdateUILists(void)
    17841874{
    17851875    m_isFilling = true;
    bool PlaybackBox::UpdateUILists(void) 
    19732063                    else if (p->IsWatched())
    19742064                    {
    19752065                        LOG(VB_GUI, LOG_DEBUG,
    1976                             QString("Watchlist: Watched - %1 %2 (%3x%4)")
     2066                            QString("Watchlist: Watched  - %1 %2 (%3x%4)")
    19772067                            .arg(MythDate::toString(p->GetScheduledStartTime(),
    19782068                                                    Qt::ISODate))
    19792069                            .arg(p->GetTitle())
    bool PlaybackBox::UpdateUILists(void) 
    20102100                                watchEpisode[title] = p;
    20112101
    20122102                                LOG(VB_GUI, LOG_DEBUG,
    2013                                     QString("Watchlist: Replace - %1 %2 (%3x%4) "
     2103                                    QString("Watchlist: Replace  - %1 %2 (%3x%4) "
    20142104                                            "succeeding %5 (%6x%7)")
    20152105                                    .arg(MythDate::toString(p->GetScheduledStartTime(),
    20162106                                                            Qt::ISODate))
    bool PlaybackBox::UpdateUILists(void) 
    21182208
    21192209            OrderByClassicStrategy(watchEpisode, watchList);
    21202210
     2211        else if (m_watchListStrategy == "LimitedOldest")
     2212
     2213            OrderByOldestStrategy(watchEpisode, watchList);
     2214
    21212215        // populate watchlist group;
    21222216        // duplicate keys will appear in reverse alphabetic order
    21232217        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 
    267267    typedef QMap<QString, ProgramInfo*> TitleMap; // progs keyed by title
    268268
    269269    void OrderByClassicStrategy(TitleMap& selections, ProgramOrder &ordered);
     270    void OrderByOldestStrategy(TitleMap& selections, ProgramOrder &ordered);
    270271
    271272    bool UpdateUILists(void);
    272273    void UpdateUIGroupList(const QStringList &groupPreferences);
    class PlaybackBox : public ScheduleCommon 
    369370    int                 m_watchListMaxAge;
    370371    /// adjust exclusion of a title from the Watch List after a delete
    371372    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;
    372377    /// strategy for ordering the watchlist
    373378    QString             m_watchListStrategy;
    374379    /// allOrder controls the ordering of the "All Programs" list