by brianon » Tue Mar 14, 2006 7:27 am
Try this.
It'll ask for a start date and end date "dd/mm/yyyy".
And then the number of tracks to include.
I use it to create weekly/monthly/yearly charts.
It creates a playlist for you once complete.
scripts.ini
Code: Select all
[CreateChart]
FileName=CreateChart.vbs
ProcName=CreateCHart
Order=100
DisplayName=&CreateChart
Description=CreateChart
Language=VBScript
ScriptType=0
CreateChart.vbs
Code: Select all
Sub CreateChart
' define vars
Dim strStartDate
Dim strEndDate
Dim strUSStartDate
Dim strUSEndDate
Dim strPlaylistName
Dim strTmp
Dim strSQL
Dim strOut
Dim strOut2
Dim howMany
Dim strPlaylistId
Dim x
''''''''''''''''''''
' get the start date
strStartDate = ""
strStartDate = InputBox("Enter the Start date [eg. '01/10/2005']", "Start Date")
'If Canceled, exit
If strStartDate = "" Then
Exit Sub
End If
'Check that the text entered is a valid parameter. Inform user if it isn't.
If Not IsDate(strStartDate) Then
mb = MsgBox("You did not enter a valid date. Please try again.",0,"Error")
Exit Sub
End If
''''''''''''''''''''
' get the end date
strEndDate = ""
strEndDate = InputBox("Enter the End date [eg. '31/10/2005']", "End Date")
'If Canceled, exit
If strEndDate = "" Then
Exit Sub
End If
'Check that the text entered is a valid parameter. Inform user if it isn't.
If Not IsDate(strEndDate) Then
mb = MsgBox("You did not enter a valid date. Please try again.",0,"Error")
Exit Sub
End If
''''''''''''''''''''''''''''''''
' make the name of the playlist
strPlaylistName = "Chart-" & strStartDate & "--to--" & strEndDate
''''''''''''''''''''''''''''''''
' make sure it doesn't already exist
strSQL = "select Count(Playlists.IDPlaylist) AS CountOfPlaylists from Playlists where Playlists.PlaylistName = '" & strPlaylistName & "'"
Set qryStats = SDB.Database.OpenSQL(strSQL)
strPlaylists = qryStats.StringByName("CountOfPlaylists")
' if it does exist see if the user wants to delete it
If Not strPlaylists = 0 then
strTmp = InputBox("Already have playlist with this name. Replace ? [y/n]", "Playlist Replace")
If strTmp = "n" then
Exit Sub
else
' delete the playlist
SDB.Database.ExecSQL("delete from Playlists where Playlists.PlaylistName = '" & strPlaylistName & "'")
end if
End If
''''''''''''''''''''''''''''''''''''
' add the playlist to Playlist table
SDB.Database.ExecSQL("insert into Playlists (PlaylistName, ParentPlaylist, Comment) values ('" & strPlaylistName & "',0,'Auto Generated Chart Playlist')")
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' create the list of songs for the playlist
' find out the max for the list
howMany = InputBox("Is this a Top 50 (+ ties) or ... ?", "Top X")
' now get the ID of the playlist we added earlier
strSQL = "select Playlists.IDPlaylist AS PlaylistId from Playlists where Playlists.PlaylistName = '" & strPlaylistName & "'"
Set qryStats = SDB.Database.OpenSQL(strSQL)
strPlaylistId = qryStats.StringByName("PlaylistId")
' if it does exist then we are screwed!
If strPlaylistId = 0 then
strTmp = InputBox("Playlist not created!", "Error")
End If
''''''''''''''''''''''''''''''''
' change the two dates from dd/mm/yyyy to mm/dd/yyyy for the comparision
strUSStartDate = Month(strStartDate) & "/" & Day(strStartDate) & "/" & Year(strStartDate)
strUSEndDate = Month(strEndDate) & "/" & Day(strEndDate) & "/" & Year(strEndDate)
' create the tmp table
SDB.Database.ExecSQL ("drop table tmpIds")
SDB.Database.ExecSQL ("drop table tmpChart")
SDB.Database.ExecSQL ("create table tmpIds (IdSong int not null)")
SDB.Database.ExecSQL ("create table tmpChart (IdSong int not null, SongCount int not null)")
' tmpIds
strSQL = "select Played.IdSong AS Ids from Played where Played.PlayDate between #" & strUSStartDate & "# and #" & strUSEndDate & "# order by IdSong "
Set qryStats = SDB.Database.OpenSQL(strSQL)
'''''''''''''''''
' insert into tmp
While Not qryStats.EOF
strOut = qryStats.StringByName("Ids")
SDB.Database.ExecSQL("insert into tmpIds (IdSong) values (" & strOut & ")")
qryStats.Next
Wend
' tmpChart
strSQL = "select distinct IdSong as topIds, Count(IdSong) as myCount from tmpIds group by IdSong"
Set qryStats = SDB.Database.OpenSQL(strSQL)
''''''''''''''''''''''''
' insert into temp chart
While Not qryStats.EOF
strOut = qryStats.StringByName("topIds")
strOut2 = qryStats.StringByName("myCount")
SDB.Database.ExecSQL("insert into tmpChart (IdSong, SongCount) values ("&strOut&","&strOut2&")")
qryStats.Next
Wend
' query the temp chart
strSQL = "select TOP " & howMany & " tmpChart.IdSong as topIds from tmpChart order by SongCount DESC"
Set qryStats = SDB.Database.OpenSQL(strSQL)
x = 0
While Not qryStats.EOF
strOut = qryStats.StringByName("topIDs")
SDB.Database.ExecSQL("insert into PlaylistSongs (IDPlaylist, IDSong, SongOrder) values (" & strPlaylistId & "," & strOut & "," & x & ")")
x = x + 1
qryStats.Next
Wend
End Sub
'strSQL = "select distinct Played.IdSong as topIds, Count(Played.IdSong) as myCount from Played where Played.PlayDate between #" & strStartDate & "# and #" & strEndDate & "# group by IdSong"
Try this.
It'll ask for a start date and end date "dd/mm/yyyy".
And then the number of tracks to include.
I use it to create weekly/monthly/yearly charts.
It creates a playlist for you once complete.
scripts.ini
[code]
[CreateChart]
FileName=CreateChart.vbs
ProcName=CreateCHart
Order=100
DisplayName=&CreateChart
Description=CreateChart
Language=VBScript
ScriptType=0
[/code]
CreateChart.vbs
[code]
Sub CreateChart
' define vars
Dim strStartDate
Dim strEndDate
Dim strUSStartDate
Dim strUSEndDate
Dim strPlaylistName
Dim strTmp
Dim strSQL
Dim strOut
Dim strOut2
Dim howMany
Dim strPlaylistId
Dim x
''''''''''''''''''''
' get the start date
strStartDate = ""
strStartDate = InputBox("Enter the Start date [eg. '01/10/2005']", "Start Date")
'If Canceled, exit
If strStartDate = "" Then
Exit Sub
End If
'Check that the text entered is a valid parameter. Inform user if it isn't.
If Not IsDate(strStartDate) Then
mb = MsgBox("You did not enter a valid date. Please try again.",0,"Error")
Exit Sub
End If
''''''''''''''''''''
' get the end date
strEndDate = ""
strEndDate = InputBox("Enter the End date [eg. '31/10/2005']", "End Date")
'If Canceled, exit
If strEndDate = "" Then
Exit Sub
End If
'Check that the text entered is a valid parameter. Inform user if it isn't.
If Not IsDate(strEndDate) Then
mb = MsgBox("You did not enter a valid date. Please try again.",0,"Error")
Exit Sub
End If
''''''''''''''''''''''''''''''''
' make the name of the playlist
strPlaylistName = "Chart-" & strStartDate & "--to--" & strEndDate
''''''''''''''''''''''''''''''''
' make sure it doesn't already exist
strSQL = "select Count(Playlists.IDPlaylist) AS CountOfPlaylists from Playlists where Playlists.PlaylistName = '" & strPlaylistName & "'"
Set qryStats = SDB.Database.OpenSQL(strSQL)
strPlaylists = qryStats.StringByName("CountOfPlaylists")
' if it does exist see if the user wants to delete it
If Not strPlaylists = 0 then
strTmp = InputBox("Already have playlist with this name. Replace ? [y/n]", "Playlist Replace")
If strTmp = "n" then
Exit Sub
else
' delete the playlist
SDB.Database.ExecSQL("delete from Playlists where Playlists.PlaylistName = '" & strPlaylistName & "'")
end if
End If
''''''''''''''''''''''''''''''''''''
' add the playlist to Playlist table
SDB.Database.ExecSQL("insert into Playlists (PlaylistName, ParentPlaylist, Comment) values ('" & strPlaylistName & "',0,'Auto Generated Chart Playlist')")
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' create the list of songs for the playlist
' find out the max for the list
howMany = InputBox("Is this a Top 50 (+ ties) or ... ?", "Top X")
' now get the ID of the playlist we added earlier
strSQL = "select Playlists.IDPlaylist AS PlaylistId from Playlists where Playlists.PlaylistName = '" & strPlaylistName & "'"
Set qryStats = SDB.Database.OpenSQL(strSQL)
strPlaylistId = qryStats.StringByName("PlaylistId")
' if it does exist then we are screwed!
If strPlaylistId = 0 then
strTmp = InputBox("Playlist not created!", "Error")
End If
''''''''''''''''''''''''''''''''
' change the two dates from dd/mm/yyyy to mm/dd/yyyy for the comparision
strUSStartDate = Month(strStartDate) & "/" & Day(strStartDate) & "/" & Year(strStartDate)
strUSEndDate = Month(strEndDate) & "/" & Day(strEndDate) & "/" & Year(strEndDate)
' create the tmp table
SDB.Database.ExecSQL ("drop table tmpIds")
SDB.Database.ExecSQL ("drop table tmpChart")
SDB.Database.ExecSQL ("create table tmpIds (IdSong int not null)")
SDB.Database.ExecSQL ("create table tmpChart (IdSong int not null, SongCount int not null)")
' tmpIds
strSQL = "select Played.IdSong AS Ids from Played where Played.PlayDate between #" & strUSStartDate & "# and #" & strUSEndDate & "# order by IdSong "
Set qryStats = SDB.Database.OpenSQL(strSQL)
'''''''''''''''''
' insert into tmp
While Not qryStats.EOF
strOut = qryStats.StringByName("Ids")
SDB.Database.ExecSQL("insert into tmpIds (IdSong) values (" & strOut & ")")
qryStats.Next
Wend
' tmpChart
strSQL = "select distinct IdSong as topIds, Count(IdSong) as myCount from tmpIds group by IdSong"
Set qryStats = SDB.Database.OpenSQL(strSQL)
''''''''''''''''''''''''
' insert into temp chart
While Not qryStats.EOF
strOut = qryStats.StringByName("topIds")
strOut2 = qryStats.StringByName("myCount")
SDB.Database.ExecSQL("insert into tmpChart (IdSong, SongCount) values ("&strOut&","&strOut2&")")
qryStats.Next
Wend
' query the temp chart
strSQL = "select TOP " & howMany & " tmpChart.IdSong as topIds from tmpChart order by SongCount DESC"
Set qryStats = SDB.Database.OpenSQL(strSQL)
x = 0
While Not qryStats.EOF
strOut = qryStats.StringByName("topIDs")
SDB.Database.ExecSQL("insert into PlaylistSongs (IDPlaylist, IDSong, SongOrder) values (" & strPlaylistId & "," & strOut & "," & x & ")")
x = x + 1
qryStats.Next
Wend
End Sub
'strSQL = "select distinct Played.IdSong as topIds, Count(Played.IdSong) as myCount from Played where Played.PlayDate between #" & strStartDate & "# and #" & strEndDate & "# group by IdSong"
[/code]