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

School of Computing: Assessment brief

Module title

Introduction to Programming

Module code

XJCO1012

Assignment title

Coursework 2

Assignment type and description

In-course assessment

Rationale

Writing python programs based on specifications

Word limit and

guidance

This coursework should take less than 10 hours to complete

Weighting

60%

Submission deadline

14/12/2023

Submission method

Online through Gradescope

Feedback provision

Rubric and comments on Gradescope, 3 weeks after submission deadline

Learning outcomes assessed

LO1: Select and use appropriate data and control structures for a given problem.

LO2: Use Python to implement a solution to a given problem.

LO3: Use JavaScript to perform simple tasks.

Module lead

Hui Lau

Other Staff contact

Zhen Jia


1. Assignment guidance

You are required to implement a diabetes.py module and JavaScript functions in morsecode.html.

A.       Preparation

Please follow the following instructions:

1.  Download the zip file cwk2-files.zip from Minerva.

2.  Unzip cwk2-files.zip and put these files in a folder/directory.  You should have the file  diabetes.py, diabetes_data.csv, diabetes2_data.csv, diabetes3_data.csv, and morsecode.html.

3.  Write your python code in the template file diabetes.py and morsecode.html. Write your name (whichever version you prefer) or university username at the top of the file indicated by @author. This is important for documentation and a good programming practice. You may

be penalised if you are not able to follow simple instructions.

You are NOT ALLOWED to import other modules for this coursework.

2. Assessment tasks

Task 1: basic tasks

1    diabetes.py module (30 marks)

You are required to implement a Diabetes class to read data from a specific diabetes-related csv    file with methods to process data from that file. All diabetes-related csv files have the same structure with the first two columns as Age and Gender, and the last column as the classification class, either Positive or Negative. All other columns are specific attributes. Figure 1 and Figure 2 are examples of the content in diabetes-related csv files.

Figure 1: Diabetes-related csv file with 17 columns.

 

Figure 2: Diabetes-related csv file with 10 columns.



Given a module template file called diabetes.py with a class called Diabetes, implement the  following methods. You should create appropriate attributes. For this question, you are only allowed to import the csv module.

1.1       init   (self, filepath: str)-> None (5 marks)

This method reads in a diabetes-related csv file, specified by filepath, and assigns data in

header to an instance variable, and the remaining data to another instance variable. Write codes to raise exception for file not found error (FileNotFoundError).

1.2  get_dimension(self) -> list (3 marks)

This method returns the dimensions of the data in the csv file as a list (excluding the header), in the format [row, column]. You should consider using the instance variable(s) from Task 1.1.

1.3  web_summary(self, filepath: str) -> None (12 marks)

This method generates an html file, specified by the filepath parameter, cointaining an HTML table. The table summarises the total count of Yes and No values for attributes other than Age and

Gender, based on the  classification (Positive or Negative) for the data in Task 1.1. Figure 1 is an

example on how the table could be presented. You can present a basic html table or enhance it with a more professional appearance, including features like centralised text, different fonts, cell colour,   and more.

Figure 1: HTML table with total count for the values in each attribute for Positive and Negative classes.

1.4  count_instances(self, criteria, ...) -> int (10 marks)

This method returns the count of instances that meet specific search criteria. You are to decide the data type for criteria and the number of arguments to this method. This is a task to test YOUR

ability to decide on appropriate data type to use. For example, if we consider a csv file with columns Age, Gender, Itching, Obesity, and weakness, the criteria could be specified as Age=20,

Gender="Male" or according to the data type format that you have chosen. The search criteria should accommodate any number of columns. You have to decide how these criteria should be

passed and accepted as argument(s) in the method. You also need to write detailed docstring documentation enclosed in triple quotes that explains with examples how to use this method   effectively.



2         JavaScript (25 marks)

Modify the JavaScript function encdec()in morsecode.html to encode/decode Morse

code/string in the (first) textarea with id="input", based on the selection box. When the submit button is clicked, the encoded/decoded Morse code is displayed in the (second) textarea with

id="output" as shown in Figure 2. You can create other functions to be used within the function encdec().

Figure 2 (a) encode a string to Morse code (b) decode a Morse code to string

Each character converted to Morse code is spaced with a blank space, except the last character. The following mcode object is provided.

