extragear/multimedia/amarok/src/scripts/score2rating

Peter C. Ndikuwera pndiku at gmail.com
Thu Jul 27 11:17:21 UTC 2006


Works fine on PgSQL.

Small nit-pick:
The queries seem to overlap, e.g.
    UPDATE statistics SET rating='2'
         WHERE percentage >= '10' AND percentage <= '30' AND rating < '2'
and:
   UPDATE statistics SET rating='3'
         WHERE percentage >= '30' AND percentage <= '45' AND rating < '3'

If I have a track with percentage = "30", it will be updated twice. :-)

Not important surely. Just a nitpick.


On 7/27/06, Jocke Andersson <ajocke at gmail.com> wrote:
> SVN commit 566783 by firetech:
>
> Ok, I'm stupid. Why the HELL didn't I do the conversions this way earlier, it's about 500 times faster (seriosly!)
> Anyway, here is Score2Rating v3.0, which is TOTALLY immune to strange file names, because it doesn't care about
> them. Can someone with PgSQL try this before I upload it to kde-apps? I've tested with MySQL and SQLite, so no need
> for that.
>
>
>  M  +1 -9      README
>  M  +45 -66    score2rating.rb
>
>
> --- trunk/extragear/multimedia/amarok/src/scripts/score2rating/README #566782:566783
> @@ -1,4 +1,4 @@
> -<div align="center"><b>Score2Rating (v2.5)</b></div>
> +<div align="center"><b>Score2Rating (v3.0)</b></div>
>
>  <p>
>  <b>About:</b><br>
> @@ -9,14 +9,6 @@
>  If you have kdialog installed, a nice progressbar will be displayed showing how the script progresses.
>  </p>
>  <p>
> -Note that tracks with the same score can get different ratings, this is because Amarok rounds the
> -score that is saved in the database.<br>
> -An example: <i>If the shown score is 95 (the limit between rating 4.5 and 5), the database can
> -contain anything from 94.500 to 95.499. If the "real" score is below 95 (94.500-94.999), the track
> -will get a rating of 4.5, if it's above 95 (95.000-95.499), the rating will be 5.</i><br>
> -This will happen around all the rating limits.
> -</p>
> -<p>
>  It is recommended that you <i>back up</i> your database (the statistics table at least) before
>  running this script. It should do no harm, but you can never be too safe...
>  </p>
> --- trunk/extragear/multimedia/amarok/src/scripts/score2rating/score2rating.rb #566782:566783
> @@ -1,6 +1,6 @@
>  #!/usr/bin/env ruby
>  #
> -# Score2Rating 2.5 (for Amarok 1.4)
> +# Score2Rating 3.0 (for Amarok 1.4)
>  # ---------------------------------
>  #
>  # First of all:
> @@ -12,87 +12,66 @@
>  #
>
>
> -if !system( "dcop amarok playlist popupMessage \"Score2Rating started. Click the 'Configure' button in the script manager (with Score2Rating selected) to start the conversion. IT IS RECOMMENDED THAT YOU MAKE A BACKUP OF YOUR DATABASE BEFORE DOING THIS!\" > /dev/null 2>&1" ) then #Info message, and running check combined
> -  print "ERROR: A suitable Amarok wasn't found running!\n"
> -  exit(1) #Exit with error
> +if !system( "dcop amarok playlist popupMessage \"Score2Rating started. Click the 'Configure' button in the script manager (with Score2Rating selected) to start the conversion. It is recommended that you make a backup of your Amarok database BEFORE doing this.\" > /dev/null 2>&1" ) then #Info message, and running check combined
> +    print "ERROR: A suitable Amarok wasn't found running!\n"
> +    exit(1) #Exit with error
>  end
>
>  dialog = ""
>
>  trap( "SIGTERM" ) { system( "dcop #{dialog} close" ) if dialog.length > 0 }
>
> -loop do
> -  message = gets().chomp()
> -  command = /[A-Za-z]*/.match( message ).to_s()
> +###THRESHOLDS START###
> +thres = Array.new
>
> -  case command
> -  when "configure"
> -    result = `dcop amarok collection query "SELECT url FROM statistics WHERE percentage > 0 ORDER BY url"`.chomp() #List tracks that have a score
> -    list = result.split( "\n" )
> +#Awful (1)
> +thres << 10
>
> -    success = true #Assume the procedure is successful
> -    failList = Array.new()
> +#Barely Tolerable (1.5)
> +thres << 30
>
> -    tracknum = 0
> +#Tolerable (2)
> +thres << 45
>
> -    dialog = `kdialog --title Score2Rating --icon amarok --progressbar "Converting Scores to Ratings..." #{list.length}`.chomp()
> -    dialog = dialog.gsub( /DCOPRef\((.*),(.*)\)/, '\1 \2') #Convert the DCOPRef, Ruby doesn't seem to like it.
> +#Okay (2.5)
> +thres << 60
>
> -    list.each do |url|
> -      tracknum += 1
> -      system( "dcop #{dialog} setProgress #{tracknum}" ) if dialog.length > 0
> +#Good (3, Tracks played full length once (75) will be here)
> +thres << 70
>
> -      sqlurl = url.gsub( /(['"`])/, '\\\\\\1' ) #\Escape 'single' and "double" quotes and `backticks`
> +#Very good (3.5)
> +thres << 80
>
> -      begin
> -        percentage = Float( `dcop amarok collection query "SELECT percentage FROM statistics WHERE url='#{sqlurl}'"`.chomp() )
> +#Excellent (4, Tracks played full length twice (87) will be here)
> +thres << 85
>
> -        rating = Integer( `dcop amarok collection query "SELECT rating FROM statistics WHERE url='#{sqlurl}'"`.chomp() )
> -        oldrating = rating
> +#Amazing (4.5, Tracks played full length three times (91) will be here)
> +thres << 90
>
> -        case percentage #The intervals are wrapped so that no scores will be left out. No existing ratings will be downgraded either.
> -        when 0..30
> -            rating = [ rating, 2 ].max #Awful
> -        when 30..45
> -            rating = [ rating, 3 ].max #Barely Tolerable
> -        when 45..60
> -            rating = [ rating, 4 ].max #Tolerable
> -        when 60..70
> -            rating = [ rating, 5 ].max #Okay
> -        when 70..80
> -            rating = [ rating, 6 ].max #Good (Tracks played full length once (75) will be here)
> -        when 80..85
> -            rating = [ rating, 7 ].max #Very good
> -        when 85..90
> -            rating = [ rating, 8 ].max #Excellent (Tracks played full length twice (87) will be here)
> -        when 90..95
> -            rating = [ rating, 9 ].max #Amazing (Tracks played full length three times (91) will be here)
> -        when 95..100
> -            rating = [ rating, 10 ].max #Favourite
> -        end
> +#Favourite (5)
> +thres << 95
>
> -        if rating != oldrating then #If a new rating was calculated
> -          if !system( "dcop amarok collection query \"UPDATE statistics SET rating='#{rating}' WHERE url='#{sqlurl}'\" > /dev/null 2>&1" ) then #If the command fails:
> -            success = false #The procedure wasn't successful
> -            failList << "DCOP: " + url
> -          end
> -        end
> -      rescue
> -        success = false
> -        failList << "SEVERE: " + url
> -      end
> -    end
> +###THRESHOLDS END###
> +thres << 100
>
> -    system( "dcop #{dialog} close" ) if dialog.length > 0
> +command = ""
> +while command != "configure"
> +    command = /[A-Za-z]*/.match( gets().chomp() ).to_s() #Wait until user clicks on Configure
> +end
>
> -    if success == true then #If the procedure was sucessful
> -      system( "kdialog --msgbox \"Done! All your tracks (that have a score) should now have ratings. You will have to reload your playlist to see them, though.\"" )
> -    else
> -      failCount = failList.length
> -      STDERR.puts( "FAILED URL LIST START\n" + failList.join("\n") + "\nFAILED URL LIST END\nPlease e-mail the entire contents of this error report to ajocke (at) gmail (dot) com to help further development of Score2Rating.")
> +dialog = `kdialog --title Score2Rating --icon amarok --progressbar "Converting Scores to Ratings..." 9`.chomp()
> +dialog = dialog.gsub( /DCOPRef\((.*),(.*)\)/, '\1 \2') #Convert the DCOPRef, Ruby doesn't seem to like it.
>
> -      system( "kdialog --sorry \"Score2Rating has finished its conversion, but the process failed for #{failCount} track(s).\nA list of the failed URL(s) will be given to you if you click Details in Amarok's error dialog which will appear after you dismiss this dialog.\n(To see the new ratings, you will have to reload your playlist.)\"" )
> -      exit(38) #Exit with error to give the user Amarok's error box
> -    end
> -  end
> -end
> \ No newline at end of file
> +for r in 2 .. 10
> +
> +    system( "dcop amarok collection query \"UPDATE statistics SET rating='#{r}' WHERE percentage >= '#{thres[r - 2]}' AND percentage <= '#{thres[r - 1]}' AND rating < '#{r}'\" > /dev/null" )
> +
> +    system( "dcop #{dialog} setProgress #{r - 1}" ) if dialog.length > 0
> +
> +end
> +
> +system( "dcop #{dialog} close" ) if dialog.length > 0
> +dialog = ""
> +
> +system( "dcop amarok playlist popupMessage \"Score2Rating is done! All your tracks (that have a score) should now have ratings. You will have to reload your playlist to see them, though.\"" )
> +exit(0)
>


-- 
"Gentlemen, you can't fight in here! This is the War Room" - The
President (Dr. Strangelove)



More information about the Amarok mailing list