Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

COMP1048, Databases and Interfaces: Coursework 2

Overview

Document Version History

Version

Date

Author

Description

1.0

1.1

05 December 2022

05 December 2022

Matthew Pike &

Yuan Yao

Matthew Pike &

Yuan Yao

Initial version for release.

For Task 3, Clarified

track_duration should not

accept numbers <=0.

Scenario

!  Fictional Scenario

Please note that this assignment is based on a fictional scenario.  The company is not real.

iMusic is a company that collects and sells physical vinyl records. Until recently, the company has been operating a physical shop in the city centre.  However, due to the COVID-19 pan- demic, the company has decided to close the shop and move to an online-only business model. The company wants to update their website accordingly.  They hired a professional developer to do this, but unfortunately the developer has been unable to complete the work due to other commitments. You have been hired to complete the work.

The company has provided you with a list of requirements for the website, which are described in the next section.  The website is partially implemented, and you will need to complete the implementation.

The website is implemented using the following technologies:

HTML, CSS, and Jinja2 for the front-end

Flask for the back-end

SQLite for the database

You must use these technologies to complete the assignment.   You must not use any other technologies.

Database Schema

The database is used to store the details of the vinyl records in the company’s inventory. The database consists of four tables:

•  Artist - Stores the name of each artist.  An artist is the person or group that created the music on the record.

Album - Stores the Title of each album and links to the artist that created the album.

•  Genre -  A  genre  is  a  category  that  describes  the  type  of  music  on  the  record.    For example, the genre of a record might be Rock” or Pop”.  This table stores the name of each available genre.

•  Track - Stores the details of each track on the record. Each track is linked to an album and a genre.

Figure 1 presents the Entity-Relationship (ER) diagram that shows the relationships between the tables.  Note, the developer has used a slightly different notation to the one used in the lectures. You must use you professional knowledge and experience to interpret the diagram.

Figure 1: ER diagram of the database schema. Note: PK = Primary Key, FK = Foreign Key.

The database schema is implemented in the file iMusic.db.  The database schema is imple- mented using the SQLite database engine.  You must use the iMusic.db database schema to complete the assignment. You may not change the database schema.

Tasks

Task 1: Fix Genre Names

Task Brief

In the process of developing the website, the developer made a mistake when inserting the Names of Genres into the database. Instead of inserting the actual genre names, the developer instead inserted the word Genre” for every genre in the database. You must fix this mistake by updating the database to contain the correct genre names.

The correct genre names are listed in genres.csv, a comma-separated values (CSV) file. The file contains a two columns of data:

genre_id - The ID of the genre.  This is the primary key of the Genre table.

genre_name - The correct name of the genre for the given ID.

Each row in the file contains the correct genre name for the given genre ID. You must use this file to update the database. genres.csv will only ever include the genre IDs that are currently in the database.  For this reason, you do not need to worry about inserting new genres into the database when writing your solution.

iMusic have asked you to write a Python script that will update the database.  The script must

be called fix_genres.py.  There are specific requirements that your script must meet:

•  The script must be able to be run from the command line using the command python fix_genres.py (or python3 fix_genres.py).

The script must read the genre names from a file named genres .csv.

•  The script should use the sqlite3 module to connect to the database and update the genre names.

•  The script should use the csv module to read the genre ids and names from the CSV file.  You are expected to read the documentation for the csv module to learn how to use it.

The script must not use any other modules.

Marking Criteria

Task 1 is worth 5 of the 25 marks available for the assignment. The following marking criteria will be used to assess your work:

ID

Requirement

Details

Marks

RQ1_1

Your solution makes correct use

of the csv module to parse the genres.csv file.

Your script must use the csv

module to read the genre ids and

names from the CSV file. You

should not write code to parse the CSV file yourself, you should use   the csv module to do this for you.

You are expected to read the

2

.

RQ1_2

RQ1_3

Your solution makes correct use

of the sqlite3 module to connect to the database and update all      the genre names.

The script can be run from the command line without error.

Your solution should not insert

any additional or incorrect data,   or marks will be deducted for this criteria.

Your script must be able to run

without additional input or            modification and handle any valid input files named genres.csv.

2

1

Task 2: Price Statistics Page

Task Brief

iMusic are keen to get an overview of the prices of the tracks in their collection.  They have asked you to finish the implementation of the Price Statistics” page. The page should display a table containing the following information:

•  Price - Each unique UnitPrice value in the database.  Each unique UnitPrice should only be listed once in the table.

# Tracks - The number of tracks in the database that have the given UnitPrice.

•  # Albums - The number of albums in the database that have at least one track with the given UnitPrice.

•  # Artists - The number of artists in the database that have at least one track with the given UnitPrice.

•  Duration -  The  total  duration  of  all  tracks  in  the  database  that  have  the  given UnitPrice.  The duration should be displayed in seconds format, rounded to the nearest integer.

•  Total Value -  The  total  value  of  all  Tracks  in  the  database  that  have  the  given UnitPrice. The value should be rounded two decimal places.

The  table  should  be  sorted  by  Price in  ascending  order.   Additionally,  your  table  should include a row at the bottom of the table that contains the following information:

Total - The word Totalshould be displayed in this cell.

# Tracks - An integer value representing the total number of tracks in the database .

•  # Albums - An integer value representing the total number of albums in the database, with at least one Track.

•  # Artists - An integer value representing the total number of artists in the database, with at least one Album.

•  Duration - The total duration of all tracks in the database.   The duration should be displayed in seconds format and rounded to the nearest second.

•  Total Value - The total value of all tracks in the database. The value should be rounded to two decimal places.

The final row of the table should be calculated from all the data available in the database.

You should not sum the values calculated for each UnitPrice (above), as this will introduce errors into the final result. An example of the output is shown in Figure 2.

Figure 2: A screenshot of an example output.

Users should be able to access the page by navigating to the /statistics/ URL. The func- tionality should be implemented in the file iMusic.py.  The previous developer has already implemented the template for the page in the file templates/statistics.html.  You must complete the implementation of the page by writing the Python code that will generate the table. You must not modify the template file.

Marking Criteria

Task 2 is worth 10 of the 25 marks available for the assignment. The following marking criteria will be used to assess your work:

Table 3: Marking Criteria for Task 2.

ID

Requirement

Details

Marks

RQ2_1

The page is accessible at the URL /statistics/

The page should be accessible at the URL /statistics/. If the

1

RQ2_2

The table contains all unique

UnitPrice values in the database.

page is not accessible at this       URL, you will lose all marks for this question.

The table should contain a row

for each unique UnitPrice value in the database

1

RQ2_3 RQ2_4

The table is sorted by Price in ascending order.

The table contains the correct

number of Tracks, Albums and Artists for each UnitPrice.

The table should be sorted by Price in ascending order.

The table should count the