mcode = {

'A': '.-',   'B': '-...', 'C': '-.-.', 'D': '-..',   'E': '.',

'F': '..-.', 'G': '--.',  'H': '....', 'I': '..',    'J': '.---',

'K': '-.-',  'L': '.-..', 'M': '--',   'N': '-.',    'O': '---',

'P': '.--.', 'Q': '--.-', 'R': '.-.',  'S': '...',   'T': '-',

'U': '..-',  'V': '...-', 'W': '.--',  'X': '-..-',  'Y': '-.--',

'Z': '--..', ' ': ' ',    '0': '-----','1': '.----', '2': '..---',

'3': '...--',  '4': '....-',  '5': '.....',  '6': '-....',

'7': '--...',  '8': '---..',  '9': '----.',  '&': '.-...',

"'": '.----.', '@': '.--.-.', ')': '-.--.-', '(': '-.--.',

':': '---...', ',': '--..--', '=': '-...-',  '!': '-.-.--',

'.': '.-.-.-', '-': '-....-', '+': '.-.-.',  '"': '.-..-.',

'?': '..--..', '/': '-..-.'

}

The table below shows strings and encoded Morse codes. For input with invalid characters, except a space, prompt an alert with “Invalid input” as shown in Figure 3. Pay attention to the spaces between characters converted to Morse code.

Examples

String            Morse code

Hello world!

 

 

 

For clarity, the code above is illustrated below where x is a space ....x.x.-..x.-..x---xx.--x---x.-.x.-..x-..x-.-.--

 

H

 

e  

l

 

l

 

o

 

 

w

 

o

 

r

 

l

 

d

 

!

....

 

.

-

. ..

 

-

. ..

 

---

 

 

--

.

 

---

 

-

. .

 

-

. ..

 

-

..

 

- - --

. .

 

morse code

-- ---  -         - -  --- -

. . ... .   . .       .. .



 

--x---x.-.x...x.xx-.-.x---x-..x.

IT'S A

BEAUTIFUL WORLD

-  ----        -  -       -   - -      -    -  -     -- ---  -   -   -

..   .     . ...  .    ... . .   ..      .. ..  . ..   .  ..   .          .  .  . ..   ..

 

..x-x.----.x...xx.-xx-...x.x.-x..-x-x..x..-.x..-x.-..xx.--x---x.-.x.-..x-..

a

-

.

$

Alert Invalid input

Morse$code

Alert Invalid input

Figure 3: Invalid character $ in the input string to encode.

3. General guidance and study support

Developing your academic skills will enable you to become a more effective learner. Online

resources on critical thinking, reading, academic writing and more can be found at Skills@Library website at https://library.leeds.ac.uk/info/1401/academic_skills#minerva.

4. Assessment criteria and marking process

When you submit work for assessment it is expected that it will meet the University’s academic integrity standards. Standard university penalty of 5% of available marks per day, or part of a day, will apply to late work. Late submissions are acceptable up to 7 days late. Feedback on late submissions may not be provided within 3 weeks of submission deadline.

5. Presentation and referencing

You are NOT ALLOWED to import modules for this coursework. Comments and conformance to PEP 8, and code modularity will be marked.

6. Submission requirements

You only need to submit the python files to Gradescope. Please do not submit any other files and do not change the filename. Make sure you have tested the  python files  with no errors. Please download your submission and check if they are they contain correct files and that they are not corrupted.


7. Academic misconduct and plagiarism

Academic integrity means engaging in good academic practice. This involves essential academic skills, such as keeping track of where you find ideas and information and referencing these accurately in your work.

By submitting this assignment you are confirming that the work is a true expression of your own work and ideas and that you have given credit to others where their work has contributed to yours.

8. Assessment/ marking criteria grid

diabetes.py

__init__ () with no errors (instance variables for header and data, exceptions for empty file and file not found)

get_dimension() with no errors for valid csv file

web_summary() (generated html file, correct values, formatted table)   count_instances() (data typeselection, correct results, exceptions, docstrings)

PEP 8 coding style and comments

5

3

12

10

5

morsecode.html

Encoding (single character, multiple characters, number of blank spaces, invalid input)

Decoding (single character, multiple characters, number of blank spaces, invalid input)

Coding style and comments

12.5

12.5

5

 

Total

65