[Coding Exercise 4] Billboard Top 100 Songs Charts

pdf

School

Simon Fraser University *

*We aren’t endorsed by this school

Course

120

Subject

Computer Science

Date

Oct 30, 2023

Type

pdf

Pages

9

Uploaded by xiaofanfan

Report
16/10/2023, 13:49 [Coding Exercise 4] Billboard Top 100 Songs Charts https://canvas.sfu.ca/courses/79847/assignments/904834?module_item_id=3035539 1/9 [Coding Exercise 4] Billboard Top 100 Songs Charts Due Nov 3 by 11:59pm Points 22 Submitting a file upload File Types py Start Assignment Concerts are coming back to town! Inspired by the CMPT 120 course, you and your friends want to get ideas of possible concerts to go to by exploring data, and here is an opportunity: You will be able to analyze a data file containing Billboard weekly ranked top 100 songs. The file c ontains data from years 1958 till 2020 and is available in Kaggle (https://www.kaggle.com/datasets/victorsoeiro/netflix-tv- shows-and-movies) (we are providing the link to Kaggle for your interest, but you do NOT need to access there and you do NOT need to become a member there!). For this assignment you are provided a partial data file to make it easier for you to work with, including only the rankings corresponding to the weeks in October 2021. Data File Start by downloading the CSV data file charts.csv from HERE (https://canvas.sfu.ca/courses/79847/files/22121807?wrap=1) (https://canvas.sfu.ca/courses/79847/files/22121807/download?download_frd=1) containing the song charts information for Oct 2021. For clarity, this document will refer to the data file's column names in orange italics . The first row has the title for each column, most of which are self explanatory. peak_rank indicates the highest rank the song reached in the whole file, and weeks_on_board , analogously, indicates the number of weeks that the song has been rated in the top 100, considering the whole file. Rank is the current week ranking, last_week is the previous week ranking. Each line in the file after the first line (i.e. after the titles line) contains data about a particular song/artist. For example, the song "Easy on Me", by Adele, in the first data line, shows how such a song advanced incredibly in the charts! It was in position 68 during the week 2021-10-23 and in the week 2021-10-30 it is in position 1! Many songs appear several times in the file (even in the partial file provided here), as there are rankings for each week and many songs appear in many weeks. Further, the same artist may appear multiple times, even during the same week, since the same or different songs by the same artist may be in these top charts. For example, Ed Sheeran and Drake have a couple songs in the board for week 2021-10-30. Have a careful look through the data file and make sure you understand how it is structured before starting the exercise. Also carefully check the sample outputs which complement the exercise
16/10/2023, 13:49 [Coding Exercise 4] Billboard Top 100 Songs Charts https://canvas.sfu.ca/courses/79847/assignments/904834?module_item_id=3035539 2/9 description. This exercise is broken down into two parts, and part 2 has two queries, all of which should be included, in order, in a single Python file named analyzingCharts.py . Part 1: Overall Data Your program should output the following information (in this order): 1. A greeting messag e to the user. 2. Aggregate information over all the songs in the provided file (i.e. with the October 2021 information): the number of songs including the word "love" in the title (upper or lower case) the songs names which were in rank 1 or 2 the artist 's names whose names start in 'A' the number of songs which advanced in the ranks with respect to the previous week (their current rank number is greater smaller than their last-week rank number ). Rank number #1 is the highest possible rank, indeed. the average of weeks-on-board (of all songs in the provided file) You should NOT check if the songs nor the artists are repeated. That is, if a song or artist is repeated in the file, consider these as separate entries. Hints for Part 1 You should be able to solve this part with one single loop ( considering the loop over the file) . Plan ahead which variables and lists you may need. You may have other loops after you visited all lines of the file to for example print a short list with names. Sample Output Welcome to the Billboard top 100 app! PART 1 ====== Number songs containing the word 'love': 28 Songs names in rank positions 1 or 2: 10 Easy On Me Stay Industry Baby Stay Stay Industry Baby My Universe Stay Stay Industry Baby Artists names starting with 'A': Adele Aventura x Bad Bunny Aventura x Bad Bunny Adele
16/10/2023, 13:49 [Coding Exercise 4] Billboard Top 100 Songs Charts https://canvas.sfu.ca/courses/79847/assignments/904834?module_item_id=3035539 3/9 Aventura x Bad Bunny Aventura x Bad Bunny Aventura x Bad Bunny Songs advancing in rank wrt previous week: 177 Average weeks on board all songs: 10.63 Part 2: User Interaction In your same analyzingCharts.py file, underneath your code for Part 1 , write code to do the following two queries (after printing the title as guided). Each query should be done only once, and in this order. 1. Print a title, or some other output to clearly separate Part 2 output from Part 1 output. Do NOT do this by clearing the screen or printing lots of empty lines, but just print some couple lines and an appropriate title. For each query, also print appropriate subtitles (see the sample runs). 2. First query: A sk the user to enter an artist name (or text which could be part of the name). Then, for each of the artist's songs print the following: the complete artist name, the song title, the date (with the same format as in the file) , the current rank and last-week rank. If an artist sings jointly with another artist that is ok, and you should include the song in the printout If the part typed by the user applies to more than one artist, include all the songs for those artists Once again, treat repeated songs as separate entries If what the user typed is not part of any artist name, inform the user that there are no songs associated to the artist. 3. Second query: Ask the user to enter one song title, or some text which could be part of the song title. Once a song with such title (or including such text) is found, then print to the user: The complete song title, the date and its weeks-on-board value. Print it only once, the first song encountered as you read the file - see Hint below. Then, after printing this information for the requested song , print all the songs (from the beginning of the file) which were on the board more weeks than the requested song. For these songs, include the song tile, the date and the difference in the number of weeks on the board between each song and the requested song. Hints for part 2, extra information to solve this part, and simplifying assumptions: For some queries you may have to process the file more than once. To do so, when your program finishes reading the file, call the method seek(0) to start reading from the beginning of the file again (e.g., suppose data_file is the variable referring to the data file, data_file . seek(0) will allow you to read the file from the first character, and therefore the first line, again). To print data in columns use the Python .format() mini-language. Here are a couple examples.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
16/10/2023, 13:49 [Coding Exercise 4] Billboard Top 100 Songs Charts https://canvas.sfu.ca/courses/79847/assignments/904834?module_item_id=3035539 4/9 print("{:<10}".format("fortune")) prints the string " fortune " so that it is left-aligned in a 10 character- wide column print("{:>6.1f}".format(42.367)) prints the number 42.367 to one decimal place, right-aligned in a 6 character-wide column More details about the format method are available in the Runestone textbook. You may also explore https://www.w3schools.com/python/ref_string_format.asp (https://www.w3schools.com/python/ref_string_format.asp) You may use a width of 25 for song titles and for artists names. This will cause a non-aligned look when the names or titles are wider, but that is accepted as ok. Your program must accept any case from the user input. For example, ' Shivers', and 'ShIvErS' would be recognized as the same song. Leading and trailing spaces and punctuation marks including the characters .,?! in the input should also be ignored. Hint for the first query in Part 2 : To determine if an artist is not in the file, notice that you need to visit the whole file. One possibility is to count the number of times the artist name is found as the file is read, and if at the end of visiting the whole file the count is still 0, that indicates that the artist was not found. Hints and simplifying assumptions for the second query in Part 2 : To print only the first occurrence of the requested song, you may use the break statement inside the for loop as soon as you printed such information. There are other ways to obtain this effect to be seen later in the course. Assume that the user types an existing song (or part of song). Assume that there exists at least one song with more weeks on board than the requested song. Sample Output Here is the output for two sample runs: (What the user types is highlighted to aid this description) Sample Run 1 PART 2 ====== First query: Individual artist songs Artist name (may be part of the name) --> sheera Artist Song Date Rank Previous rank Ed Sheeran Bad Habits 2021-10-30 5 4 Ed Sheeran Shivers 2021-10-30 9 10 Ed Sheeran Bad Habits 2021-10-23 4 5 Ed Sheeran Shivers 2021-10-23 10 11 Ed Sheeran Bad Habits 2021-10-16 5 6 Ed Sheeran Shivers 2021-10-16 11 14 Ed Sheeran Bad Habits 2021-10-09 6 4 Ed Sheeran Shivers 2021-10-09 14 17 Ed Sheeran Bad Habits 2021-10-02 4 3 Ed Sheeran Shivers 2021-10-02 17 16
16/10/2023, 13:49 [Coding Exercise 4] Billboard Top 100 Songs Charts https://canvas.sfu.ca/courses/79847/assignments/904834?module_item_id=3035539 5/9 Second query: Songs and weeks on board Song title (may be part of the title) --> wave Requested Song Date Weeks on board Heat Waves 2021-10-30 40 Songs with more weeks on board than the requested song Song Date Extra weeks on board Levitating 2021-10-30 15 Save Your Tears 2021-10-30 5 Levitating 2021-10-23 14 Save Your Tears 2021-10-23 4 Levitating 2021-10-16 13 Save Your Tears 2021-10-16 3 Levitating 2021-10-09 12 Save Your Tears 2021-10-09 2 Levitating 2021-10-02 11 Save Your Tears 2021-10-02 1 Bye! End of app! Sample Run 2 PART 2 ====== First query: Individual artist songs Artist name (may be part of the name) --> xxxxxxxx Artist Song Date Rank Previous rank There is no such artist in the file Second query: Songs and weeks on board Song title (may be part of the title) --> tears Requested Song Date Weeks on board Save Your Tears 2021-10-30 45 Songs with more weeks on board than the requested song Song Date Extra weeks on board Levitating 2021-10-30 10 Levitating 2021-10-23 9 Levitating 2021-10-16 8 Levitating 2021-10-09 7 Levitating 2021-10-02 6 Bye! End of app! General Notes, Requirements
16/10/2023, 13:49 [Coding Exercise 4] Billboard Top 100 Songs Charts https://canvas.sfu.ca/courses/79847/assignments/904834?module_item_id=3035539 6/9 billboardTop100 The information and titles that you show to the user should be analogous to what is shown in the sample runs At this point in the course we require that you do NOT load the whole file nor all the songs nor all the artists, etc. as big lists in memory. We will work with other kind of solutions later in the course. We may use a different data file (but with the same file name and structure) to mark your assignment's correctness. So do NOT "hard code" anything based on the data. It is fine that you hardcode titles, widths of columns when you print, etc. You must write Python code that calculates and prints out the answers to the questions, by processing the CSV file in your program . You get no points just for providing the exact answers by calculating the answers in Excel and printing them. At this point, for either part, we are requiring you NOT to import any module (e.g., providing CSV file manipulation methods) because one objective of this coding exercise is for you to practice with basic text file manipulation. We will work with modules later in the course. If your program does not run (i.e. crashes or produces an error), your mark will be calculated using the rubric and then multiplied by 0.5. To avoid this penalty, try to start early so you can get help from the teaching team if needed! It is better to submit code that works perfectly but doesn't contain all the features, than one that has all the features (potentially) but crashes. Make sure that your code follows the readability guidelines (https://canvas.sfu.ca/courses/79847/pages/readability-guidelines) . Required Tasks 1. Submit your . py file (named analyzingCharts.py) . Do NOT submit other files (such as the CSV file). 2. AND Complete the short reflection activity (worth points) HERE (https://canvas.sfu.ca/courses/79847/quizzes/253780) (i t is the same deadline, so, do not leave submissions to the end!) (https://canvas.sfu.ca/courses/79847/quizzes/253780)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
16/10/2023, 13:49 [Coding Exercise 4] Billboard Top 100 Songs Charts https://canvas.sfu.ca/courses/79847/assignments/904834?module_item_id=3035539 7/9 Criteria Ratings Pts 2 pts 2 pts 2 pts 2 pts PART 1 number songs w/word 'love' checked that 'love' is *in* the song name, calculated with accumulation pattern 2 pts Full Marks 1 pts partially correct 0 pts not done or incorrect (hardcoded answer is 0 also for all queries) PART 1 song names in rank positions 1 or 2 maybe printed directly as file is read (requiring starting reading the file form start again) or from a list. Number of songs not required. Maybe using Boolean expression with 'or' or comparing int(rank) <=2 2 pts Full Marks 1 pts partially correct 0 pts No Marks PART 1 artists names starting with 'A' (or "a") (analogous comments to counting song names). Only required that the first name starts with 'A', if multiple artists and 'A' appears after this is NOT required to be counted as first letter having an "A" 2 pts Full Marks 1 pts partially correct 0 pts No Marks PART 1 songs advancing rank wrt. prev week rank number < prev week rank number. (Clarified that *peak number* should not be used, but no penalty if it was used instead of rank number) (Clarified that a previous rank 0 means that such song just entered the charts, so it is not considered to advance. If a special treatment 2 pts Full Marks 1 pts partially correct (comparison made without converting to int: -0.5) 0 pts No Marks
16/10/2023, 13:49 [Coding Exercise 4] Billboard Top 100 Songs Charts https://canvas.sfu.ca/courses/79847/assignments/904834?module_item_id=3035539 8/9 Criteria Ratings Pts 2 pts 1 pts 1 pts 2 pts 1 pts 1 pts 2 pts is done with 0 and reasonable, no penalty) PART 1 avg weeks on board 2 pts Full Marks 1 pts partially correct 0 pts No Marks PART 1 and PART 2 - titles clearly welcome user, identify the two parts 1 pts Full Marks 0 pts No Marks PART 2 First query - ask user part of artist name. consider same case to compare (.lower() or .upper()) 1 pts Full Marks 0 pts No Marks PART 2 first query - all associated info shown may be constructing a list or directly printing. 2 pts Full Marks 1 pts partially correct 0 pts No Marks PART 2 First query correctly aligned (maybe aligned fine for songs that are up to 25 characters. if wider songs are misaligned, no penalty 1 pts Full Marks 0 pts No Marks PART 2 first query correctly (only once) inform when artist name does not contain the part 1 pts Full Marks 0 pts No Marks PART 2 Second query. show requested song information 2 pts Full Marks 1 pts partially correct 0 pts No Marks
16/10/2023, 13:49 [Coding Exercise 4] Billboard Top 100 Songs Charts https://canvas.sfu.ca/courses/79847/assignments/904834?module_item_id=3035539 9/9 Total Points: 22 Criteria Ratings Pts 4 pts 0 pts -- * break* was allowed/suggested to be used. No penalty if not used -- no need to check if the part of the song is found - assumption that it is there PART 2 Second query 1- prints songs that were more weeks on board than the requested. 1 - Includes correct difference information. 1 - correctly aligned, information included. 1- Correct result, including songs from the start of file -- both solutions with list creation or direct print are fine (ok to go back to start of file) 4 pts Full Marks 3 pts Missing 1 requirement 2 pts Missing 2 requirements 1 pts Missing 3 requirements 0 pts No Marks TA Marker The name of the TA who marked the assignment 0 pts Marker 1 0 pts Marker 2 0 pts Marker 3 0 pts Marker 4 0 pts Marker 5
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help

