Thursday, February 28, 2008

2008 Scripting Games - Advanced Event 8

 

Event 8: Making Beautiful Music

 

$TotalMusicTime = New-TimeSpan

$songList = cat C:\Scripts\songlist.csv | foreach {
    $item = $_.split(",")
    $time = $item[2].split(":")
    $song = new-object psobject
    add-member -inp $song noteproperty Artist $item[0]
    add-member -inp $song noteproperty SongName $item[1]
    add-member -inp $song noteproperty Minutes $time[0]
    add-member -inp $song noteproperty Seconds $time[1]
    $song    
}

$cd=@()

$singleArtist = $songList | group Artist | where {$_.count -eq 1}
$groupsArtist = $songList | group Artist | where {$_.count -gt 1}
$singleArtist | foreach {
    $song = new-object psobject
    add-member -inp $song noteproperty Artist $_.Group[0].Artist
    add-member -inp $song noteproperty SongName $_.Group[0].SongName
    add-member -inp $song noteproperty Minutes $_.Group[0].Minutes
    add-member -inp $song noteproperty Seconds $_.Group[0].Seconds
    $cd+=$song
    $TotalMusicTime = $TotalMusicTime.add((New-TimeSpan -Minutes $song.Minutes -Seconds $song.Seconds))
}

$groupsArtist | foreach {
    if(($TotalMusicTime.TotalMinutes -ge 75) -and ($TotalMusicTime.TotalMinutes -le 80)){return}
    $song = new-object psobject
    add-member -inp $song noteproperty Artist $_.Group[0].Artist
    add-member -inp $song noteproperty SongName $_.Group[0].SongName
    add-member -inp $song noteproperty Minutes $_.Group[0].Minutes
    add-member -inp $song noteproperty Seconds $_.Group[0].Seconds
    $cd+=$song
    $TotalMusicTime = $TotalMusicTime.add((New-TimeSpan -Minutes $song.Minutes -Seconds $song.Seconds))
}

write-host
$cd | select Artist,SongName,@{n="Time";e={"{0}:{1}" -f $_.Minutes,$_.Seconds}} | sort artist | ft -a

"Total music time: {0}:{1}" -f $TotalMusicTime.TotalMinutes.ToString("N0"),$TotalMusicTime.Seconds
write-host

 

Artist                      SongName                     Time
------                      --------                     ----
Alice Cooper                I'm Eighteen                 2:58
Badfinger                   No Matter What               2:59
Cracker                     Eurotrash Girl               8:03
Credence Clearwater Revival Have You Ever Seen the Rain? 2:39
Dire Straits                So Far Away                  5:12
Don McLean                  American Pie                 8:35
Donovan                     Catch the Wind               5:02
Jefferson Airplane          White Rabbit                 2:34
John Prine                  New Train                    3:24
Nick Cave and the Bad Seeds Deanna                       3:46
Nirvana                     Heart-Shaped Box             4:41
Paul Simon                  Mother and Child Reunion     2:48
REM                         Losing My Religion           4:28
Robert Palmer               Simply Irresistible          4:12
The Animals                 House of the Rising Sun      4:31
The Bangles                 Manic Monday                 3:06
The Beatles                 Help                         2:18
The Kinks                   Sunny Afternoon              3:36
The Ramones                 I Wanna Be Sedated           2:29


Total music time: 77:21

No comments: