Assignment 2 for the class CS60013 : Programming and Data Structures is due on 20th October 2022 23:59 IST. The assignment is worth 10% of the total marks for the course. Assignment submission is done via GitHub Classroom.
This assignment crafted by Vinay and Sai Pavan and approved by Prof Subhamoy Mandal.
- PDS Assignment 2
- Instructions
- Assignment 2 : Topics
- Task Allocation
- Tasks
- Task 1 : Recursive file text search
- Task 2 : Recursive math expression evaluation
- Task 3 : Recursive pattern printing
- Task 4 : Object Oriented Programming for Hospital Management System(HMS)
- Task 5 : Object Oriented Programming for Agriculture Management System(AMS)
- Task 6 : Object Oriented Programming for Class Management System(CMS)
- Task 7 : Collections and Sequences in Python : Application to Medical Transcriptions
- Task 8 : Collections and Sequences in Python : Application to ISBI 2022 Accepted Submissions
- Resources
- All the best!
- The assignment is to be done individually. You are
not allowed to collaborate
with other students. However, you areallowed
to the discuss the assignment with thecourse TAs
. - Each student is required to complete only 3 tasks as given in the Task Allocation table. The first 2 tasks are as designated and the third task is to be chosen from either Task 7 or Task 8.
- Tasks can be completed in any order. Partial credit will be given for completed tasks.
- The assignment submission is handled via GitHub Classroom.
- Late submissions will not be accepted.
Important
: More than 20% of code plagiarism will lead to 100% penalty without any further notice.
- The submissions will be evaluated based on the correctness of the code.
- A
partial
credit will be given for thecorrect
code that isnot complete
. - The
correctness
of the code will be evaluated based on theonline test cases
associated with the task. - Any
late
submission will be givenzero
credit.
- The assignment link will be shared via email.
- Clone the assignment repository to your local machine using the command
git clone <assignment-repo-link>
- Go to the assignment directory using the command
cd <assignment-repo-name>
- Open the assignment in your VS Code using the command
code .
- Read the instructions in the
README.md
file and start working on the assignment.
- The auto grading and test cases are only available for the Task 1, Task 2, Task 3, Task 7 and Task 8.
- All the object oriented programming tasks are not auto graded. You have to test your code manually. You can do it as far as you can.
- Whoever assigned with the Task 1, Task 2, Task 3, Task 7 and Task 8 should follow the auto grading instructions.
- For auto graded questions your code will be tested against the online test cases. For this to work your code should produce the expected output in the format as specified in the test cases and example outputs.
-
Test your code using the
test cases
provided in thetests/
directory. -
To run the test cases, use the command with
python
orpython3
depending on your system configuration. This command should be run from the assignment root directory.python -m unittest tests/<test_case_file_name>.py
-
Commit your changes to the local repository using the command
git add . git commit -m "<commit-message>"
-
Push your changes to the remote repository using the command
git push
-
Repeat steps 3 and 4 until you are done with the assignment.
The deadline for the assignment is 20th October 2022, 23:59 IST. No late submissions will be accepted.
Recursion
Sequences
[Lists, Tuples, Strings, Dictionaries, Sets]Iteration
andComprehensions
Classes
andObjects
- The task is to recursively search for all emails in a given directory tree.
- The given directory tree is a directory containing sub-directories and files.
- The text files in the directory tree may contain emails.
- Recursively search for all emails in the directory tree.
- The emails should be returned as a list of strings in alphabetically sorted order.
- Complete the function
get_emails_recursive
inrecursive_text_search.py
file. - The recursion can be either functional or iterative. Better to use
iterative recursion
. - Directory tree :
data/emails/
- Output : Return a
list of emails(without duplicates) in alphabetically sorted order
- This task is auto-graded. Check the correctness of your code before submission.
- The task is to recursively evaluate a math expression given as a string.
- Complete the function
evaluate_mathexp
inrecursive_mathexp_eval.py
file. - Math expression will only contain +, -, *, /, ^, (, ) and integers.
- All the math operations are to be performed as per the order of precedence (PEMDAS) or (BODMAS).
- Examples
- Example 1 :
evaluate_mathexp("2+3*4")
should return14
- Input : "2+3*4"
- Output : 14
- Reasoning : 2+3*4 => 2+12 => 14
- Example 2 :
evaluate_mathexp("2+3*4^2")
should return50
- Input : "2+3*4^2"
- Output : 50
- Reasoning : 2+3* 4^2 => 2+3*16 => 2+48 => 50
- Example 1 :
- The recursion can be either functional or iterative.
- This task is auto-graded. Check the correctness of your code before submission.
-
The task is to implement the function
print_pattern
inrecursive_pattern.py
file. -
Function takes two arguments: x and n both are integers
-
Note 1 : Along with the printing pattern, the function should also return
x^n
-
Strip any leading and trailing spaces from the pattern.
-
Examples:
- Example 1:
Input
: x = 2, n = 2Returns
: 4Prints
:
- Example 1:
y^2*-z^2*-b^2*-a^3*-b^2*-z^2*-y^2 x^4*-y^4*-z^4*-c^4*-b^4*-a^5*-b^4*-c^4*-z^4*-y^4*-x^4
- Example 2:
Input
: x = 3, n = 3Returns
: 27Prints
:
y^3*-z^3*-b^3*-a^4*-b^3*-z^3*-y^3 x^9*-y^9*-z^9*-c^9*-b^9*-a^10*-b^9*-c^9*-z^9*-y^9*-x^9 w^27*-x^27*-y^27*-z^27*-d^27*-c^27*-b^27*-a^28*-b^27*-c^27*-d^27*-z^27*-y^27*-x^27*-w^27
- Example 3:
Input
: x = 5, n = 3Returns
: 125Prints
:
y^5*-z^5*-b^5*-a^6*-b^5*-z^5*-y^5 x^25*-y^25*-z^25*-c^25*-b^25*-a^26*-b^25*-c^25*-z^25*-y^25*-x^25 w^125*-x^125*-y^125*-z^125*-d^125*-c^125*-b^125*-a^126*-b^125*-c^125*-d^125*-z^125*-y^125*-x^125*-w^125
- Example 4:
Input
: x = 3, n = 5Returns
: 243Prints
:
y^3*-z^3*-b^3*-a^4*-b^3*-z^3*-y^3 x^9*-y^9*-z^9*-c^9*-b^9*-a^10*-b^9*-c^9*-z^9*-y^9*-x^9 w^27*-x^27*-y^27*-z^27*-d^27*-c^27*-b^27*-a^28*-b^27*-c^27*-d^27*-z^27*-y^27*-x^27*-w^27 v^81*-w^81*-x^81*-y^81*-z^81*-e^81*-d^81*-c^81*-b^81*-a^82*-b^81*-c^81*-d^81*-e^81*-z^81*-y^81*-x^81*-w^81*-v^81 u^243*-v^243*-w^243*-x^243*-y^243*-z^243*-f^243*-e^243*-d^243*-c^243*-b^243*-a^244*-b^243*-c^243*-d^243*-e^243*-f^243*-z^243*-y^243*-x^243*-w^243*-v^243*-u^243
- This task is a bit tricky. So, try to understand the pattern and then implement the function.
- This task is auto-graded. So, make sure you are returning the correct value and printing the correct pattern.
- The task is to implement a the classes
Hospital
,Patient
andDoctor
inhms_classes.py
file. - The Hospital class should have the following attributes and methods:
name
: Name of the hospitaldoctors
: List of doctor objects in the hospitalpatients
: List of patient objects in the hospitaladd_doctor
: Add a doctor to the hospitaladd_patient
: Add a patient to the hospitalget_doctor
: Get a doctor from the hospitalget_patient
: Get a patient from the hospitalget_doctors
: Get all the doctors from the hospitalget_patients
: Get all the patients from the hospitalget_doctors_count
: Get the number of doctors in the hospitalget_patients_count
: Get the number of patients in the hospital
- The Patient class should have the following attributes and methods:
id
: Auto generated IDname
: Name of the patientage
: Age of the patientgender
: Sex of the patient
- The Doctor class should have the following attributes and methods:
id
: Auto generated IDname
: Name of the doctorspecialization
: Specialization of the doctorpatients
: List of patients assigned to the doctoradd_patient
: Add a patient to the doctorget_patient
: Get a patient from the doctorget_patients
: Get all the patients from the doctorget_patients_count
: Get the number of patients assigned to the doctor
- The
id
attribute of the Patient and Doctor class should be auto generated. - Implement the
__str__
method for theHospital
,Patient
andDoctor
classes. - Demonstrate the use of implemented classes by creating a hospital object and adding doctors and patients to it.
- The demo driver code should make use of all the implemented methods of the classes.
- This task has no test cases. You can test your code by running the
hms_classes.py
file. - This task will not be auto-graded.
- The task is to implement a the classes
Farm
,Crop
,Farmer
and inams_classes.py
file. - The Farm class should have the following attributes and methods:
name
: Name of the farmcrops
: List of crop objects in the farmfarmers
: List of farmer objects in the farmadd_crop
: Add a crop to the farmadd_farmer
: Add a farmer to the farmget_crop
: Get a crop from the farmget_farmer
: Get a farmer from the farmget_crops
: Get all the crops from the farmget_farmers
: Get all the farmers from the farmget_crops_count
: Get the number of crops in the farmget_farmers_count
: Get the number of farmers in the farm
- The Crop class should have the following attributes and methods:
id
: Auto generated IDname
: Name of the croptype
: Type of the cropfarmers
: List of farmers assigned to the cropadd_farmer
: Add a farmer to the cropget_farmer
: Get a farmer from the cropget_farmers
: Get all the farmers from the cropget_farmers_count
: Get the number of farmers assigned to the crop
- The Farmer class should have the following attributes and methods:
id
: Auto generated IDname
: Name of the farmerage
: Age of the farmer
- The
id
attribute of the Crop and Farmer class should be auto generated. - Implement the
__str__
method for the Farm, Crop and Farmer classes. - Demonstrate the use of implemented classes by creating a farm object and adding crops and farmers to it.
- The demo driver code should make use of all the implemented methods of the classes.
- This task has no test cases. You can test your code by running the
ams_classes.py
file. - This task will not be auto-graded.
- The task is to implement a the classes
Class
,Student
andTeacher
incms_classes.py
file. - The Class class should have the following attributes and methods:
name
: Name of the classstudents
: List of student objects in the classteachers
: List of teacher objects in the classadd_student
: Add a student to the classadd_teacher
: Add a teacher to the classget_student
: Get a student from the classget_teacher
: Get a teacher from the classget_students
: Get all the students from the classget_teachers
: Get all the teachers from the classget_students_count
: Get the number of students in the classget_teachers_count
: Get the number of teachers in the class
- The Student class should have the following attributes and methods:
id
: Auto generated IDname
: Name of the studentage
: Age of the student
- The Teacher class should have the following attributes and methods:
id
: Auto generated IDname
: Name of the teacherage
: Age of the teacherstudents
: List of students assigned to the teacheradd_student
: Add a student to the teacherget_student
: Get a student from the teacherget_students
: Get all the students from the teacherget_students_count
: Get the number of students assigned to the teacher
- The
id
attribute of the Student and Teacher class should be auto generated. - Implement the
__str__
method for the Class, Student and Teacher classes. - Demonstrate the use of implemented classes by creating a class object and adding students and teachers to it.
- The demo driver code should make use of all the implemented methods of the classes.
- This task has no test cases. You can test your code by running the
cms_classes.py
file. - This task will not be auto-graded.
-
The task is to implement the set of functions in
medical_transcription.py
file. -
These functions are to be used to process the medical transcriptions in
data/mtsamples.csv
file. -
This task is heavily oriented towards the use of collections and sequences in Python. Use the most appropriate collections and sequences as possible.
-
For working with the CSV file, you can use the
csv
module in Python or thepandas
module.pandas
doesn't come pre-installed with Python. You can install it usingpip install pandas
command. -
In this task you will be implementing the following functions:
get_medical_specalities
- Implement the function
get_medical_specalities
inmedical_transcription.py
file. - This function should return a list of all the medical specialties from the
medical_specialty
column in thedata/mtsamples.csv
file. The list should not contain any duplicates. The list should be sorted in alphabetically ascending order. - Check the expected output in the
tests/transcription_outputs/get_medical_specalities.txt
file.
- Implement the function
get_medical_specialities_count
- Implement the function
get_medical_specialities_count
inmedical_transcription.py
file. - This function should return a dictionary of all the medical specialties from the
medical_specialty
column in thedata/mtsamples.csv
file. The dictionary should have the medical specialty as the key and the number of times it occurs as the value. The dictionary should be sorted in descending order of the number of times the medical specialty occurs. - Check the expected output in the
tests/transcription_outputs/get_medical_specialities_count.txt
file.
- Implement the function
get_medical_speciality_sample_names
- Implement the function
get_medical_speciality_sample_names
inmedical_transcription.py
file. - This function should return a dictionary of all the medical specialties from the
medical_specialty
column in thedata/mtsamples.csv
file. The dictionary should have the medical specialty as the key and the list of sample names as the value. The dictionary should be sorted in alphabetically ascending order of the medical specialty. - Check the expected output in the
tests/transcription_outputs/get_medical_speciality_sample_names.txt
file.
- Implement the function
-
This task is auto-graded. Run the test cases and check the correctness of your code.
-
The task is to implement the set of functions in
isbi2022.py
file. -
These functions are to be used to process the ISBI 2022 accepted submissions in
data/isbi2022.csv
file. -
The given dataset
data/isbi2022.csv
file is a scrapped dataset from the ISBI 2022 accepted submissions page. Each record in the dataset represents a paper that has been accepted for presentation at ISBI 2022. Each record will have the following attributes:citationCount
: Number of citations for the paperarticleTitle
: Title of the paperdownloadCount
: Number of times the paper has been downloadedauthors
: List of authors of the paper
-
There are other attributes in the dataset. You can explore them on your own. The dataset conists of 313 records.
-
This task is heavily oriented towards the use of collections and sequences in Python. Use the most appropriate collections and sequences as possible.
-
For working with the JSON file, you can use the
json
module in Python. -
In this task you will be implementing the following functions:
-
get_authors
- Implement the function
get_authors
inisbi2022.py
file. - This function should return a dictionary of all the unique authors from the given dataset and the number of times they have appeared in the dataset. The dictionary should be sorted in descending order of the number of times the author has appeared in the dataset.
- Check the expected output in the
tests/isbi2022_outputs/get_authors.json
file.
- Implement the function
-
get_titles
- Implement the function
get_titles
inisbi2022.py
file. - This function should return a dictionary of all the titles as the key and the sum of the
citationCount
anddownloadCount
as the value. The dictionary should be sorted in descending order of the sum of thecitationCount
anddownloadCount
. - Check the expected output in the
tests/isbi2022_outputs/get_titles.json
file.
- Implement the function
-
get_word_cloud
- Implement the function
get_word_cloud
inisbi2022.py
file. - This function should return a dictionary of all the words in the
articleTitle
attribute as the key and the number of times the word has appeared in thearticleTitle
attribute as the value. The dictionary should be sorted in descending order of the number of times the word has appeared in thearticleTitle
attribute. - Check the expected output in the
tests/isbi2022_outputs/get_word_cloud.json
file.
- Implement the function
-
-
This task is auto-graded. Run the test cases and check the correctness of your code.