1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-13 17:43:59 +02:00

Move score-keeping from Result to Query.

This commit is contained in:
Christian Muehlhaeuser
2015-04-03 17:20:12 +02:00
parent b265af268a
commit c1d9bd6244
4 changed files with 27 additions and 33 deletions

View File

@@ -151,6 +151,7 @@ Query::init()
d->solved = false;
d->playable = false;
d->saveResultHint = false;
d->score = 0.0;
}
@@ -196,7 +197,7 @@ Query::addResults( const QList< Tomahawk::result_ptr >& newresults )
}*/
d->results << newresults;
qStableSort( d->results.begin(), d->results.end(), Query::resultSorter );
qStableSort( d->results.begin(), d->results.end(), std::bind( &Query::resultSorter, this, std::placeholders::_1, std::placeholders::_2 ) );
// hook up signals, and check solved status
foreach( const result_ptr& rp, newresults )
@@ -265,8 +266,8 @@ Query::onResultStatusChanged()
{
Q_D( Query );
QMutexLocker lock( &d->mutex );
if ( d->results.count() )
qStableSort( d->results.begin(), d->results.end(), Query::resultSorter );
if ( !d->results.isEmpty() )
qStableSort( d->results.begin(), d->results.end(), std::bind( &Query::resultSorter, this, std::placeholders::_1, std::placeholders::_2 ) );
}
checkResults();
@@ -404,8 +405,8 @@ Query::id() const
bool
Query::resultSorter( const result_ptr& left, const result_ptr& right )
{
const float ls = left->isOnline() ? left->score() : 0.0;
const float rs = right->isOnline() ? right->score() : 0.0;
const float ls = left->isOnline() ? howSimilar( left ) : 0.0;
const float rs = right->isOnline() ? howSimilar( right ) : 0.0;
if ( ls == rs )
{
@@ -509,6 +510,10 @@ void
Query::checkResults()
{
Q_D( Query );
if ( !d->results.isEmpty() )
{
d->score = howSimilar( d->results.first() );
}
bool playable = false;
bool solved = false;
@@ -521,7 +526,7 @@ Query::checkResults()
if ( rp->playable() )
playable = true;
if ( rp->isOnline() && rp->score() > 0.99 )
if ( rp->isOnline() && howSimilar( rp ) > 0.99 )
{
solved = true;
}
@@ -602,6 +607,14 @@ Query::toString() const
}
float
Query::score() const
{
Q_D( const Query );
return d->score;
}
// TODO make clever (ft. featuring live (stuff) etc)
float
Query::howSimilar( const Tomahawk::result_ptr& r )
@@ -716,4 +729,3 @@ Query::setWeakRef( QWeakPointer<Query> weakRef )
Q_D( Query );
d->ownRef = weakRef;
}

View File

@@ -79,6 +79,9 @@ public:
/// true when any result has been found (score may be less than 1.0)
bool playable() const;
float score() const;
void setScore( float score );
Tomahawk::Resolver* currentResolver() const;
QList< QPointer< Tomahawk::Resolver > > resolvedBy() const;
@@ -109,7 +112,7 @@ public:
void setWeakRef( QWeakPointer< Tomahawk::Query > weakRef );
/// sorter for list of results
static bool resultSorter( const result_ptr& left, const result_ptr& right );
bool resultSorter( const result_ptr& left, const result_ptr& right );
signals:
void resultsAdded( const QList<Tomahawk::result_ptr>& );

View File

@@ -102,7 +102,6 @@ Result::Result( const QString& url, const track_ptr& track )
, m_bitrate( 0 )
, m_size( 0 )
, m_modtime( 0 )
, m_score( 0 )
, m_fileId( 0 )
, m_track( track )
{
@@ -169,13 +168,6 @@ Result::mimetype() const
}
float
Result::score() const
{
return m_score;
}
RID
Result::id() const
{
@@ -209,7 +201,7 @@ Result::playable() const
}
else
{
return score() > 0.0;
return true; //FIXME
}
}
@@ -226,7 +218,7 @@ Result::toVariant() const
m.insert( "size", size() );
m.insert( "bitrate", bitrate() );
m.insert( "duration", m_track->duration() );
m.insert( "score", score() );
// m.insert( "score", score() );
m.insert( "sid", id() );
m.insert( "discnumber", m_track->discnumber() );
m.insert( "albumpos", m_track->albumpos() );
@@ -243,9 +235,8 @@ Result::toString() const
{
if ( m_track )
{
return QString( "Result(%1, score: %2) %3 - %4%5 (%6)" )
return QString( "Result(%1) %2 - %3%4 (%5)" )
.arg( id() )
.arg( m_score )
.arg( m_track->artist() )
.arg( m_track->track() )
.arg( m_track->album().isEmpty() ? QString() : QString( " on %1" ).arg( m_track->album() ) )
@@ -253,9 +244,8 @@ Result::toString() const
}
else
{
return QString( "Result(%1, score: %2) (%3)" )
return QString( "Result(%1) (%2)" )
.arg( id() )
.arg( m_score )
.arg( m_url );
}
}
@@ -478,13 +468,6 @@ Result::modificationTime() const
}
void
Result::setScore( float score )
{
m_score = score;
}
void
Result::setFileId( unsigned int id )
{

View File

@@ -89,7 +89,6 @@ public:
*/
ResultProvider* resolvedBy() const;
float score() const;
RID id() const;
bool isOnline() const;
bool playable() const;
@@ -112,7 +111,6 @@ public:
unsigned int size() const;
unsigned int modificationTime() const;
void setScore( float score );
void setFileId( unsigned int id );
void setRID( RID id ) { m_rid = id; }
@@ -174,8 +172,6 @@ private:
unsigned int m_bitrate;
unsigned int m_size;
unsigned int m_modtime;
float m_score;
unsigned int m_fileId;
track_ptr m_track;