INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Calculating relative Number Plays (for dappadappa)  (Read 2137 times)

gappie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4583
Calculating relative Number Plays (for dappadappa)
« on: November 15, 2008, 04:15:18 am »

dappadappa asked me if i could explain how to make the view that is on the first picture in the pix01 gallery http://pix01.com/zV@gLaL.
it involves user library fields, a plugin in vb 2005.net and a few playlists.

first of all, Besides calculating the relative number plays and the average number plays for the album, the plugin communicates with girder (telling girder if the file is an image or video or audio), creates a playlist with the whole album from the song that is playing now (for when i play a mixed list and want to hear the whole album), and makes a form which shows all kind of information from the file playing and the volume (I use that with Theater View).
I tried to clean up the code for those things.

First there are several custom library fields I use
Np Album, Gives the average numberplays of the album, Data type is decimal and it can not be edited
Np Album Rel, same as above but then  the average of the relative number playes
Np rel , number plays relative, also decimal and cant be edited
Np rel upd, is an integer that gives the last time the file is updated.
Np Contr, also integer, gives the number plays but then written by the plugin. Important to see what file has not been done yet.
Np sel, a calculated field checking the file that has to be done code: if(isequal([number plays,0],[np contr],2),G,F)

The code will be in the next post...
Logged

gappie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4583
Re: Calculating relative Number Plays (for dappadappa)
« Reply #1 on: November 15, 2008, 04:52:27 am »

i wrote the code using Mr ChriZ his template: http://yabb.jriver.com/interact/index.php?topic=34294.0

i do not know to much about the naming convention for programming, and a lot of names i use are dutch.. im sorry about that

first there is catching the event sended by mc when a track changes. if that happens there is a search string defined (zoekA) which looks to the calculated field 'Np Sel' and picks one album. this search is sended to MaakNpAlbum
Code: [Select]
    Private Sub MJEvent(ByVal s1 As String, ByVal s2 As String, ByVal s3 As String) Handles mediaCenterRef.FireMJEvent
        Dim zoekA As String
        If s2 = "MCC: NOTIFY_TRACK_CHANGE" Then
            zoekA = "[Media Type]=[Audio] [NP Sel]=[F] ~limit=1,1,[Album],[Album Artist (auto)] ~a"
            MaakNPAlbum(zoekA, True)
        End If
    End Sub

MaakNpAlbum raises the np relative with 1 and calculates the averages of the number plays and number plays relative for that album. at the end it makes the np cont the same as number plays. besides that, it will restart the MaakNpAlbum one time (NogEenKeer and ZoekWeer) to see if there is maybe an other file played but not calculeted yet. and it will start the recalculation of one album (BerNpRel).

Code: [Select]

    Private Sub MaakNPAlbum(ByVal zoek As String, ByVal NogEenKeer As Boolean)
        Dim lijst As MediaCenter.IMJFilesAutomation
        Dim Liedje As MediaCenter.IMJFileAutomation
        Dim aantal, t1, t2, NP, NPC As Integer
        Dim NPA, NPI, NPR, NPRA, NPAN, NPRAN, a As Decimal
        Dim ZoekNPR As String
        NPA = 0
        NPRA = 0
        lijst = mediaCenterRef.Search(zoek)
        aantal = lijst.GetNumberFiles()
        If aantal = 0 Then
            Exit Sub
        End If
        For t1 = 0 To aantal - 1
            Liedje = lijst.GetFile(t1)
            If Liedje.Get("NP Rel", False) = "" Or Liedje.Get("NP Rel", False) = "0" Then
                NPR = 0
            Else
                NPR = Liedje.Get("NP Rel", False)
            End If

            If Liedje.Get("Number Plays", False) = "" Then
                NP = 0
            Else
                NP = Liedje.Get("Number Plays", False)
            End If
            NPA = NPA + NP

            If Liedje.Get("NP Contr", False) = "" Then
                NPC = 0
            Else
                NPC = Liedje.Get("NP Contr", False)
            End If

            If Liedje.Get("NP sel", False) = "F" Then
                NPR = NPR + NP - NPC
                lijst.Set(t1, "NP Rel", NPR)
            End If
            NPRA = NPRA + NPR

        Next
        a = Convert.ToDecimal(aantal)
        NPAN = Math.Round(NPA / a, 4)

        NPRAN = Math.Round(NPRA / a, 4)
        For t2 = 0 To aantal - 1
            Liedje = lijst.GetFile(t2)
            If Liedje.Get("Number Plays", False) = "" Then
                NPI = 0
            Else
                NPI = Liedje.Get("Number Plays", False)
            End If

            lijst.Set(t2, "NP Album Rel", NPRAN)
            lijst.Set(t2, "NP Album", NPAN)
            lijst.Set(t2, "NP Contr", NPI)
        Next
        ZoekNPR = "[Media Type]=[Audio] ~sort=[NP Rel Upd],[Last Played] ~limit=1,1,[Album],[Album Artist (auto)] ~a"
        BerNpRel(ZoekNPR)

        If NogEenKeer = True Then
            Zoekweer()
        End If
    End Sub

    Sub Zoekweer()
        Dim zoekB As String
        zoekB = "[Media Type]=[Audio] [NP Sel]=[F] ~limit=1,1,[Album],[Album Artist (auto)] ~a"
        MaakNPAlbum(zoekB, False)
    End Sub

