Playback statistics

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

psyXonova
Posts: 785
Joined: Fri May 20, 2005 3:57 am
Location: Nicosia, Cyprus
Contact:

Playback statistics

Post by psyXonova » Thu Oct 06, 2005 4:56 am

The idea for this script came from this topic.

What it does
This scipt monitors the player and inserts (in percent) how much of the song has been played in the Played table. This way not only it records if a song has been played less than the 1/3 of its time (which is the default value that MM records the play) but also adds how much of the files duration we had listened evetime we played the song.

Useness
Nice to keep track of your file usages... and urghhh i can't think of anything else :cry:

Requirements
This scripts requires from you to add a new column inside the "Played" table which you must name PlayPercentage and use integer as its datatype

Known Issues
This script (by design) doesn't update the play counter. This means that MM is responsible for updating the play counter (which is done every time the 1/3 of a file has been played). There are scripts out there than will update Play counter according to the statistics stored in the Played table if you like to....

Instructions

First of all create a new column inside the "Played" table which you must name PlayPercentage and use integer as its datatype. If you don't have access then you have a problem....
If you don't know how to do it search Access help, its quite easy

Afterwards insert the following lines at the end of
the Scripts.ini:

Code: Select all

[Percentage]
FileName=Auto\Percentage.vbs
ProcName=SetPercentage
Order=10
DisplayName=SetPercentage
Description=SetPercentage
Language=VBScript
ScriptType=2
Create a new text file and add the following lines:

Code: Select all

'==========================================================================
' NAME: SetPercentage.vbs
'
' AUTHOR: psyXonova
' DATE  : 06/10/2005
'
' COMMENT: This script sole purpose is to call the setpercentageext.vbs every
'		   time the playback of a song starts. Must be put in the auto folder
'==========================================================================


Sub SetPercentage

Dim WShell, Command, Result

Set WShell = CreateObject("WScript.Shell")

'This is the path to the SetPercentageExt.vbs
'If yours is located elsewhere change the value

Command = Chr(34)&"C:\Program Files\MediaMonkey\Scripts\SetPercentageExt.vbs"&Chr(34)

Result = WShell.Run(Command, 1, 1) 

End Sub
Save this file as SetPercentage.vbs inside the Scripts\Auto folder

Create another textfile and paste those lines:

Code: Select all

'==========================================================================
' NAME: SetPercentageExt.vbs
'
' AUTHOR: psyXonova
' DATE  : 06/10/2005
'
' COMMENT: This script is called by the auto script setpercentage.vbs every
'		   time a new song starts playing.
'		   This scripts stops execution if the player is stopped or If
'		   current playback Time Is smaller than the last value entered
'		   in the table. This means that if you seek backwards to a file
'		   it will stop scripts execution
'==========================================================================

'Initilization

Dim SDB

Set SDB = CreateObject("SongsDB.SDBApplication")

Dim itm, percentage, StrQuery, totaltime, CurrentTime, StartTime, id, iter, song

Set itm = SDB.Player.CurrentSong
totaltime = itm.SongLength

StartTime = Now()

song = itm.ID

'Add the first entry in the played table (you must create a new column named PlayPercentage first

strQuery = "INSERT INTO Played (IdSong, PlayDate, PlayPercentage) VALUES (" & itm.ID & ",  Now(), 1)"
SDB.Database.ExecSQL(strQuery)
StrQuery = "SELECT Played.IdPlay FROM Played Where Played.IDSong = " & itm.ID & " ORDER BY Played.IdPlay DESC"
Set Iter = SDB.Database.OpenSQL(strQuery)

'Get the rows id so from now on we update this and don't add new rows
id = iter.stringbyname("IdPlay")

'Start Updating every 2 seconds
Do While SDB.Player.PlaybackTime < totaltime
WScript.Sleep 2000 'This is the update interval in milliseconds. DONT MAKE IT LOWER THAN 1000 !!!!


If SDB.Player.isPlaying = False Then Exit Do 'Stop script if playback has stopped


' stop script if playback time is lower than the last value entered. 
' Had to add this because script does't realize if the player started playing another
' and continues to update song statistics even though the playback of the specific song has stopped
If CurrentTime > SDB.Player.PlaybackTime Then Exit Do 

percentage = Round((SDB.Player.PlaybackTime/TotalTime)*100,0)

' If playback percentage is higher than 90% make it 100
' This way we will have 100 percent values in our statistics if the playback
' is reaching to the end (otherwise this would be almost impossible since
' script checks for playback status every 2 seconds
If percentage > 90 Then 
percentage = 100
End If

If percentage > 35 Then
StrQuery = "DELETE Played.IdPlay FROM Played WHERE Played.IdPlay > " & id & " AND Played.IDSong = " & itm.ID
SDB.Database.ExecSQL(strQuery)
End If

' Update Statistics
strQuery = "UPDATE Played Set Played.PlayPercentage = " & percentage & " WHERE Played.IdPlay = " & id & " AND Played.IdSong = " & itm.ID
SDB.Database.ExecSQL(strQuery)
CurrentTime = SDB.Player.PlaybackTime

Loop
Save this file as SetPercentageExt.vbs inside the Scripts folder (not auto)

Restart MM. Begin playing your files as normal.
Check your statistics inside the Played table everytime you want.
You can now create scripts that access those statistics and use them as you please!!!

Hope you like it :lol:

onkel_enno
Posts: 2146
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno » Thu Oct 06, 2005 5:29 am