Browse Popular Homework Q&A

Q: Remember to keep tabs on any and all databases that could include your personal information. For how…
Q: Question 7 Which of the following compounds is an Arrhenius acid? Ba(OH)2 KOH Ca(OH)2 HBr
Q: Hello. Can you hand write the solution. I'm not understanding.  It's not really clear. Thank you
Q: Which mechanisms are used by miRNAs to regulate expression? O Targeted degradation of mRNAs O…
Q: % Create a program to plot the motion of the ping pong ball with drag. % The program will take…
Q: 30. 1 [² ( 1/3 + 1 = 0 + 1 = 10²/3) dw 8
Q: 6) dilation of 2 about the origin H.
Q: Solid sodium reacts with liquid water to form hydrogen gas according to the equation 2 Na(s) + 2…
Q: FALL QUARTER 2017 Letter Grade Credits 3 2 Course CHEM 140 CHEM 141 ENGL 101 MATH&151 F B D B 5…
Q: 데 2 This is a Matrix multiplication of C with the transpose of C Given C = find CCT.
Q: N To measure the amount of nickel in some industrial waste fluid, an analytical chemist adds 0.190M…
Q: This depicts the probability the mans runs between 4.36 and 6.2 mph.
Q: Presented below is the trial balance of Flounder Corporation at December 31, 2020. Cash Sales Debt…
Q: Use Newton's method to approximate a root of the equation 5x^3+5^x+2=0 as follows. Let x1=−2 be the…
Q: 48. f" (t) = t² + 1/t², t>0, f(2)=3, f' (1)=2
Q: Phosphoric acid, a mild acid used among other things as a rust inhibitor, food additive, and etching…
Q: Consider the equilibrium system described by the chemical reaction below. For this reaction, Kc =…
Q: (a) Br LDA -78deg 1.) 03' 2.) Me₂S NaBH4 ethanol
Q: What are the fixed and variable cost?
Q: Using the given graph of the function f, find the following.
Q: Write the balanced NET ionic equation for the reaction when (NH₄)₂CO₃ and CaCl₂ are mixed in aqueous…
Q: O osoft C To measure the amount of citric acid (C,H,O(CO,H),) water and titrates this solution to…