Python代写:CS602 Order Summary Matrix

使用Python基础语法,实现一个Order Summary Matrix程序。

Matrix

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

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:

1
2
3
4
5
6
7
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],
]

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.

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:

1
2
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
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.

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:

1
2
3
4
5
6
7
8
9
10
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
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.
  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.
    • 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.