PYTHON ASSIGNMENT 3

CS602 – Data-Driven Development with Python Fall’2020 Programming Assignment 3
1
Programming Assignment 3
Getting started
This assignment requires knowledge of loops, lists and function definitions, which will be introduced in the course of three weeks, but you need not postpone working on it. After reading the description of the project, read the Suggested Plan section, which describes how you can organize your work on this project over 3 weeks.
As usual, your weekly homework requires completing the reading and practice assignments posted on the course schedule and reviewing class handouts and examples.
Programming Project: WeeklySummary worth: 20 points
Create an order summary matrix.
In this assignment you will be processing order data from a fictional coffee shop. The café’s owner would like to optimize the business operations and has hired you to create a program that will compose and display a summary of the purchase data from the past week. The first task concerns computing the number of orders received on specific days of week at specific times and answering questions regarding peak for each day of the week.
The data, collected from online and in-person orders, includes a set of uniform records, each storing the following fields
• Date and time of the order. The dates range over one week. The range of the time parameter corresponds to the working hours of the business, which is 6 am until 10 pm.
• First and last name of the person making the order, if known. ‘anon’ represents orders by anonymous customers.
• Number of items ordered for each of the following products: espresso, cappuccino, americano, pastry, muffin, scone.
The data is supplied in a file, orderlog.py, which is posted with the assignment. For simplicity, orderlog.py contains a definition of a python list, stored in variable called orderlst, as follows:
orderlst=[
[‘date’, ‘time’, ‘first name’, ‘last name’, ‘espresso’, ‘cappuccino’, ‘americano’, ‘muffin’, ‘scone’],
[‘2020-02-06′, ’09:57:50’, ‘anon’, ‘anon’, 2,3,0,2,1],
[‘2020-02-05′, ’19:38:50’, ‘Neves’, ‘Moorheart’, 0,0,3,1,3],
[‘2020-02-03′, ’16:15:21’, ‘Nuri’, ‘Fuggles’, 0,2,1,2,0],
[‘2020-02-09′, ’14:55:45’, ‘Aretha’, ‘Millbank’, 2,0,1,2,2],
. . . the rest of the content is omitted . . .
]
As you can see from the above, orderlst is a two-dimensional list, in which the first row represents column titles, and each of the rest of the rows represents a single order, stored as a list. The inner lists have the same structure, listing values of the fields described in the first row, as shown.
CS602 – Data-Driven Development with Python Fall’2020 Programming Assignment 3
2
To use the orderlst list in your program, download orderlog.py in your project folder and include the following code in the beginning of your program:
import orderlog
ORDERS = orderlog.orderlst # rename for brevity
This will make the orderlst content available to the program through the ORDERS global variable.
The program that you write must work as follows.
1. Ask the user to specify the length (in minutes) of the time interval used to aggregate the orders. You can assume that the length of the full work day will be a multiple of the interval.
2. Create and display the order summary matrix, summarizing how many orders were placed during each interval starting from 6 am and ending at 10 pm, for each day of the week. Recall, that each row in the ORDERS list represents one order and the orders listed were all placed within one week.
3. Repeat until user enters nothing: ask to enter a day and respond with the begin-end time of the interval with the highest number of orders on that day.
The following interaction, in which user input is indicated in boldface, illustrates one execution of the program with the data file orderlog.py posted with the assignment.
Please specify the length of the time interval in minutes: 240
WEEKLY ORDER SUMMARY
DAY\TIME | 6:00-9:59|10:00-13:59|14:00-17:59|18:00-21:59|
———————————————————
Monday 367 373 341 349
Tuesday 384 383 335 356
Wednesday 315 402 338 380
Thursday 368 383 342 371
Friday 335 355 347 340
Saturday 351 338 377 400
Sunday 358 344 333 334
———————————————————
Enter day to see peak interval, or press enter to stop: Wednesday
10:00-13:59, 402 orders
Enter day to see peak interval, or press enter to stop: Sunday
6:00-9:59, 358 orders
Enter day to see peak interval, or press enter to stop:
Bye!
Explanation:
User input in the interaction above specified time interval of 240 minutes (4 hours), thus the chart above shows four columns, corresponding to the consecutive time intervals of 240 minute length from the beginning of the day. The column headings indicate begin and end times of each interval. There are seven rows, one for each day of the week. Each number displayed is a number of orders placed on a specific day within a specific time interval. For example, there were 367 orders made on Monday, between 6:00:00 and 9:59:59.
order summary matrix
CS602 – Data-Driven Development with Python Fall’2020 Programming Assignment 3
3
The next part of the interaction has the user entering days of week and the computer responding with the time interval with the highest number of orders. For example, for Wednesday, the time of the peak number of orders was between 10:00 and 13:59, when there were 402 orders placed.
The next interaction is based on a much smaller data file, and also illustrates how the program should behave when the user enters an incorrect day.
The data for the next interaction is as follows:
orderlst=[
[‘date’, ‘time’, ‘first name’, ‘last name’, ‘espresso’, ‘cappuccino’, ‘americano’, ‘muffin’, ‘scone’],
[‘2020-02-09′, ’11:55:32’, ‘anon’, ‘anon’, 0,0,2,3,1],
[‘2020-02-03′, ’18:38:58’, ‘anon’, ‘anon’, 2,3,1,1,0],
[‘2020-02-05′, ’17:14:43’, ‘Snezha’, ‘Oldborough’, 1,0,1,2,3],
[‘2020-02-04′, ’18:38:58’, ‘anon’, ‘anon’, 2,3,1,1,0],
[‘2020-02-05′, ’17:04:41’, ‘Snezha’, ‘Oldborough’, 1,0,1,2,3],
[‘2020-02-07′, ’15:52:35’, ‘anon’, ‘anon’, 0,0,0,2,0],
[‘2020-02-09′, ’09:59:05’, ‘Camillo’, ‘Delander’, 3,0,3,1,1]
]
And the interaction:
Please specify the length of the time interval in minutes: 160
WEEKLY ORDER SUMMARY
DAY\TIME | 6:00-8:39| 8:40-11:19|11:20-13:59|14:00-16:39|16:40-19:19|19:20-21:59|
———————————————————————————
Monday 0 0 0 0 1 0
Tuesday 0 0 0 0 1 0
Wednesday 0 0 0 0 2 0
Thursday 0 0 0 0 0 0
Friday 0 0 0 1 0 0
Saturday 0 0 0 0 0 0
Sunday 0 1 1 0 0 0
———————————————————————————
Enter day to see peak interval, or press enter to stop: Fri
Enter day to see peak interval, or press enter to stop: Friday
14:00-16:39 1 orders
Enter day to see peak interval, or press enter to stop: ssss
Enter day to see peak interval, or press enter to stop: Sunday
8:40-11:19 1 orders
Enter day to see peak interval, or press enter to stop: Wednesday
16:40-19:19 2 orders
Enter day to see peak interval, or press enter to stop:
Bye!
Important Notes and Requirements:
1. Your program should not use any global variables except for
a. ORDERS,
b. variables defining the opening and closing times (6am and 10pm, expressed in minutes),
c. a list of day names.
CS602 – Data-Driven Development with Python Fall’2020 Programming Assignment 3
4
2. You must define and use the following functions, plus define and use others as you see fit:
a. function main(), to start the program flow, read user input and call other functions as needed.
b. function labelString () that will produce a string label with begin-end times of an interval, as shown in the top of the output chart. The function must be passed the interval number (0-based), opening time, and the length of the time interval as input parameters and must calculate and return a string defining the start and end time of the interval, as shown in the sample interaction. For example, to generate the second value (‘8:40-11:19’) in the top of the second column shown in the last interaction, the function should be called as labelString(1, STARTMIN, 160), where STARTMIN is a constant defining 6*60.
c. function composeWeeklyOrdersMatrix(), with one parameters: the length of the time interval in minutes, defaulting to 60. The method should create and return a two-dimensional list, representing the order summary matrix shown in the interaction as the shaded part of the order summary display. In the matrix, each value in row r will represent the total number of orders received on day r, in the time interval corresponding to each column.
To compose the matrix, first, create the two-dimensional list populated with seven rows of 0s. The length of each row must equal to the number of time intervals. Then, fill the matrix with values based on the ORDERS list and return the matrix populated with summarized order information.
Hints:
• to determine which week day corresponds to a date, you can use the datetime package functions (need to import datetime). For example,
datetime.datetime(2020, 2, 12).weekday() will produce value 2,
signifying that Feb 2, 2020 is a Wednesday (day number 2, if starting from 0, Monday)
• the summary data can be collected using only one pass over the ORDERS data.
d. function printOrderSummaryMatrix(), with two parameters: a two-dimensional list of integers and the length of the time interval. The function should display the content of the matrix as shown in the interaction, with the exact formatting and alignment.
3. There should be no code outside of function definitions, except for the definitions of the global variables described above, and a call to method main.
Hints:
– Remove the first row from the ORDERS list to get rid of the column headers.
– Conduct all time arithmetic in minute-based representation, converting from minutes to hours and minutes when you need to display the time intervals.
– Start your development using a small data set so that you could test the correctness of your summary data. You can create a testing copy of the orderlog.py with a much smaller, manageable number of orders. Furthermore, you can modify the data to test specific parts of your program.
CS602 – Data-Driven Development with Python Fall’2020 Programming Assignment 3
5
Grading:
The grading schema for this project is roughly as follows:
Your program should compile without syntax errors to receive any credit. If a part of your program is working, you will receive partial credit, but only if the program compiles without syntax errors.
• 2 point will be awarded for correctly handling the input, including repeated entry for invalid input values.
• 5 points for correctly constructing the matrix.
• 4 points for correctly displaying the matrix in the specified form.
• 4 points for the correct reporting of the peak intervals.
• 3 points for defining the required methods using the prescribed design.
• 2 points will be awarded for good programming style, as defined in handout 1. Make sure to include introductory comments to functions, documenting what the function does, the parameters and the return values.
Suggested Plan of Work
Week 1 (loops)
Write a program that would ask for the length of the time interval, and go through the list of orders, for each order printing out
• the day number (0-based, starting from Monday),
• the interval number corresponding to each order (0-based), and
• begin and end time corresponding to the order time.
For example, for the order represented by list [‘2020-02-06′, ’13:57:50’, ‘anon’, ‘anon’, 2,3,0,2,1], given the interval length of 120 minutes output should be day 6, interval 3, 12:00 – 13:59.
Week 2 (lists)
Write a program that
• creates a matrix (you can choose its number of rows and columns) represented with a two-dimensional list populated with arbitrary values of your choice,
• runs a loop, which asks the user to indicate the row number (ignoring invalid ones), and prints out the column with the highest value in that row.
Update the program from Week 1 to create and populate the order summary matrix, as described on page 2.
Week 3 (functions)
Create a solution to this programming project, by completing definitions of functions described in page 4. The code developed so far should serve as a basis for this week’s work, but you will need to edit it and fill in the gaps. Don’t forget to test!
Created by Tamara Babaian on September 22, 2020


Buy plagiarism free, original and professional custom paper online now at a cheaper price. Submit your order proudly with us

Essay Hope