every time a song has been played, (number plays has changed) one album is picked and the relative number plays is multiplied with 0.95 (factor, this can be changed of cource). to make sure this happens in more or less the same order, and every record is done there is a value written to 'Np Rel Upd' as yyyyMMdd (today 20081115).
Code: [Select]
    Sub BerNpRel(ByVal zoek As String)
        Dim Factor As Decimal
        Dim UpdRel As String
        Dim lijst As MediaCenter.IMJFilesAutomation
        Dim Liedje As MediaCenter.IMJFileAutomation
        Dim t1, t2, aantal, Teller As Integer
        Dim NPAT, NP, NPN, a As Decimal
        Factor = 0.95
        Teller = 0
        aantal = 1
        'UpdRel = Month(Now) & Year(Now) & Day(Now)
        UpdRel = Now.ToString("yyyyMMdd")
        'MsgBox(UpdRel)
        NPAT = 0
        lijst = mediaCenterRef.Search(zoek)
        aantal = lijst.GetNumberFiles()
        If aantal = 0 Then
            Exit Sub
        End If

        For t1 = 0 To aantal - 1
            Liedje = lijst.GetFile(t1)
            If Liedje.Get("NP Rel", False) = "" Then
                NPN = 0
            ElseIf Liedje.Get("NP Rel", False) = "0" Then
                NPN = 0
            Else
                NP = Liedje.Get("NP Rel", False)
                NPN = NP * Factor
            End If
            NPAT = NPAT + NPN
        Next
        a = Convert.ToDecimal(aantal)
        NPAT = Math.Round(NPAT / a, 4)

        For t2 = 0 To aantal - 1
            Dim Nrel, rel As Decimal
            Liedje = lijst.GetFile(t2)
            If Liedje.Get("NP Rel", False) = "" Then
                Nrel = 0
            ElseIf Liedje.Get("NP Rel", False) = "0" Then
                Nrel = 0
            Else
                rel = Liedje.Get("NP Rel", False)
                Nrel = Math.Round(rel * Factor, 4)
            End If
            lijst.Set(t2, "NP Rel", Nrel)
            lijst.Set(t2, "NP Rel Upd", UpdRel)
            lijst.Set(t2, "NP Album Rel", NPAT)
            Teller = Teller + 1
        Next
    End Sub

well this is for the calculations in the library. i also have a ticker that is used one time (cant remember why i used a ticker and not on open, guess it worked better:

Code: [Select]
   
Private Sub EenKeer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EenKeer.Tick
        EenKeer.Enabled = False
        Dim zoekA As String
        zoekA = "[Media Type]=[Audio] [NP Sel]=[F] ~limit=1,1,[Album],[Album Artist (auto)] ~a"
        MaakNPAlbum(zoekA, True)
    End Sub

playlists next post
Logged

gappie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4583
Re: Calculating relative Number Plays (for dappadappa)
« Reply #2 on: November 15, 2008, 05:15:37 am »

i made several smartlists:
top: [Media Type]=[Audio] ~limit=-1,1,[album],[album artist (auto)] ~sort=[NP Album Rel]-d,[Last Played]-d ~%=5 ~a
95% :[Media Type]=[Audio] ~limit=-1,1,[album],[album artist (auto)] ~sort=[NP Album Rel]-d,[Last Played]-d ~%=10 ~a
90% :[Media Type]=[Audio] ~limit=-1,1,[album],[album artist (auto)] ~sort=[NP Album Rel]-d,[Last Played]-d ~%=20 ~a

same for 80, 70, 50 and 25 %

now i make a view (the one on the picture) with search lists:
top is playlist top
95% is playlist 95% and not playlist top
90% is playlist 90% and not playlist 95%

etc

i made a same list for absolute number plays also


that is it

 :)

hope it helps

gab

Logged

dappadappa

  • Member
  • *
  • Posts: 4
Re: Calculating relative Number Plays (for dappadappa)
« Reply #3 on: November 15, 2008, 09:55:07 am »

Thankyou Very Much

i really appreciate you going thru all that trouble

have a gud day :)

DappaDappa
Logged
Pages: [1]   Go Up