CS21 Lab 8: Searching

Written portion: due in class Friday, November 16

Programming portion: due Saturday night, November 17, before midnight


Make sure all programs are saved to your cs21/labs/08 directory. Files outside this directory will not be graded.

$ update21
$ cd ~/cs21/labs/08

Goals

Topics for this assignment


1. Searching worksheet

The first part of the lab involves you tracing linear and binary searches on a list. This is excellent practice for what will almost certainly be a question on quizzes and the final exam!

Download the PDF, print it out, and turn it in at the start of class on Friday.


2. Music information

Overview

This week’s lab involves processing a music library. Your program music_info.py will help the user search through their music library and learn interesting information. We strongly recommend reading through the entire lab and creating a TDD before implementing your program.

The files below contain music libraries for several different users. There is also a small file music-small.txt in your lab 8 directory for testing.

/home/smathieson/public/cs21/musicA.txt
/home/smathieson/public/cs21/musicB.txt
/home/smathieson/public/cs21/musicC.txt

Here are the first few lines of musicA.txt:

100 Years,Five for Fighting,100 Years - Single,244,25,4/10/16; 2:52 PM
11:11 P.M,All-American Rejects,Move Along,184,1,10/21/09; 10:55 AM
1234-007,DDR,DDR,89,2,4/11/14; 2:59 PM
16 Military Wives,The Decemberists,Picaresque,292,20,7/24/14; 2:21 PM
19-2000,Gorillaz,,207,47,7/29/14; 9:00 PM

Each line contains the information about a song. The lines in the file are in alphabetical order based on the name of the song.

Here is a table for what the different data entries mean: song name, artist, album, time (sec), play count, last played

Song table
Song table

Note that the length of the song is in seconds and the last played shows the date and time.

You will write a program (music_info.py) that reads in the music data and allows the user to explore this dataset, to see if certain songs are present and how many times they have been played. You will implement a text-based menu system that allows the user to search through the data for either the name of the song (exact match), or any song with a play count in a user-chosen range (e.g., played 40-45 times). When the program quits, it should list all the songs with lengths above 8 minutes (very long songs!)

Sample output for music_info.py

Here is an example of the program (another, longer example is at the bottom of the page). More detailed requirements are listed after the example, but at a high level you must:

  1. support searching by song title
  2. support searching by the number of times the song has been played (within a range)
  3. print the long songs when exiting the program
$ python3 music_info.py
========== Welcome to Music Information =========
Enter A,B,C for music library: A

=================================================
(1) Song name (2) Play count (3) Quit : 1
Enter song name: Schoolin' Life

    Song name:  Schoolin' Life
       Artist:  Beyoncé
        Album:  4 (Deluxe Edition)
       Length:  4:53
   Play count:  30
  Last played:  8/18/15; 4:25 PM

=================================================
(1) Song name (2) Play count (3) Quit : 1
Enter song name: Happy Birthday
Song not found!

=================================================
(1) Song name (2) Play count (3) Quit : 1
Enter song name: london calling

    Song name:  London Calling
       Artist:  The Clash
        Album:  Billy Elliot
       Length:  3:20
   Play count:  68
  Last played:  8/18/17; 3:43 PM

=================================================
(1) Song name (2) Play count (3) Quit : 2
Enter min play count: 70
Enter max play count: 75

                Song  Play count
              ------  ------
           A Message   73
       American Girl   71
    Heart of Courage   71
          Last Night   72

=================================================
(1) Song name (2) Play count (3) Quit : 2
Enter min play count: 22
Enter max play count: 25

                Song  Play count
              ------  ------
           100 Years   25
 Anyone Else But You   23
   Boys Wanna Be Her   24
      Cast No Shadow   23
     Cliffs of Dover   24
          Cosmo Girl   25
        Diamond Dogs   22
        Fallen Angel   22
       Feel Good Inc   24
       Feliz Navidad   25
          Green Eyes   23
          Hands Down   22
 Here (In Your Arms)   24
           I Believe   23
          I Want You   25
         I Will Wait   22
            Inta Eyh   22
   Into the Airwaves   24
           La La Lie   24
          Last Straw   25
         Left Behind   23
         Let It Rain   22
 Livin' La Vida Loca   25
 Made For Each Other   22
    Maybe; This Time   23
        Miss Delaney   23
       Monkey Wrench   25
           New Years   25
      Sana Wara Sana   22
           Save Room   22
    Somebody Told Me   24
             Strings   24
          Summersong   22
     The Guilty Ones   23
      The Wild Goose   22
  This Ain't Goodbye   23
          This Night   22
 Walking On Sunshine   23
         Wicked Ways   23
             Wounded   23

=================================================
(1) Song name (2) Play count (3) Quit : 3

=================================================
Warning! The following songs are very long:

        American Pie      8:34
               Caves      8:19
          Homecoming      9:18
  Immortan’s Citadel      8:41
   Jesus of Suburbia      9:08
 Made For Each Other      8:01
    Piano Variations      9:43
     Pärt: Für Alina     10:47
     Pärt: Für Alina     10:53
    Sonata in B flat     15:07
         The Dawning      8:04

To get the information required in this program, you will have to search through the music information. For the first type of search (searching for data about a specific song), you MUST use binary search. For many of the other parts, since the data is only sorted alphabetically by song name, you will have to use a linear search. You are not allowed to use any of Python’s built-in search functions for ANY of the searching.

Requirements and tips

Here are the specifications for this program and a few helpful tips. Make sure your program meets all of these specifications.

[[data for song 1], [data for song 2], ...]

Here’s what the inner lists for each song should contain:

[song name, artist, album, length of song, play count, last played]

The data for each song should be stored in the correct format. For example, the song name should be a string, the play count should be an int, etc.

["Schoolin' Life", "Beyoncé", "4 (Deluxe Edition)", 293, 30, "8/18/15; 4:25 PM"]
ninja_lst = ['Ayaka', 'Christie', 'Kendre', 'Kenny', 'Maleyah', 'Mikey','Rohan',
    'Shayne', 'Sky', 'Tai', 'Tristan', 'Zach']

for ninja in ninja_lst:
    print("%10s" % ninja)

Output:

     Ayaka
  Christie
    Kendre
     Kenny
   Maleyah
     Mikey
     Rohan
    Shayne
       Sky
       Tai
   Tristan
      Zach

We highly recommend that you show your design to an instructor or ninja before you start to implement this lab. You don’t need to submit your design as a separate document.

Here is another example run of the program, with a variety of user inputs.

Submit

Once you have fully tested all your functions and are confident your program works, fill out the questionnaire in QUESTIONS-08.txt. Then run handin21 a final time to make sure you have submitted the most recent version of your file.