But now I have to entries for each song in Played.
The One you create and the one MM creates :(

IdPlay IdSong PlayDate PlayPercentage
16690 6231 06.10.2005 12:16:48 100
16691 6231 06.10.2005 12:17:51 0
16692 2715 06.10.2005 12:20:39 100
16693 2715 06.10.2005 12:21:35 0
16694 72 06.10.2005 12:23:33 100
16695 72 06.10.2005 12:24:51 0
SansaMonkey - for SanDisk Sansa and Rockbox Users

Please no PMs for Questions which should be asked in the Forum. Thx

psyXonova
Posts: 785
Joined: Fri May 20, 2005 3:57 am
Location: Nicosia, Cyprus
Contact:

Post by psyXonova » Thu Oct 06, 2005 5:55 am

Pss,
i thought nobody took it before i correct it
I noticed that alos 10 minutes after the original post and fixed it.
Try re-copying re-pasting the setpercentageext.vbs.
It is fixed now

Philby
Posts: 155
Joined: Wed Aug 10, 2005 7:49 am

Post by Philby » Thu Oct 06, 2005 8:28 pm

Code: Select all

but also adds how much of the files duration we had listened evetime we played the song. 
So if we play a song five times, and stop it at a different point each time, what will we see in the DB ? Five different entries, one for each time, or just the last one, or a total of all the time played so far ?
Regards
Philby

psyXonova
Posts: 785
Joined: Fri May 20, 2005 3:57 am
Location: Nicosia, Cyprus
Contact:

Post by psyXonova » Fri Oct 07, 2005 4:03 am

The logic is same as MM. SO, if you play a song five times you will see it in the Played table 5 times, each one with its on percentage (e.g. 20, 50, 100, 90, 80)

The purpose of this script is to record the statistics.
In order to enjoy those statistics though you will have to use other (not yet created scripts)
One case (e.g.) is to create a graph that will tell you how many songs you have listened till the end, how many up to 80% how many up to 50 etc.
Or you can create usage statistics for each song or album etc

Philby
Posts: 155
Joined: Wed Aug 10, 2005 7:49 am

Post by Philby » Sun Oct 09, 2005 6:33 pm

psyxonova,
As a novice script witer, I also felt very satisfied with my first few that actually made MM do things that I wanted, but were not offered in the standard package.

You stats seem very "individual". I cannot imagine the average user wanting to know how many times a song has been played 10%, 25%, 80%, etc. But each to their own. I would find it much more useful not to have my "played" counter increment until I had played a track more than X%, where X is a number I could nominate myself. But congratulations on making all your stats happen. Quite an achievement really.
Regards
Philby

psyXonova
Posts: 785
Joined: Fri May 20, 2005 3:57 am
Location: Nicosia, Cyprus
Contact:

Post by psyXonova » Mon Oct 10, 2005 3:43 am

Philby,
this stats scripts came as a request from another post (see 1st post for details).
I did it because i want to sharp my scills on VBScript since i felt it would be easy (because i allready know VB).
This scripts was quite a chalenge to me because i had to make it work outside MM which wasn't my intention at all. It helped my realize MM's scripting model along with its disadvantages.

I agree with you that this script in its current form doesn't realy helps on presenting statistics but it can easilly create them for you (as a root material) so other scripts can access them.
Adding a play counter increcement is very easy and as a matter of fact i will include it as an option inside the script as soon as i have the time. I jst thought that many people may not like changing so commonly used statistics as play count is.
There is also a script out there that will update the playcounter based on the entries inside the played table so one can know exactly the play count no matter how long the track played...
Anyway, now that i have found out how to use scripting outside MM i am ready to create a scrpt that will really help people and cover a major problem of MM. I want to make a cover designer script. Something like neros cover designer....
I hope i will have the time and patient to start it soon.
Thnks for your comments and nice words Philby :lol:

Anubis
Posts: 439
Joined: Fri Feb 04, 2005 4:57 pm
Location: Sydney, Australia

Re: Playback statistics

Post by Anubis » Tue Oct 18, 2005 10:46 pm

psyxonova wrote:First of all create a new column inside the "Played" table which you must name PlayPercentage and use integer as its datatype.
Hmm, can you (or more specifically, the MM developers) comment on what impact changing MM's DB/Table structures will have.

Without some sort of guarantee that it won't break MM, now or in the future, this sort of change scares me...

Now, I understand that if everything is done by SQL, there is a layer of abstraction between scripts/programs/MM and the actual structure that should allow additions to tables structures. And I say additions, changing existing fields/structures would be a no-no...

Thanks for this script, I will be seriously looking at it once I get a satisfaction level about changing the DB structure. I'd still love to see the dev's add the the underlying capability for this script into MM...

psyXonova
Posts: 785
Joined: Fri May 20, 2005 3:57 am
Location: Nicosia, Cyprus
Contact:

Post by psyXonova » Wed Oct 19, 2005 5:04 am

I can't speak on behalf of the developers but i can tell you these:

1. The addition of a column to a database table usually doesn't impact compability or performance unless the table is frequently queried by the apllication and the column you add is indexed (and in some other cases which are not of importance here). Now, the played table is a table that MM uses only once every playback. Furthermore the added column is a simple numeric one with no index. The only problem i see is that if developers decide to include a feature that will have to update the structure of the "Played" table there maybe problems. In this case all you have to do is to delete the PlayPercentage column prior to updating.

2. I use the script all the time from the 1st minute i post it. This is more than a month of 15 hrs of playback daily. Still haven´t any problems or performance issues at all.

Hope this helps...

P.S. In case you are still not convised consider the solution of storing this data on a 2nd database. This can be easilly done. That way you will have your original database intact and also store all your statistics

Post Reply