11/30/22, 9:36 PM Programming Project 2
https:
uwwtw.instructure.com/courses/497799/assignments/ XXXXXXXXXX/7
Programming Project 2
Due Dec 14 by 11:59pm Points 80 Submitting a website url or a file upload
File Types s, scm, rkt, py, and zip Available Nov 21 at 12am - Dec 14 at 11:59pm
Start Assignment
Objectives
Practice writing slightly more complex Python and Scheme programs
Use higher-order functions in a program
Write programs that process data recursively
Instructions
For this programming project, you will solve one programming problem in Python and in Scheme. You
may need to write multiple functions to solve the problem in each language. Each program will be worth
40 points, for a total of 80 points.
You will need to submit one Scheme file and one Python file with solutions to both problems. You can
package them inside of a .zip file or upload them separately: it's your choice.
Problem overview
Many kinds of data analysis involve the following high-level steps.
1. Open a database or some other collection of data.
2. Extract data from the database that satisfy certain criteria.
3. Apply a processing operation to the data that were extracted in step 2.
In this project, you will write Scheme and Python code to do these steps. Importantly, you will write this
code in a flexible way that uses higher-order functions in both languages. We will focus on using both
languages' built-in map and filter functions, which apply other functions to produce results quickly and
predictably—and without writing loops.
This style of programming has become common in Web apps and other settings. Code that interacts
with "Web APIs" or REST services will often rely on this model. In fact, JavaScript provides map and
filter functions that work like their Python and Scheme equivalents.
11/30/22, 9:36 PM Programming Project 2
https:
uwwtw.instructure.com/courses/497799/assignments/ XXXXXXXXXX/7
Data set
Download the data set. (https:
uwwtw.instructure.com/courses/497799/files/ XXXXXXXXXX?wrap=1)
(https:
uwwtw.instructure.com/courses/497799/files/ XXXXXXXXXX/download?download_frd=1)
Hint: The column labels are long! The Canvas preview does not show the full column labels. To
see the full column labels, open the CSV file in a text editor or expand the columns in Excel/Google
Sheets/Li
eOffice Calc.
This data set is in CSV format, where each record (line) contains the following fields in this order.
Each field's expected data type is in parentheses. However, the CSV reader will store everything as a
string within the dictionary (Python) or association list (Scheme) for each customer. Use you
language's type-conversion functions when (or if) they are needed.
First Name (string of any length)
Last Name (string of any length)
Postal Code (string; not an integer)
Country (2-character string)
Items Ordered This Month (integer)
Items Ordered Total (integer)
Amount To Pay ("float" in Python, "decimal" or "real" in Scheme)
Due Date (integer)
For easier processing, dates will be encoded in a modified ISO 8601
(https:
en.wikipedia.org/wiki/ISO_8601) format as integers.
Examples: May 7, 2019 would be encoded as XXXXXXXXXXOctober 24, 2021 would be encoded as
XXXXXXXXXX.
This means that later dates are always "greater" than earlier dates.
The first row of this CSV file is a header row, which contains labels but no data. My CSV reader code will
handle the header row for you.
To simplify the problem, you can assume that the data set is well-formed, meaning here that every field
of every record contains the expected type of data.
Starter files
Begin each version of your code with these starter files.
Python starter file for Project 2 (https:
uwwtw.instructure.com/courses/497799/files/ XXXXXXXXXX?
wrap=1) (https:
uwwtw.instructure.com/courses/497799/files/ XXXXXXXXXX/download?download_frd=1) .
https:
uwwtw.instructure.com/courses/497799/files/ XXXXXXXXXX?wrap=1
https:
uwwtw.instructure.com/courses/497799/files/ XXXXXXXXXX/download?download_frd=1
https:
en.wikipedia.org/wiki/ISO_8601
https:
uwwtw.instructure.com/courses/497799/files/ XXXXXXXXXX?wrap=1
https:
uwwtw.instructure.com/courses/497799/files/ XXXXXXXXXX/download?download_frd=1
11/30/22, 9:36 PM Programming Project 2
https:
uwwtw.instructure.com/courses/497799/assignments/ XXXXXXXXXX/7
Add your code to complete the Python version.
Scheme starter files for Project 2: CSV reader module
(https:
uwwtw.instructure.com/courses/497799/files/ XXXXXXXXXX?wrap=1)
(https:
uwwtw.instructure.com/courses/497799/files/ XXXXXXXXXX/download?download_frd=1) , Project 2
starter file (https:
uwwtw.instructure.com/courses/497799/files/ XXXXXXXXXX?wrap=1)
(https:
uwwtw.instructure.com/courses/497799/files/ XXXXXXXXXX/download?download_frd=1) . Put both
files into the same folder or directory. Add your code to the Project 2 starter file complete the Scheme
version.
For easiest results, put your data-set file in the same folder or directory as your code. Python and
Scheme code files can live in the same folder or directory without problems.
These starter files include a pre-written CSV reader file for this project, among other things. You are not
expected to know how the CSV reader code works.
Read the comments! I wrote them to help you.
Code to write
extract function: get records that satisfy certain criteria
This function returns a list of records (rows) from a CSV file that satisfy certain criteria. The search
criteria must be encoded inside a separate query function. See the "Query functions" subsection, below,
for information about these.
Your extract function should take 2 arguments: the name of a function that returns a Boolean value,
and the path to a CSV file. It should do the following.
1. Open the provided data set, which is given as a CSV file. The starter files include code that you can
use for this step.
2. Use a filter function to return only the lines that satisfy the given Boolean query function.
Query functions
Each query function must return a Boolean result: true if the given condition is true, and false otherwise.
The starter code files include two sample query functions: is_Canadian and postcode_begins_with .
1. is_Canadian
expects one argument, which is a customer (record)
eturns true if the customer's Country field is "CA" for Canada
2. postcode_begins_with
expects one argument, which is a string of characters that is the prefix for a postal code
https:
uwwtw.instructure.com/courses/497799/files/ XXXXXXXXXX?wrap=1
https:
uwwtw.instructure.com/courses/497799/files/ XXXXXXXXXX/download?download_frd=1
https:
uwwtw.instructure.com/courses/497799/files/ XXXXXXXXXX?wrap=1
https:
uwwtw.instructure.com/courses/497799/files/ XXXXXXXXXX/download?download_frd=1
11/30/22, 9:36 PM Programming Project 2
https:
uwwtw.instructure.com/courses/497799/assignments/ XXXXXXXXXX/7
creates and returns a function, which expects one argument (a customer) and returns true if that
customer's postal code (ZIP) begins with the given string of characters
You will need to write the following query functions.
1. ordered_this_month
expects one argument, which is a customer (record)
eturns true if the customer ordered any items this month
2. has_zero_balance
expects one argument, which is a customer (record)
eturns true if the customer has a zero balance
3. due_before
expects one argument, which is a string of characters (or an integer) that encodes a date
creates and returns a function, which expects one argument (a customer) and returns true if the
customer's due date is before the given date
the format will be similar to postcode_begins_with ; use that as an example.
You are encouraged, but not required, to write additional query functions if they will help you.
Main program: process the data
Write code to generate a report that will contain the following output.
1. The number of customers who placed orders this month.
2. The number of customers from Whitewater (postal code XXXXXXXXXXwho placed orders this month.
3. The average (mean) balance across all customers who placed orders this month.
4. The number of customers who have zero balances.
5. The number of customers who have overdue accounts (due before November 30, 2022).
6. The average (mean) balance across all customers who have overdue accounts (due before
November 30, 2022).
7. The first name, last name, and postal code of the customer who has the largest overdue balance
(due before November 30, 2022).
See the "Main program" section of each starter file for example code that generates simple formatted
output in Python and Scheme.
Test cases
The given data set will be your primary test case. Your report should look similar to this sample report.
The formatting does not need to be 100% identical, but the output values should be the same.
11/30/22, 9:36 PM Programming Project 2
https:
uwwtw.instructure.com/courses/497799/assignments/ XXXXXXXXXX/7
CS320 PP2 Ru
ic
8 customers placed orders this month
3 customers from Whitewater placed orders this month
Average balance for customers who placed orders this month is $51.29
2 customers have zero balances
----------
2 customers have overdue accounts
Average balance for customers who have overdue accounts is $66.76
The customer with the largest overdue balance is:
Brenda Schmidt, postal code 53190
Submitting Your Work
Submit a single archive file containing all of your Programming Project 2 work to this assignment.
Upload one Python file and one Scheme file containing your solutions for both problems. You may
also upload your files as a .zip file (no other compressed file formats, please).
11/30/22, 9:36 PM Programming Project 2
https:
uwwtw.instructure.com/courses/497799/assignments/ XXXXXXXXXX/7
Criteria Ratings Pts
4 pts
4 pts
8 pts
8 pts
8 pts
8 pts
4 pts
4 pts
8 pts
8 pts
8 pts
Python: no syntax e
ors 4 pts
No Syntax E
ors
2 pts
Has E
ors
0 pts
Missing
Python: extract 4 pts
No E
ors
2 pts
Has E
ors
0 pts
Missing
Python: ordered_this_month 8 pts
Full Marks
7 pts
Small E
o
5 pts
Some E
ors
2 pts
Incomplete
0 pts
No Marks
Python: has_zero_balance 8 pts
Full Marks
7 pts
Small E
o
5 pts
Some E
ors
2 pts
Incomplete
0 pts
No Marks
Python: due_before 8 pts
Full Marks
7 pts
Small E
o
5 pts
Some E
ors
2 pts
Incomplete
0 pts
No Marks
Python: main program 8 pts
Full Marks
7 pts
Small E
o
5 pts
Some E
ors
2 pts
Incomplete
0 pts
No Marks
Scheme: no syntax e
ors 4 pts
No Syntax E
ors
2 pts
Has E
ors
0 pts
Missing
Scheme: extract 4 pts
No E
ors
2 pts
Has E
ors
0 pts
Missing
Scheme: ordered_this_month 8 pts
Full Marks
7 pts
Small E
o
5 pts
Some E
ors
2 pts
Incomplete
0 pts
No Marks
Scheme: has_zero_balance 8 pts
Full Marks
7 pts
Small E
o
5 pts
Some E
ors
2 pts
Incomplete
0 pts
No Marks
Scheme: due_before 8 pts
Full Marks
7 pts
Small E
o
5 pts
Some E
ors
2 pts
Incomplete
0 pts
No Marks
11/30/22, 9:36 PM Programming Project 2
https:
uwwtw.instructure.com/courses/497799/assignments/ XXXXXXXXXX/7
Total Points: 80
Criteria Ratings Pts
8 pts
Scheme: main program 8 pts
Full Marks
7 pts
Small E
o
5 pts
Some E
ors
2 pts
Incomplete
0 pts
No Marks