When writing and submitting your assignments follow these requirements:
Name your Eclipse project with your Network login, an underscore, 'a' (for
'assignment', then the assignment number: login_en.zip
.
For example, if the user barn4520
submits Assignment 1, the
name should be: barn4520_a01
. Give your .zip file the same
name when exporting your project. The project above would be exported in a
.zip file named barn4520_a01.zip
. Use only Eclipse's built-in
archive capability to create these .zip files. No other format will be
accepted.
Some assignments consist of multiple Eclipse projects where one project
references another. Use the same naming scheme for all your projects.
Thus, a project named data_structures
should be barn4520_data_structures
.
Test your programs thoroughly - show us how it works. Copy the outputs
from your testing to a file in your Eclipse/Pydev project named testing.txt
.
Make sure the tests are well labelled so that the markers know which
program the results represent.
There should be no errors or warnings in your code. Watch out particularly for bad or unused imports - these generate warnings and must be removed.
If you are asked to provide discussion put this discussion in your
Eclipse/Pydev project in a file named discussion.txt
.
Put all your programs, testing, and discussion files into one Eclipse/Pydev project.
Zip the entire project using Eclipse and submit the resulting .zip file through MyLearningSpace.
Marks will be deducted from any questions where these requirements are not met.
Follow the assignment instructions to the letter (e.g. name the function
module functions.py
), as this assignment is auto-graded. If
your Eclipse project is not defined correctly, the auto-grading fails, and
your assignment will be given a mark of 0.
Pages of use for this assignment:
These questions use the DCRIS database.
These functions return lists of tuples containing the results of the
various database calls. How you display these results is up to you. Do not
call print
from within the functions. Do not close the
database from within the functions. It is the responsibility of whatever
opens the database to close the database.
Write and test the following function:
def get_broad(cursor, broadId=None):
"""
-------------------------------------------------------
Queries the broad table.
Use: rows = get_broad(cursor)
Use: rows = get_broad(cursor, broadId=v)
-------------------------------------------------------
Parameters:
cursor - a database cursor (cursor)
broadId - a broad ID (int)
Returns:
rows - (list of broad table data)
if broadId is not None:
rows matching broadId
else:
the entire broad table
Sorted by broad description
-------------------------------------------------------
"""
Add this function to the PyDev module functions.py
. Test
it from .
This function uses a Python feature known as named arguments. Function arguments may be given default values. If the function is called without the argument, that argument is given its default value. These arguments can be listed in any order by using their names.
In this function the default value None
is given to the
parameter broadId
by the definition line:
def get_broad(cursor, broadId=None):
The documentation for this function show two versions of Use::
Use: rows = get_broad(cursor)
instructs Python to accept the first parameter cursor
as
passed in, and sets broadId
to its default value None
.
The second version:
Use: rows = get_broad(cursor, broadId=v)
instructs Python to accept the first parameter as above, and then
assign the value v
to the broadId
parameter.
Your code clearly must decide what to do when broadId
is None
and otherwise.
Note that you have used named arguments to functions before, although we didn't call them that. Two examples:
print(value, end="")
fv = open(filename, encoding="utf-8")
Write and test the following function:
def get_publications(cursor, memberId=None, pubPubType=None):
"""
-------------------------------------------------------
Queries the pub table.
Use: rows = get_publications(cursor)
Use: rows = get_publications(cursor, memberId=v1)
Use: rows = get_publications(cursor, pubPubType=v2)
Use: rows = get_publications(cursor, memberId=v1, pubPubType=v2)
-------------------------------------------------------
Parameters:
cursor - a database cursor (cursor)
memberId - a member ID number (int)
pubPubType - a publication type (str)
Returns:
rows - (list of pub table data)
if memberId and/or pubPubType are not None:
rows matching memberId and/or pubPubType
else:
the entire pub table
Sorted by publication title
-------------------------------------------------------
"""
Add this function to the PyDev module functions.py
. Test
it from .
Write and test the following function:
def get_member_broad(cursor, memberId=None, broadId=None):
"""
-------------------------------------------------------
Queries the vMemberBroad view.
Use: rows = get_member_broad(cursor)
Use: rows = get_member_broad(cursor, memberId=v1)
Use: rows = get_member_broad(cursor, broadId=v2)
Use: rows = get_member_broad(cursor, memberId=v1, broadId=v2)
-------------------------------------------------------
Parameters:
cursor - a database cursor (cursor)
memberId - a member ID number (int)
broadId - a broad ID number (int)
Returns:
rows - (list of vMemberBroad view data)
if memberId and/or broadId are not None:
rows matching memberId and/or broadId
else:
the entire vMemberBroad view
Sorted by member last name, first name, and broad description
-------------------------------------------------------
"""
Add this function to the PyDev module functions.py
. Test
it from .
Write and test the following function:
def get_expertises(cursor, broad=None, narrow=None):
"""
-------------------------------------------------------
Queries the vBroadNarrow view.
Use: rows = get_expertises(cursor)
Use: rows = get_expertises(cursor, broad=v1)
Use: rows = get_expertises(cursor, narrow=v2)
Use: rows = get_expertises(cursor, broad=v1, narrow=v2)
-------------------------------------------------------
Parameters:
cursor - a database cursor (cursor)
broad - a partial broad expertise description (str)
narrow - a partial narrow expertise description (str)
Returns:
rows - (list of vBroadNarrow view data)
if broad and/or narrow are not None:
rows containing broad and/or narrow
else:
the entire vBroadNarrow view
Sorted by broad description, narrow broad description
-------------------------------------------------------
"""
Add this function to the PyDev module functions.py
. Test
it from .