Assignment Part B
Assignment Part B
Assignment Overview:
Assignments task you with applying the skills and knowledge you have learnt through the Ed
Lessons. They are no more difficult than the exercises in your Ed Lessons. You must meet all
competency requirements for each task to be marked as competent overall on the
assignment.
In Assignment Part B, we're going to continue to use our programming skills to customize and display
data for a user. These are basic examples of how many of the apps and websites you use every day
work. We've continued to look at some features of a fictional USyd Music app, an app like Spotify or
Apple Music that allows users to stream their favourite music.
Assignment Part B requires you to complete 5 tasks here in Ed Lessons;
Music Wrapped (Part 1)
Song Information
Music Wrapped (Part 2)
Song queues (Part 1)
Song queues (Part 2)
It should take you between 4 and 10 hours to complete, but do not leave it until the last minute to
attempt.
General instructions:
Please avoid changing function signatures
Assume that cases not mentioned in the specification will not be tested
Hard coding to pass test cases rather than constructing meaningful programs will result in a NSI
result return.
Missing code comments will result in a NI result return
Please avoid writing programs that are overly complex for the sake of it to "aim for a C*". C* is
designed to award work that is well structured, nuanced, and shows good/deep thinking about
code structure. It is inherent traits of your programming skills, as opposed to a list of things we
are looking for.
MAKE SURE YOU READ THE COMPETENCY REQUIREMENTS CAREFULLY!You must complete your code review in your schedule lab during week 9.
Competency requirements:
The competency requirements are summarized below (but are also listed on the page for each task).
You must meet all requirements to be awarded a Competent (C) for a question.
You must receive a minimum of Competent (C) for all questions to receive a Competent (C)
grade overall and move onto Assignment Part C.
To receive an Above Competent (C*) overall, you must receive an Above Competent (C*) in 3/5 tasks.
Full competency requirements outlined -
https://canvas.sydney.edu.au/courses/59287/pages/assignment-part-b-overview?
module_item_id=2431178 Testing vs Submitting Your Assignment
We have changed the interface to make it easier for us to determine when late submissions are
submitted. What this means for you is that you can use the 'test' button as many times as you would
like before officially submitting the assignment (bottom right hand side of the workspace). To
officially lodge your submission you will need to use the 'submit' button (top right hand side of the
workspace).
Any press of the submit button after 11:59pm on 22nd September will be counted as a late
submission. Late penalties will apply if you do not have special considerations or an academic
accommodations plan. Understanding Test Case Output
There will be 3 main types of test cases:
(UNIT) - Tests individual functions to check actions such as return values or modification of
attributes of an instance
(IO) - Tests a function to check if the values printed to stdout (terminal) is what was expected
(IO-UNIT) - Mix of Unit and IO where both return values, modification of attributes and stdout
will be tested altogether
Have a look at the examples below for a better understanding!
Example 1 [UNIT]
On the header you can find the information on what is being tested:
[Song] : Class/function being tested.
Constructor : Brief description of the test case.You will find the relevant output under Test Case Output where:
A brief description will tell you how your function/method was called. e.g with what
arguments.
Expected is what the the test case was expecting your function to do.
Got is what your function did/returned.
############## <END> ############# is a marker showing the end of the
expected/actual block (not to be printed or returned by your function).
Additional comments will give you additional information on the error. In this case, the
duration attribute is not correctly set
Example 2 [IO]
The header is similar to the previous exampleHighlighted in Green (+): Your program did not produce/output that line
Highlighted in Red (-): Your program produced an incorrect output and should be removed.
Example 3 [IO-UNIT]
The header is similar to the previous example
(stdout)->: This shows what your program should produce after each test case action.
If the IO-testing part of this test case fails, then you will see an additional output similar to [IO]
test cases shown in Example 2.If the unit-testing part of this test case fails, then you will see an additional output similar to
[UNIT] test cases shown in Example 1.Tips:
Sometimes the output of the cases in the diff view will not be helpful e.gThis will usually happen for IO-UNIT test cases. Switching to Your output view will be more helpful
in such cases.Music Wrapped (Part 1)
Write a program that verifies a user's username and password and displays the most
streamed song, artist, genre and total streaming hours for a specified month of a year. The
music wrapped will be displayed in a format specified in part 2.
This question involves knowledge from the following Ed Lessons (but not limited to):
IF statement
FOR loops
Break and continue
WHILE loops
Handling errors
Functions
Input/Output
In this part, we will ONLY focus on verifying user authentication.
Format of <username>.txt
The first line will always contain the password of the <username> . The rest of the lines contain the
details of the songs the user listens to each time. Each line will represent a single listening entry and
will be shown in the following format:
<password>
<song_name>,<artist>,<genre>,<song_duration>,<date>
<password> : The <username> 's password
<song_name> : The name of the song.
<artist> : The artist of the song
<genre> : The genre of the song
<song_duration> : The duration of the song, in the format mm:ss
<date> : The date the song was listened to, in the format DD-MM-YYYY
In this exercise, Music Wrapped you can assume that the format of the file <username>.txt is always
correct. All lines in the file will be case-sensitive.
Example of akali.txt
dowhat12kjk
Espresso,Sabrina Carpenter,Pop,04:22,23-02-2024
Ephemeral Dreamscape,Celestial Echoes,Rock,03:54,24-03-2024where the first line contains the password of the username akali and each of other lines contains
the single listening entry of username akali.
This example has also been given to you as part of the scaffold.
Part 1 - Username and Password
The program will begin by displaying the welcome message Welcome to USYD MUSIC! . It will then
continuously prompt the user for their username and password until a matching pair is found or 3
unsuccessful attempts have been made. The program will prompt for user's username and password
in the exact following format:
Welcome to USYD MUSIC!
Enter your username: <username>
Enter your password: <password>
where <username> and <password> are placeholder for user's input for username and password.
The function check_password(username, password) is implemented to check whether the input
<username> and <password> match those in the system. This function will first check whether
<username> exists in the USYD MUSIC system by checking the existence of <username>.txt in the
user_info directory (i.e folder).
If <username>.txt does not exist, the program will print No <username> found :(( , where
<username> is the user input, and returns False .
Otherwise, if <username>.txt exists, the program will check if the entered <password>
matches the password stored on the first line of the file.
If the password matches, print Login successful :)) and returns True .
Otherwise, print Username and password do not match :(( and return False .
If the function check_password returns True , exit the program. Otherwise, the program will go back
to prompt for the user's username and password. If the maximum number of 3 attempts has been
reached, the program will stop prompting for input and exit the program with the following message
Maximum of 3 attempts has been reached. You will be temporarily disabled from logginng
in :((
Example 1 - Matching Username and Password
$ python3 wrapped.py
Welcome to USYD MUSIC!
Enter your username: akali
Enter your password: dowhat12kjk
Login successful :))
Example 2 - Reaching 3 attempts$ python3 wrapped.py
Welcome to USYD MUSIC!
Enter your username: akali
Enter your password: dowhat12
Username and password do not match :((
Enter your username: aka
Enter your password: dowhat12kjk
No aka found :((
Enter your username: akali
Enter your password: idontknow
Username and password do not match :((
Maximum of 3 attempts has been reached. You will be temporarily disabled from logging in :((
Note: You can assume that all standard input are always valid. Lines that start with a $ indicates a
terminal command, which is an instruction you type into the terminal to run your program. Standard
inputs, which the user types into the terminal, are shown in bold.
Competency Requirements:
The test cases do not test that you meet all competency requirements. Please review the requirements
yourself even if you get a green tick. The green tick "mark" just checks if your code runs.
You can test your code as many times as you like before the submission deadline.Song Information
Write a Song class containing all song information and functionality relevant to the song.
This question involves knowledge from the following Ed Lessons (but not limited to):
Variables and data types
IF statements
CLASSES
The Song class will be used in all future exercises in Assignment Part B.
The program requires you to implement the Song class (including its attributes and methods) to store
all information on the songs and functionalities (i.e. methods) that are relevant to the Song objects.
Here are the instance attributes of a Song object.
Here are the instance methods of Song object.Competency Requirements:
The test cases do not test that you meet all competency requirements. Please review the requirements
yourself even if you get a green tick. The green tick "mark" just checks if your code runs.
You can test your code as many times as you like before the submission deadline.Music Wrapped (Part 2)
This question involves knowledge from the following Ed Lessons (but not limited to):
String formatting
IF statements
input() function
Containers (lists, tuples, and dictionaries
Mutable and Immutable data
WHILE and FOR loops
Handling errors
Functions
CLASSES
In this exercise, Music Wrapped, you can assume that the format of the file <username>.txt is always
correct. All lines in the file will be case-sensitive.
Write a program that verifies a user's username and password and displays the most
streamed song, artist, and genre within a specified month in a year. The music wrapped will
be displayed at the end of this part.
In this part, we will focus on creating the Music Wrapped Wall.
You will need to use the Song class in this exercise. You can just copy over the song.py file from the previous
exercise.
Part 2 - Wrapped Wall
The initial login part is the same as what you implemented in Part 1 and can be copied
over.
After a successful login, the program will ask for the specific with message Specify the month that
you want to display: . The input will be validated in the following order:
If the input is not an integer, print Month must be an integer :((
If the input is not within the range of , print Month must be between 1 and 12,
inclusively :((
[1, 12]
If the input is valid, the program will ask for the specific year with a message Specify the year
that you want to display: . The input will be validated in the following order:If the input is not an integer, print Year must be an integer :((
If the input is less than 2000, print Year must be larger than 2000 :((
You can assume that the user will not input a year larger than 2024.
Here we list the functions that you will implement and call within the main() function. Later we
provide details for each function.
You should be extracting the songs using the extract_song_details() function using the
username and the month and year provided by the user.
You should then use count_streams() with the extracted songs to find the number of times
each song, artist and genre has been listened to. Think about how the date_type parameters is
going to help you with that.
Once you have separate dictionaries for songs, artists and genres, you need to use the
find_most_frequent() function to find the most streamed song, artist and genre as tuples.
As you are also required to print the total streaming time, you need to use the
calculate_streaming_second() on the songs list to find the total streaming time in seconds.
Finally, you will pass the tuples and total streaming time to the print_rewind_wall() function
to print the final output.
extract_song_details()
Parameters:
filename: str : user file to extract songs from
month: int : month for which the songs need to be extracted from
year: int : year for which the songs need to be extracted from
Returns:
list[Song] : list of song objects extracted, each as a Song object
The first line will always contain the password of the <username> . The rest of the lines contain the
details of the songs the user listens to each time. Each line will represent a single listening entry and
will be shown in the following format:
<password>
<song_name>,<artist>,<genre>,<song_duration>,<date>
<password> : The <username> 's password
<song_name> : The name of the song.
<artist> : The artist of the song
<genre> : The genre of the song
<song_duration> : The duration of the song, in the format mm:ss
<date> : The date the song was listened to, in the format DD-MM-YYYYcount_streams()
Parameters:
songs: list[Song] : list of song objects
data_type: str : The song attribute for which we need the frequency. This will be either:
'song'
'artist'
'genre'
Returns:
dict[str: int] : A dictionary with the unique song, artist, or genre as keys and the
corresponding streaming counts as values. This should be in the format {song/genre/artist:
frequency, song/genre/artist: frequency,...} where
song/genre/artist is the name of a song, genre or artist depending on the data_type
parameter
frequency is how many times it appears in the songs list.
The count_streams() function will count the streaming frequency for each unique song, artist, or
genre (specified by the data_type parameter). The name of each unique song, artist, or genre will be
used as the key in the dictionary, while the number of streams will be stored as the value. During the
search, if the current song, artist, or genre is already in the dictionary, the streams count is
incremented by one.
You can assume that there will be at least one line for the specified month and year .
find_most_frequent()
Parameters:
streaming_data: dict[Song] : A dictionary containing the streaming data of a single
data_type
Returns:
tuple[str, int] : A tuple containing the key (song, artist, or genre) and its corresponding
number of streaming times.
The find_most_frequent() function will find the most frequently streamed song, artist, or genre.
This is done by iterating through a dictionary of song, artist, or genre data and identifying the keyvalue
pair with the largest streaming count. The function will return the key-value pair with the largest the streaming count as a tuple.
You can assume that there will be no ties.
calculate_streaming_seconds()
Parameters:
songs: list[Song] : list of song objects
Returns:
int : The total streaming seconds
The calculate_streaming_seconds() function will calculate the total streaming seconds from a list
of songs. This is done by iterating through all Song objects and adding their streaming time. This
function will return the total streaming seconds at the end.
print_wrapped_wall()
Parameters:
top_song: tuple(str, int) : the name of top song and its streaming frequency.
top_artist: tuple(str, int) : the name of top artist and its streaming frequency.
top_genre: tuple(str, int) : the name of top genre and its streaming frequency.
total_stream: int : the total streaming seconds
We will use the information about the total_streaming seconds and the most popular songs, artist
and genre within a specific time frame to display the Music Wrapped Wall. The function will first
display banner for the Wrapped Wall as follows:
****************************************************
MONTHLY MUSIC WRAPPED WALL
****************************************************
We then need to print the most streamed song, artist and genre in a specific format as follows:
Top Name Stream Times
Song <song_name> XXXX
Artist <artist_name> XXXX
Genre <genre_name> XXXX
Format specificationEach row will contain 3 columns: Top, Name, and Stream times.
Top : Left-padded with a column width of 8 characters.
Name : Left-padded with a column width of 32 characters.
Stream times : Displayed in a 4-digit format (XXXX) with leading zeros if necessary.
You can assume that all strings in the name column will be fewer than 31 characters long.
The function will then print the total listening hours as follows after converting it from seconds to
DD:HH:mm:ss .
****************************************************
Total streaming DD:HH:mm:ss
****************************************************
Remember to convert the seconds into days, hours, minutes and seconds in this function
Format Specifications:
Total streaming: Left-padded with a column width of 41 characters.
DD: Represents the number of whole streaming days with leading zeros.
HH: Represents the number of whole streaming hours with leading zeros.
mm: Represents the number of whole streaming minutes with leading zeros.
ss: Represents the number of streaming seconds with leading zeros.
You can assume that the stream times is a positive integer that less than 9999
Example of Monthly Wrapped
****************************************************
MONTHLY MUSIC WRAPPED WALL
****************************************************
Top Name Stream Times
Song Do you want to build a snowman 0020
Artist Elena Williams 0100
Genre Pop 0193
****************************************************
Total streaming DD:HH:mm:ss
End-to-end Examples
Sample 1 - akali$ python3 wrapped.py
Welcome to USYD MUSIC!
Enter your username: akali
Enter your password: dowhat12kjk
Login successful :))
Specify the month that you want to display: 2
Specify the year that you want to display: 2024
****************************************************
MONTHLY MUSIC WRAPPED WALL
****************************************************
Top Name Stream Times
Song Espresso 0002
Artist Sabrina Carpenter 0002
Genre Pop 0002
****************************************************
Total streaming 00:00:08:44
Sample 2 - karencat with invalid inputs
$ python3 wrapped.py
Welcome to USYD MUSIC!
Enter your username: karencat
Enter your password: password
Login successful :))
Specify the month that you want to display: ab
Month must be an integer :((
Specify the month that you want to display: 13
Month must be between 1 and 12, inclusively :((
Specify the month that you want to display: 6
Specify the year that you want to display: 6a
Year must be an integer :((
Specify the year that you want to display: 1999
Year must be larger than 2000 :((
Specify the year that you want to display: 2024
****************************************************
MONTHLY MUSIC WRAPPED WALL
****************************************************
Top Name Stream Times
Song Sunset Lover 0003
Artist The Weeknd 0004
Genre Pop 0004
****************************************************
Total streaming 00:00:32:59
These sample user files have been given to you as part of the scaffold.
Note: You can assume that all standard input are always valid. Lines that start with a $ indicates a
terminal command, which is an instruction you type into the terminal to run your program. Standard inputs, which the user types into the terminal, are shown in bold.
Competency Requirements:
The test cases do not test that you meet all competency requirements. Please review the requirements
yourself even if you get a green tick. The green tick "mark" just checks if your code runs.
You can test your code as many times as you like before the submission deadline.Song queues (Part 1)
Write a program that mimics the queue functionality of a music app. The program should
allow users to reset, append or modify existing queues and create a new queue. This task
will be divided into two parts.
The first part will focus on implementing a program that supports adding songs to the queue.
Just like the previous program, copy over your Song class to the song.py folder
This question involves knowledge from the following Ed Lessons (but not limited to):
String formatting
IF statements
input() function
Containers (lists, tuples, and dictionaries
Mutable and Immutable data
WHILE and FOR loops
Handling errors
Functions
CLASSES
You need to use add_song() and write_queue() functions that you will implement in the main()
function.
You need to first prompt the user for the queue mode. See Selecting the queue mode section
below
You then need to initialise an empty list as a queue.
You need to then get song inputs if a user is specified. See Getting song input section below
Here you will be checking whether the argument of <operation> is valid. If it is invalid,
print ***Invalid operation!*** and continue to prompt for next song input.
If a valid <operation> is provided, you should use load_song() function to help
initialise a Song object and add this to the queue using the add_song() function. The
songs will be added to the queue you initialised in point 2.
After the user enters END QUEUE , you will pass the final queue i.e the list of Song objects to
write_queue() function to write all songs in the queue into the <username>_queue.txt file in
the queue_info directory.
1. Selecting the queue mode
The program will receive the username of the users via command line arguments. If no command line argument are given, print No username found! and exit the programs. Otherwise, the program
will check for the existence of <username> 's queue by searching for <username>_queue.txt in the
queue_info directory.
If the <username>_queue.txt file does not exist:
The program will display No queue for <username> found! Creating a new queue...
and then prompt the user for song inputs. In this case, you will need to set the queue
mode to CREATE when calling the write_queue() function later (see below).
Otherwise, the program will ask the user to select between RESET or APPEND mode with the
message Do you want to reset or append to your queue?
If the user inputs RESET , the program will display Resetting your queue... and then
prompt the user for song inputs. You need to set the queue mode to RESET when calling
the write_queue() function to overwrite the file with the queue.
If the user inputs APPEND , the program will display Appending to your queue... . You
need to set the queue mode to APPEND when calling the write_queue() function to
write the queue below the existing queue in the file
If the user inputs neither of the above, the program will print Invalid mode! and return
to prompt for the queue mode.
The input for this prompt will be case-insensitive but space-sensitive (i.e., no leading or trailing
whitespace before or after the input).
Have a look at END-TO-END Examples at the bottom for examples.
2. Getting song input
The program will display a message Update songs in the queue: and ask the user to update the
queue via standard input. The user is expected to provide the details of the song exactly as specified
below:
<operation>,<song name>,<artist>,<genre>,<duration>
<operation> : specify whether the user wants to add ( A ) or not. operations are case sensitive,
meaning 'a' would be an invalid operation.
A : The program calls add_song() function to add song into the playlist.
Otherwise, prints ***Invalid operation!***
<song name> : The name of the song, with words.
<artist> : The name of the artist who sings the song.
<genre> : The genre of the song.
<duration> : The song duration in the format mm:ss .
Each argument will be separated by a comma , .
If the user inputs END QUEUE (case sensitive) , stop prompting the user and write the songs in the queue to the file.
You can assume that all song inputs are always in a correct format.
Have a look at END-TO-END Examples at the bottom for examples.
load_song_from_input()
Parameters:
input_song: str : The string that contains the song information in a correct format. This will
be the input given by the user in the form <operation>,<song name>,<artist>,<genre>,
<duration>
Returns:
Song : The Song object created using the information provided in the parameter.
The load_song_from_input() function parses the input song and extract all song's information. This
information is used to initialise a Song object.
add_song()
Parameters:
queue: list[Song] : list of Song objects
song: Song : The Song object to be added to the queue.
The add_song() function adds a song to the queue (called when the user input has value A in the
<operation> field). If a Song object with the same name and artist already exists in the queue, the
program will print ***'<song name>' by <artist> is already in the queue*** . You only need
to check this against the songs that are being input by the user NOT what exists in the file.
You can assume a user would not add a song to the queue that exists in the file.
Otherwise, the program will print ***'<song_name>' by <artist> is added to the queue*** and
add this Song object to the queue variable.
Think about why we do not need to return the queue to update the queue variable in the main function write_queue()
Parameters:
filename: str : file to wrote the queue into.
queue: list[Song] : list of Song objects in the queue
queue_mode: str : The queue mode selected in "Selecting the queue mode" section. The queue
mode is either RESET, APPEND or CREATE
The write_queue() function writes all Song objects stored in the queue variable to the
<username>_queue.txt file in the queue_info directory. The file-open mode depends on the
selected queue mode:
CREATE: Create a new file to store the queue information and write the queue to it.
RESET: Overwrite the contents of the <username>_queue.txt file with the new queue.
APPEND: Write the new queue below the old queue in the <username>_queue.txt file.
Each song in the queue is written as a single line in the output file. The format of each line is as
follows:
<song name>,<artist>,<genre>,<song duration>
<song name> : The name of the song.
<artist> : The artist of the song.
<genre> : The genre of the song.
<song duration> : The duration of the song in the format mm:ss
Example of the output file karencat_queue.txt
Espresso,Sabrina Carpenter,Pop,04:22
Ephemeral Dreamscape,Celestial Echoes,Rock,03:54
END-TO-END Examples
Example 1 - No command line argument given
Terminal output
$python3 queue.py
No <username> found!
Example 2 - Queue does not exist: Createkarencat_queue.txt does not exist before the program is run
Terminal output
$python3 queue.py karencat
No queue for karencat found! Creating a new queue...
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is added to the queue***
Update songs in the queue: A,Twinkle star,Layla Smiths,Kids,02:22
***'Twinkle star' by Layla Smiths is added to the queue***
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is already in the queue***
Update songs in the queue: X,Magnificient,Sasha Scarlet,Pop,04:23
***Invalid operation!***
Update songs in the queue: END QUEUE
karencat_queue.txt will be created after the program is run
Magnificient,Sasha Scarlet,Pop,04:23
Twinkle star,Layla Smiths,Kids,02:22
Example 3 - Queue already exists: Append
karencat_queue.txt before the program is run
Espresso,Sabrina Carpenter,Pop,04:22
Ephemeral Dreamscape,Celestial Echoes,Rock,03:54
Terminal output
$python3 queue.py karencat
Do you want to reset or append to your queue? ApPEnD
Invalid mode!
Do you want to reset or append to your queue? APPED
Invalid mode!
Do you want to reset or append to your queue? aPPeND
Appending to your queue...
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is added to the queue***
Update songs in the queue: A,Twinkle star,Layla Smiths,Kids,02:22
***'Twinkle star' by Layla Smiths is added to the queue***Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is already in the queue***
Update songs in the queue: X,Magnificient,Sasha Scarlet,Pop,04:23
***Invalid operation!***
Update songs in the queue: END QUEUE
karencat_queue.txt after the program is run
Espresso,Sabrina Carpenter,Pop,04:22
Ephemeral Dreamscape,Celestial Echoes,Rock,03:54
Magnificient,Sasha Scarlet,Pop,04:23
Twinkle star,Layla Smiths,Kids,02:22
Example 4 - Queue already exists: Reset
karencat_queue.txt before the program is run
Espresso,Sabrina Carpenter,Pop,04:22
Ephemeral Dreamscape,Celestial Echoes,Rock,03:54
Terminal output
$python3 queue.py karencat
Do you want to reset or append to your queue? RESET
Resetting your queue...
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is added to the queue***
Update songs in the queue: A,Twinkle star,Layla Smiths,Kids,02:22
***'Twinkle star' by Layla Smiths is added to the queue***
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is already in the queue***
Update songs in the queue: X,Magnificient,Sasha Scarlet,Pop,04:23
***Invalid operation!***
Update songs in the queue: END QUEUE
karencat_queue.txt after the program is run
Magnificient,Sasha Scarlet,Pop,04:23
Twinkle star,Layla Smiths,Kids,02:22
Note: You can assume that all standard input are always valid. Lines that start with a $ indicates a terminal command, which is an instruction you type into the terminal to run your program. Standard
inputs, which the user types into the terminal, are shown in bold.
This means you can assume the user will:
Always provide correct number of arguments when adding the song to the queue
Will provide the correct arguments for the song
Competency Requirements:
The test cases do not test that you meet all competency requirements. Please review the requirements
yourself even if you get a green tick. The green tick "mark" just checks if your code runs.
You can test your code as many times as you like before the submission deadline.Song queues (Part 2)
Write a program that mimics the queue functionality of a music app. The program should
allow users to reset, append or modify existing queues and create a new queue.
This is the second part of song queues where you will focus on implementing features that allow users
to remove songs and replace songs in a specific position in the queue.
You can copy over functions that you have already implemented from the previous parts
This question involves knowledge from the following Ed Lessons (but not limited to):
String formatting
IF statements
input() function
Containers (lists, tuples, and dictionaries)
Mutable and Immutable data
WHILE and FOR loops
Handling errors
Functions
CLASSES
You need to use all functions in part 1 and additional replace_song() and remove_song()
functions in this task in the main() function. Here we list high-level functionality, and later we
provide detailed specifications for each function.
As carries on from part 1, your program will still receive the username of the users via
command line arguments. If no command line arguments are given, print No username
found! and exit the programs.
After that, your program should prompt user to select the queue mode until receive a valid
input as stated in the first part.
You then need to initialise an empty list as a queue (Similar to part 1).
After successfully selecting the queue mode, your program should prompt for song input until
the user enter END QUEUE . The format input of song is exactly the same as stated in part 1,
except your program should also handle ( R ) remove and ( S ) replace as other argument options
for <operation> .
If the <operation> is R , you should be removing a song from the queue using the
remove_song() function.
If the <operation> is S , you should ask for the position of the song they want to replace with the message: Which position do you want to replace this song with? . You
should then be replacing a target song in the queue with the replacement song specified
via input using the replace_song() function.
Your program continue prompt, and then add/remove/replace until the user enters END QUEUE .
You then pass the list of Song objects to write_queue() function to write all songs in the
queue into the <username>_queue.txt file.
remove_song()
Parameters:
queue: list[Song] : list of Song objects
song: Song : The Song object to be removed from the queue.
The remove_song() function removes a specified song from the queue if the user inputs R for
<operation> .This function iterates through a list of Song objects to find the Song object that
matches the name and artist of the input. If no Song objects in the queue match these, prints ***No
'<song_name>' by <artist> found, cannot remove it*** . Otherwise, prints ***Successfully
removed '<song_name>' by <artist>*** .
If the queue mode is APPEND , you cannot remove song details that have already been written to the output
file. You can only remove songs that the user inputs in.
replace_song()
Parameters:
queue: list[Song] : list of Song objects
song: Song : The Song object to be moved into the queue.
position: str : The position of the song to be replaced in zero base-indexing given by the
user.
The replace_song() function replaces a specified song with another at a specified position. This
function will check if the input position is valid. If the specified position is valid, prints
***Successfully replaced '<song_name1>' by <artist1> to '<song_name2>' by <artist2>*** ,
where <song_name1> and <artist1> are the name and artist of the input song and <song_name2>
and <artist2> are the name and artist of the song that got replaced. The song that gets replaced will
be removed from the queue.
Otherwise, the replace operation will not occur, and a corresponding error message will be printed.
The order of error checking is as follows:
Not an integer: Prints ***Position must be an integer***
Negative integer: Prints ***Position must be at least 0***
Out of range of the queue: Prints ***The specified position is out of range of the queue***
If the queue mode is APPEND , you cannot replace song details that have already been written to the output
file. You can only replace with the songs that the user inputs in.
END-TO-END Examples
Example 1 - Create mode with Remove and Add operations
karencat_queue.txt does not exist before the program is run
Terminal output
$python3 queue.py karencat
No queue for karencat found! Creating a new queue...
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is added to the queue***
Update songs in the queue: A,Twinkle star,Layla Smiths,Kids,02:22
***'Twinkle star' by Layla Smiths is added to the queue***
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is already in the queue***
Update songs in the queue: X,Magnificient,Sasha Scarlet,Pop,04:23
***Invalid operation!***
Update songs in the queue: R,Magnificient,Sasha Scarlet,Pop,04:23
***Successfully removed 'Magnificient' by Sasha Scarlet***
Update songs in the queue: R,Magnetic,Hyper,KPop,04:23
***No 'Magnetic' by Hyper found, cannot remove it***
Update songs in the queue: R,Magnificient,Sasha Scarlet,Pop,04:23
***No 'Magnificient' by Sasha Scarlet found, cannot remove it***
Update songs in the queue: END QUEUE
karencat_queue.txt will be created after the program is run
Twinkle star,Layla Smiths,Kids,02:22
Example 2 - Append mode with Remove and Add operations
karencat_queue.txt before the program is runEspresso,Sabrina Carpenter,Pop,04:22
Ephemeral Dreamscape,Celestial Echoes,Rock,03:54
Terminal output
$python3 queue.py karencat
Do you want to reset or append to your queue? ApPEnD
Invalid mode!
Do you want to reset or append to your queue? APPED
Invalid mode!
Do you want to reset or append to your queue? aPPeND
Appending to your queue...
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is added to the queue***
Update songs in the queue: A,Twinkle star,Layla Smiths,Kids,02:22
***'Twinkle star' by Layla Smiths is added to the queue***
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is already in the queue***
Update songs in the queue: A,Beauty and the beast,Alena,Ballad,06:17
***'Beauty and the beast' by Alena is added to the queue***
Update songs in the queue: R,Do you want to build a snowman?,Elsa,Kids,03:14
***No 'Do you want to build a snowman?' by Elsa found, cannot remove it***
Update songs in the queue: R,Magnificient,Sasha Scarlet,Pop,04:23
***Successfully removed 'Magnificient' by Sasha Scarlet***
Update songs in the queue: END QUEUE
karencat_queue.txt after the program is run
Espresso,Sabrina Carpenter,Pop,04:22
Ephemeral Dreamscape,Celestial Echoes,Rock,03:54
Twinkle star,Layla Smiths,Kids,02:22
Beauty and the beast,Alena,Ballad,06:17
Example 3 - Create mode with Add and replace operations
karencat_queue.txt does not exist before the program is run
Terminal output
$python3 queue.py karencat
No queue for karencat found! Creating a new queue...Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is added to the queue***
Update songs in the queue: A,Twinkle star,Layla Smiths,Kids,02:22
***'Twinkle star' by Layla Smiths is added to the queue***
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is already in the queue***
Update songs in the queue: X,Magnificient,Sasha Scarlet,Pop,04:23
***Invalid operation!***
Update songs in the queue: A,Beauty and the beast,Alena,Ballad,06:17
***'Beauty and the beast' by Alena is added to the queue***
Update songs in the queue: S,Magnetic,Hyper,KPop,04:23
Which position do you want to replace this song with? 1
***Successfully replaced 'Twinkle star' by Layla Smiths to 'Magnetic' by Hyper***
Update songs in the queue: S,All by me,Jasper,KPop,05:34
Which position do you want to replace this song with? 10
***The specified position is out of range of the queue***
Update songs in the queue: S,All by me,Jasper,KPop,02:34
Which position do you want to replace this song with? ten
***Position must be an integer***
Update songs in the queue: S,All by me,Jasper,KPop,05:22
Which position do you want to replace this song with? -10
***Position must be at least 0***
Update songs in the queue: END QUEUE
karencat_queue.txt will be created after the program is run
Magnificient,Sasha Scarlet,Pop,04:23
Magnetic,Hyper,KPop,04:23
Beauty and the beast,Alena,Ballad,06:17
Example 4 - Append mode with replace and Add operations
karencat_queue.txt before the program is run
Espresso,Sabrina Carpenter,Pop,04:22
Ephemeral Dreamscape,Celestial Echoes,Rock,03:54
Terminal output
$python3 queue.py karencat
Do you want to reset or append to your queue? AppendAppending to your queue...
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is added to the queue***
Update songs in the queue: A,Twinkle star,Layla Smiths,Kids,02:22
***'Twinkle star' by Layla Smiths is added to the queue***
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is already in the queue***
Update songs in the queue: X,Magnificient,Sasha Scarlet,Pop,04:23
***Invalid operation!***
Update songs in the queue: A,Beauty and the beast,Alena,Ballad,06:17
***'Beauty and the beast' by Alena is added to the queue***
Update songs in the queue: S,Magnetic,Hyper,KPop,04:23
Which position do you want to replace this song with? 1
***Successfully replaced 'Twinkle star' by Layla Smiths to 'Magnetic' by Hyper***
Update songs in the queue: S,All by me,Jasper,KPop,05:34
Which position do you want to replace this song with? 10
***The specified position is out of range of the queue***
Update songs in the queue: S,All by me,Jasper,KPop,02:34
Which position do you want to replace this song with? ten
***Position must be an integer***
Update songs in the queue: S,All by me,Jasper,KPop,05:22
Which position do you want to replace this song with? -10
***Position must be at least 0***
Update songs in the queue: END QUEUE
karencat_queue.txt after the program is run
Espresso,Sabrina Carpenter,Pop,04:22
Ephemeral Dreamscape,Celestial Echoes,Rock,03:54
Magnificient,Sasha Scarlet,Pop,04:23
Magnetic,Hyper,KPop,04:23
Beauty and the beast,Alena,Ballad,06:17
Example 5 - Reset with all operations
karencat_queue.txt before the program is run
Espresso,Sabrina Carpenter,Pop,04:22
Ephemeral Dreamscape,Celestial Echoes,Rock,03:54Terminal output
$python3 queue.py karencat
Do you want to reset or append to your queue? reset
Resetting your queue...
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is added to the queue***
Update songs in the queue: A,Twinkle star,Layla Smiths,Kids,02:22
***'Twinkle star' by Layla Smiths is added to the queue***
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is already in the queue***
Update songs in the queue: A,Beauty and the beast,Alena,Ballad,06:17
***'Beauty and the beast' by Alena is added to the queue***
Update songs in the queue: R,Do you want to build a snowman?,Elsa,Kids,03:14
***No 'Do you want to build a snowman?' by Elsa found, cannot remove it***
Update songs in the queue: R,Magnificient,Sasha Scarlet,Pop,04:23
***Successfully removed 'Magnificient' by Sasha Scarlet***
Update songs in the queue: S,Starlight,Bobby,Pop,05:12
Which position do you want to replace this song with? 0
***Successfully replaced 'Twinkle star' by Layla Smiths to 'Starlight' by Bobby***
Update songs in the queue: END QUEUE
Output file karencat_queue.txt
Starlight,Bobby,Pop,05:12
Beauty and the beast,Alena,Ballad,06:17
Note: You can assume that all standard input are always valid. Lines that start with a $ indicates a
terminal command, which is an instruction you type into the terminal to run your program. Standard
inputs, which the user types into the terminal, are shown in bold.
Competency Requirements:
The test cases do not test that you meet all competency requirements. Please review the requirements
yourself even if you get a green tick. The green tick "mark" just checks if your code runs.
You can test your code as many times as you like before the submission deadline.Log of Changes
The changes will only contain reclarifications of description and inconsistencies in the docstring / type-hints.
We aim to have no changes to the actual code implementation.
The changes as of now is simply miscellaneous and very small. It would be faster to just copy and paste it over.
However, you may also click the ... and click Reset to Scaffold which will give you an up to date scaffold.
Ensure you first submit your code before resetting to scaffold with this so you can copy all your
implementation back over.
Extra Pinned Changes
Pinned Changes
20/09
3:20pm:
Changed the name of testcase "[Song] is_identical True and False (UNIT)" to "[Song] is_same True and
False (UNIT)" and fixed its bugs.
2:00pm:
Fixed the docstring for the parameter song of the function replace_song() , from "removed from"
to "moved into".
16/09
10:20am
Fixed the scaffold for song.py to fix misspelled method names and missing methods for exercises
after Song Informatiion. Please copy over your solution from Song Information to the song.py
files in the rest of the exercises.
10/09
6:00pm
The format specification of Top for print_wrapped_wall() in Music Wrapped (Part 2) was changed
from 6 characters to 8 characters to match the expected output for the test cases.3:00pm
The scaffold for Song.py was updated for all Song Queues to fix the constructor. Please copy over
your song.py file from previous exercises or just reset to scaffold to pull latest changes.
The condition in Song Queues (Part 1) if __name__ == '__main__' was fixed to include == instead
of = . You can fix this or just reset to scaffold to pull latest changes.
12:15pm
The scaffold for queue.py was updated for Song Queues (Part 2) to change the swap_song()
method to replace_song() as specified in the question description. Please rename the method to
pass test cases or just reset to scaffold to pull latest changes.
10:30am
The example and test cases were fixed to correct the spelling of logging .
$ python3 wrapped.py
Welcome to USYD MUSIC!
Enter your username: akali
Enter your password: dowhat12
Username and password do not match :((
Enter your username: aka
Enter your password: dowhat12kjk
No aka found :((
Enter your username: akali
Enter your password: idontknow
Username and password do not match :((
Maximum of 3 attempts has been reached. You will be temporarily disabled from logging in :((
09/09
10:30pm
The example snippets for print_wrapped_wall() had extra whitespaces after Stream Times for first
song and the test case was expecting 'MONTHLY MUSIC REWIND WALL' instead of 'MONTHLY MUSIC
WRAPPED WALL'. The examples and the test cases have now been fixed, please refresh the page to
remark and resubmit.
****************************************************
MONTHLY MUSIC WRAPPED WALL
****************************************************
Top Name Stream Times
Song Do you want to build a snowman 0020
Artist Elena Williams 0100Genre Pop 0193
****************************************************
Total streaming DD:HH:mm:ss
3:30pm
The scaffold for Song.py was updated for all exercises to change the has_same_duration() method
to get_longest() as specified in the question description. Please rename the method to pass test
cases or just reset to scaffold to pull latest changes.Code Review - In Week 9 Lab
Do not forget to turn up for your code review in the Week 9 Lab.
If you are unable to attend, you will need to apply for special consideration. For more details on the
相关推荐
告别Keil,用IAR for ARM 8.50.1从零搭建STM32F407工程(保姆级避坑指南)
本文详细介绍了如何从Keil迁移到IAR for ARM 8.50.1,搭建STM32F407工程的完整流程。涵盖工程结构转换、编译配置对比、调试器设置等关键步骤,提供实用的避坑指南和优化技巧,帮助开发者高效完成工具切换。
Unreal Basics Learning
Unreal Basics Learning
Python零基础到实战:环境配置、语法详解与42个常用命令
Python作为一门简洁高效的编程语言,其核心优势在于清晰的语法结构和丰富的生态系统。从基础语法概念入手,理解变量、数据类型和流程控制是掌握Python编程的关键。通过函数封装和面向对象编程,开发者能够构建可复用的代码模块,提升开发效率。在实际工程应用中,Python的环境配置、常用模块库的使用以及调试技巧都是必备技能。本文基于Python学习路径和实战项目开发需求,详细解析了从环境搭建到项目实战的完整流程,包含42个常用命令详解和多个实战项目源码,帮助开发者系统掌握Python编程。无论是零基础入门还是需
AIGC(生成式AI)试用 38 -- 辅助测试 Browser-use, Playwright
AIGC(生成式AI)试用 37 -- 辅助测试 Browser-use, Playwright
Agent应用实践之三十九 - OpenClaw:提示词
AI 大模型飞速进化,不懂 AI、不会用 Agent 的程序员,正在慢慢被行业淘汰。现在 AI 新技术迭代快到离谱:RAG 还没学明白,MCP 接踵而来;工具刚上手,Skills、各类新 Agent 概念又轮番刷屏;Manus还没看懂,就出来OpenClaw,OpenClaw热度还没退,又出来Hermes。越追越乱、越学越焦虑,永远在被动跟风,陷入学不完、跟不上、用不上的内耗。其实焦虑的根本原因,不是新技术太多,而是不懂大模型 Agent 应用底层原理,只会零散跟风,没有通用方法论。为此我专门推出Agent
【TC3xx芯片】TC3xx芯片电源管理系统PMS详解
本文主要介绍了TC3xx芯片的电源管理系统(PMS),重点探讨了供电模式选择、电源监控机制及电源管理模式。文章首先分析了4种供电模式及其硬件配置方式,详细说明了3.3V单电源供电模式的特点;其次阐述了Primary和Secondary两种电源监控机制,包括阈值配置和异常中断处理;最后重点讲解了CPU和系统的电源管理模式,特别对Standby模式及其进入/退出条件进行了详细说明。文章以软件开发视角解析了TC3xx芯片的电源管理功能,为ECU低功耗设计提供了技术参考。
打造专属音乐界面:3步定制Spotify字体与主题系统
厌倦了Spotify千篇一律的默认字体和单调界面?想要让歌词显示更加清晰、播放列表标题更具个性,打造完全属于自己的音乐播放体验?通过spicetify-cli这款强大的命令行工具,你可以轻松实现Spotify客户端的深度定制。本文将带你掌握字体自定义、主题系统配置和个性化界面优化的完整流程,无需编程基础,3步即可打造专属音乐界面。 ## 为什么需要个性化Spotify界面? Spotify作为
Windows 10 下 Nacos 3.0.2 单机版保姆级安装教程(含JDK 17配置与MySQL 8.0连接避坑)
本文提供Windows 10下Nacos 3.0.2单机版的详细安装教程,涵盖JDK 17配置、MySQL 8.0连接优化及生产级安全设置。通过步骤详解和常见问题解决方案,帮助开发者快速完成Nacos的安装与配置,确保服务发现与配置管理的高效运行。
Deep Agents 框架-基础篇
DeepAgents是LangChain生态中的高级API,构建于LangChain核心智能体模块和LangGraph运行时之上,旨在简化复杂智能体的开发。它提供任务规划、文件系统管理、子智能体生成等内置功能,适用于长期运行的多步骤任务。然而,DeepAgents并非独立框架,仍需依赖LangChain和LangGraph,学习成本较高。文档详细介绍了其核心能力、与LangChain/LangGraph的差异、配置方法及最佳实践,强调其在处理复杂任务时的优势,但也指出工程化选择需谨慎考虑其依赖关系和实际需求
c语言面试5(希诺麦田)
在 C 语言中,当使用strlen函数计算字符串的长度时,它会返回字符串中字符的实际个数,不包括字符串结束符’\0’。而sizeof(array)返回的是array指针所占用的字节数,通常在 32 位系统上为 4 个字节,在 64 位系统上为 8 个字节。在给定的代码中,array被初始化为"\0\0",其中包含两个转义字符’\0’。当使用strlen函数计算array的长度时,它会遇到第一个’\0’并停止计数,因此返回的长度为 2。12.下面四个选项是四个整数在内存中的存储情况,其中数值最大的一个是。
FPGA调试利器:VIO与ILA在Vivado中的实战应用指南
本文详细介绍了Vivado中FPGA调试工具VIO与ILA的实战应用技巧。VIO作为虚拟输入/输出工具,可实时调整参数;ILA作为集成逻辑分析仪,能高效捕获内部信号。文章通过具体案例展示了如何配置ILA采样深度、触发条件,以及VIO的动态参数调整功能,帮助开发者提升上板调试效率,解决常见通信失败、数据不同步等问题。
H2O-3 快速入门全指南:下载安装、Flow 可视化建模与 Python/R 实战起步
H2O-3 是一个开源的分布式内存机器学习平台,核心代码以 Java 实现,提供了 R、Python、Java、Scala 以及 Flow Web 界面等多套访问入口。本文以官方文档 [getting-started.rst](https://link.gitcode.com/i/0445e792f268a788b9d4a4357e4d3b17) 为主线,系统讲解从下载安装、使用 Flow 图形界
2026年数字IC设计禾赛科技笔试带答案解析
本文介绍了一份数字IC设计工程师笔试的试卷结构和部分题目解析。试卷包含15道单选题(30分)、10道填空题(20分)和5道简答/编程题(50分),总分100分,考试时长120分钟。单选题涉及同步时序电路、Verilog语法、跨时钟域设计、FPGA优化、存储器层次、功耗优化等知识点;填空题考查环形振荡器、工艺参数、时序约束、LUT结构等基础概念。试题重点考察应聘者对数字电路设计核心概念的理解和实际工程应用能力,特别是针对激光雷达芯片设计中的关键技术点进行考核。
3小时零基础Python入门:从环境搭建到实战项目完整指南
Python作为一种高级编程语言,以其简洁语法和强大功能成为科研和工程领域的首选工具。其核心原理基于解释器执行和动态类型系统,通过丰富的标准库和第三方模块实现快速开发。在技术价值方面,Python显著降低了编程门槛,提高了开发效率,特别适合数据处理和科学计算。应用场景涵盖Web开发、数据分析、人工智能等多个领域,其中深度学习研究对Python基础要求尤为突出。本文聚焦Python环境搭建、基础语法和实战项目,通过变量类型、流程控制等热词内容,帮助零基础学习者快速掌握编程核心概念,为后续技术进阶奠定坚实基础。
第95节:多模型多卡推理管理
多模型推理:在同一硬件平台上同时部署多个不同或相同的深度学习模型,满足多任务需求。多卡推理:利用多块 GPU 资源,提升推理吞吐量与并发能力。目标:合理分配 GPU 资源,实现高效、低延迟的推理服务。
用 SAP ABAP ALV 重塑 SM30:可扩展的自定义表维护视图与自动传输实践
文章摘要: 本文提出了一种基于ALV Grid的动态表维护框架,用于替代传统SM30维护视图。该方案通过输入表名自动生成维护界面,支持动态筛选、批量操作和自动传输管理。核心设计包括:利用BAdI实现扩展点、通过行状态字段简化数据变更跟踪、使用Style Table控制单元格编辑权限、集成CTS实现自动传输。相比SM30标准维护,该框架显著提升了交互体验(支持ALV排序/过滤/汇总)和业务扩展性(统一校验与权限控制),同时解决了"维护+传输"流程割裂的问题。文中详细阐述了技术实现方案,并提
Debian/Ubuntu 系linux操作系统Kali Linux 2026 里安装 Hermes Agent
Kali Linux 2026安装HermesAgent指南 环境准备:更新系统并安装基础工具(git、curl等)。 一键安装:推荐国内加速镜像(res1.hermesagent.org.cn),自动安装Python 3.11、Node.js 22等依赖,约3-5分钟完成。 验证与配置:执行hermes --version检查版本,运行hermes init配置模型提供商(如OpenRouter)及API Key。 启动服务:hermes start启动Agent,常用命令包括stop、restart及网
2万字大厂面经:小米嵌入式面试题及参考答案(持续更新)
BIOS (Basic Input/Output System) 是一种存储在ROM中的固件程序,它为计算机提供了最基础的硬件初始化和服务。BIOS主要存在于传统的x86架构计算机中。嵌入式系统的启动流程取决于具体的硬件平台和所采用的操作系统。复位阶段:当系统通电或复位时,CPU进入复位状态。硬件初始化:CPU和必要的硬件设备(如内存控制器)被初始化。加载引导加载程序:引导加载程序(如U-Boot)被加载到内存中。执行引导加载程序:引导加载程序开始执行,初始化更多的硬件设备,并检测存储介质。
liunx版本的
services:ports:volumes:network_mode: "host" # 添加此行(必须)kibana:ports:ELASTICSEARCH_HOSTS: http://192.168.1.145:9200 # 具体ip(必须)network_mode: "host" # # 添加此行(必须)
深度学习工具包 DeepLearningToolbox
深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[](https://bitdeli.com/free "Bitdeli Badge")
迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)
迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)
PHP - PHP-FPM - 学习/实践
本文摘要: 文章主要探讨了Nginx+PHP-FPM的运行机制、配置优化与实践应用。首先介绍了PHP-FPM作为PHP FastCGI进程管理器的工作原理,对比了CGI与FastCGI的区别,强调FastCGI通过主进程管理worker进程提升性能。详细解析了php-fpm.conf配置文件结构及核心参数,包括进程管理、日志设置等。同时展示了Nginx与PHP-FPM的协同配置,特别是虚拟主机多站点部署。文中还讨论了PHP-FPM的进程模型(master+worker)、平滑重启方法,以及常驻内存特性与Sw
IDEA的使用指南
IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.
(课程设计)nodeJS跳蚤市场网站-计算机毕设 附源码83381
普通用户管理模块: (1)用户注册登录:用户注册为普通用户并登录跳蚤市场网站;用户对个人信息的增删改查,比如个人资料,密码修改。 (2)用户查看商品:用户进行商品信息的阅览,通过发现喜欢的商品后可以购买+评论+收藏。 (3)商品资讯:用户进行资讯的阅览,查看管理者发布的商品资讯信息。 (4)商品购买:用户对喜欢的商品可以加购,在购物车里面,当用户确定提交完毕后,将其提交给服务器后台系统,并生成订单。 (5)我的订单:用户在提交订单后,可以对提交的订单进行管理。 管理员管理模块: (1)登录:管理员的账号是在
假人有限元模型
假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用
【课程设计】springboot定制化书籍销售系统-计算机设计毕业源码71193
随着电子商务的快速发展和图书市场的不断变革,定制化书籍销售系统的需求日益凸显。本文介绍了一种基于SpringBoot框架的定制化书籍销售系统的设计与实现。该系统旨在满足用户对于个性化、专业化的书籍需求,为用户提供高效、便捷的定制化购书体验。本文首先分析了当前图书销售市场的现状和挑战,阐述了定制化书籍销售系统的必要性和优势。随后,详细介绍了系统的整体架构、功能模块和技术实现方案。在架构设计上,系统采用了基于SpringBoot的MVC架构,实现了前后端分离,提高了系统的可维护性和可扩展性。
5分钟用 spicetify-cli 把 Spotify 客户端改造成你的专属播放器:换肤、增强歌词、自定义快捷键零门槛上手
晚上十点,你戴上耳机准备放松,打开 Spotify 准备听日语歌单。可盯着那套看了三年的绿色界面,心里总有点说不出的平淡;切到一首日文歌,歌词全是汉字假名,想跟唱却读不出音;想跳过一首口吐芬芳的歌,还得手动点下一首。这些"小别扭"凑在一起,就成了每天都要忍一遍的体验。 本文要介绍的 spicetify-cli,正是一款能一口气解决这些痛点的命令行定制工具。它是用 Go 编写的开源项目,专门用来改
基于Spring Boot与Vue的水果销售系统的设计与实现-计算机毕设 【课程设计】12720
前端注册用户模块: (1)注册登录:注册和登录是用户进入系统的门户,它们是用户与系统交互的首要步骤。注册功能允许新用户创建账户,而登录功能则允许已注册用户进入他们的个人空间。 (2)首页:首页是用户进入平台后首先看到的页面,它为用户提供了一个直观的界面,展示平台的核心内容和功能。首页包括水果资讯和水果商城的推荐商品。首页的设计吸引用户深入浏览,提供丰富的信息和便捷的入口,让用户能够快速找到他们感兴趣的内容或商品。 (3)公告信息:公告信息模块是平台与用户沟通的重要渠道,用于发布最新的平台通知、活动信息、政策
(课程设计)springboot手工艺品在线销售系统的设计与实现-计算机毕设 附源码 29217
注册用户模块 1.注册登录:用户可以通过注册和登录功能访问平台,浏览商品、下单购物、管理个人信息及订单。 2.首页:用户登录后可访问首页,查看推荐商品、通知公告、新闻资讯等内容。 3.通知公告:提供平台重要公告,展示系统运营相关的通知和活动信息。 4.新闻资讯:展示与手工艺品相关的最新新闻、行业动态和文化活动资讯。 5.艺品商城:用户可以浏览和购买不同类型的手工艺品,查看商品详情及价格。 6.商城管理:用户可以查看和管理自己的购物车、订单、收货地址等。 7.修改密码:用户可以修改账户密码,确保账户安全。
(课程设计)基于Spring Boot的社区生鲜配送管理系统的设计与实现-计算机毕设 附源码08610
注册用户功能分析: 登录注册:注册用户可以通过手机号、邮箱等信息完成账户的注册和登录。登录后,系统会根据用户的角色和权限展示相应的功能模块,保证了用户体验的个性化。 首页:为用户展示系统的核心内容,包括热销生鲜商品、促销活动、最新消息等。通过首页,用户能够快速了解商城动态,便于后续购物决策。 通知公告:系统通过通知公告模块向用户发布相关的系统信息、活动信息、服务更新等,确保用户能够及时了解平台的最新消息和变动。 新闻资讯:用户可以在平台上查看各类生鲜相关的新闻资讯,包括饮食健康、食材选择等内容,为用户提供有
397



被折叠的 条评论
为什么被折叠?



