Question about ratings with TrackStat

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Roland0
    Senior Member
    • Aug 2012
    • 1343

    Question about ratings with TrackStat

    I'm writing a plugin which changes ratings of tracks. While looking at the implementation in Slim::Schema, I noticed that it's possible to use a different ratings implementation than the one provided as a default. Since TrackStat is the only plugin I'm aware of which might do such a thing, I had a look at it's source. I noticed that, while it doesn't actually provide a different ratings implementation, it still seems to change the standard logic. At startup, this SQL statement is executed:
    Code:
    UPDATE tracks_persistent set rating=(select track_statistics.rating from track_statistics where tracks_persistent.urlmd5=track_statistics.urlmd5 and track_statistics.rating>0 and (tracks_persistent.rating!=track_statistics.rating or tracks_persistent.rating is null)) where exists (select track_statistics.rating from track_statistics where tracks_persistent.urlmd5=track_statistics.urlmd5 and track_statistics.rating>0 and (tracks_persistent.rating!=track_statistics.rating or tracks_persistent.rating is null
    which means that if I use the standard LMS rating method (Slim::Schema->rating), which only updates tracks_persistent, the changes will be overwritten if there is also a rating in track_statistic.

    So the first question is: Is this analysis correct (I can't really test it since I have no license for TrackStat) ?

    If yes, that would be my approach to handle the situation depending on TrackStat being installed or not (the "setratingpercent" seems to update both persistent and statistics):
    Code:
    	my $hasTS = ($client->execute(["can","trackstat","setratingpercent","?"])->getResults())->{'_can'};
    	my @trackRS = Slim::Schema->rs('Track')->search( {'me.id' => \@$trackids } );
    	if(@trackRS) {
    		foreach (@trackRS) {
    			$log->debug("rate track " . $_->get_column("title") . " rating $rating");
    			if ($hasTS) {
    				$log->debug("using TrackStat to set rating");
    				$client->execute(["trackstat","setratingpercent",$_->get_column("id"),$rating]);
    			} else {
    				$log->debug("using Schema::rating to set rating");
    				Slim::Schema->rating( $_, $rating );
    			}
    		}
    	}
    Is this a valid approach? I'd be grateful if anyone familiar with the matter (Erland maybe ;-) could comment..

    ----
    Roland
    Various SW: Web Interface | Text Interface | Playlist Editor / Generator | Music Classification | Similar Music | Announce | EventTrigger | Ambient Noise Mixer | DB Optimizer | Image Enhancer | Chiptunes | LMSlib2go | ...
    Various HowTos: build a self-contained LMS | Bluetooth/ALSA | Control LMS with any device | ...
  • erland
    Senior Member
    • Jan 2006
    • 11323

    #2
    Originally posted by Roland0
    which means that if I use the standard LMS rating method (Slim::Schema->rating), which only updates tracks_persistent, the changes will be overwritten if there is also a rating in track_statistic.

    So the first question is: Is this analysis correct (I can't really test it since I have no license for TrackStat) ?
    I haven't tested it but I'm pretty sure you are correct in your assumption. If I remember correctly, the reason TrackStat overwrites standard ratings is because if your file have RATING tags the standard scanner will overwrite the content in the database with the content in the RATING tag during scanning and this could result in that ratings in TrackStat tables isn't in sync with LMS tables. This might probably be a good idea to be aware of in your plugin if you are using tracks_persistent table as your primary storage place for ratings, tracks_persistent.rating can be overwritten with older information during a rescan.

    You can use this functionality without a license to TrackStat, rating single songs in TrackStat works without a license, it's the browsing, dynamic playlists and import/export modules that requires a license.

    Originally posted by Roland0
    If yes, that would be my approach to handle the situation depending on TrackStat being installed or not (the "setratingpercent" seems to update both persistent and statistics):
    Code:
    	my $hasTS = ($client->execute(["can","trackstat","setratingpercent","?"])->getResults())->{'_can'};
    	my @trackRS = Slim::Schema->rs('Track')->search( {'me.id' => \@$trackids } );
    	if(@trackRS) {
    		foreach (@trackRS) {
    			$log->debug("rate track " . $_->get_column("title") . " rating $rating");
    			if ($hasTS) {
    				$log->debug("using TrackStat to set rating");
    				$client->execute(["trackstat","setratingpercent",$_->get_column("id"),$rating]);
    			} else {
    				$log->debug("using Schema::rating to set rating");
    				Slim::Schema->rating( $_, $rating );
    			}
    		}
    	}
    Is this a valid approach? I'd be grateful if anyone familiar with the matter (Erland maybe ;-) could comment..
    I haven't verified your code, but from a quick look I think the principle should work.
    Erland Lindmark (My homepage)
    Developer of many plugins/applets
    Starting with LMS 8.0 I no longer support my plugins/applets (see here for more information )

    Comment

    • Roland0
      Senior Member
      • Aug 2012
      • 1343

      #3
      Originally posted by erland
      I haven't tested it but I'm pretty sure you are correct in your assumption. If I remember correctly, the reason TrackStat overwrites standard ratings is because if your file have RATING tags the standard scanner will overwrite the content in the database with the content in the RATING tag during scanning and this could result in that ratings in TrackStat tables isn't in sync with LMS tables. This might probably be a good idea to be aware of in your plugin if you are using tracks_persistent table as your primary storage place for ratings, tracks_persistent.rating can be overwritten with older information during a rescan.

      You can use this functionality without a license to TrackStat, rating single songs in TrackStat works without a license, it's the browsing, dynamic playlists and import/export modules that requires a license.


      I haven't verified your code, but from a quick look I think the principle should work.
      Thanks for the quick reply. Since my plugin only lets the user rate tracks interactively using a GUI (similar to the standard web interface), I think it's fine if it mimics the 'standard' way this is handled in LMS (the build-in 'rating' cli command also only calls Track->rating())
      Various SW: Web Interface | Text Interface | Playlist Editor / Generator | Music Classification | Similar Music | Announce | EventTrigger | Ambient Noise Mixer | DB Optimizer | Image Enhancer | Chiptunes | LMSlib2go | ...
      Various HowTos: build a self-contained LMS | Bluetooth/ALSA | Control LMS with any device | ...

      Comment

      Working...