Reference no: EM132383911
Programming Assignment
Getting started
Complete the reading and practice assignments posted on the course schedule. Review class handouts and examples. This assignment requires knowledge of loops, lists and function definitions.
Programming Project: OrderSummary
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 few summary analyses of the data. The first task concerns determining how many employees are needed in the shop at different times, for which the owner would like to see how many orders came within each hour of the work day.
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 date ranges over all dates of August, 2019. The time range of orders corresponds to the working hours of the business, which is 6 am until midnight.
• 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=[
['datetime', 'first name', 'last name', 'espresso', 'cappuccino', 'americano', 'pastry', 'muffin', 'scone'],
['2019-08-03 09:05:54', 'anon', 'anon', 0,1,1,3,0,4],
['2019-08-06 10:17:17', 'Jacquelin', 'Trevale', 0,2,1,3,1,0],
['2019-08-21 12:33:23', 'Zuleyma', 'Pemdevon', 2,2,2,3,2,1],
. . . 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.
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 variableThe program that you write must work as follows.
1. Ask the user
a. how many days of data to summarize,
b. the length (in minutes) of the time interval used to aggregate the number of orders.
2. Create and display the order summary matrix, summarizing how many orders were placed during each interval starting from 6 am and ending at midnight, for each day starting from the first of the month until the day number, provided by the user in step 1. Recall, that each row in the ORDERS list represents one order.
3. Ask the user to specify the date, for which a histogram will be displayed. The histogram displays each order as one * symbol. If the user enters a number that falls beyond the range from 1 to the number of days in the summary matrix, the program should just repeat step 3 (as shown in the interaction below). Repeat step 3, until -1 is entered.
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 24am, expressed in minutes)
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 methods as needed.
b. function labelString () that will produce a string label shown in the leftmost column of the output. The function will be passed the interval number, opening time, and the length of the time interval as input parameters and must 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 ('7:00 - 7:59') in the leftmost column shown in the interaction, the function should be called as labelString(1, 6*60, 60 ).
c. function composeOrderMatrix(), with two parameters: the number of days, with a default value of 31, and the length of the 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 column c will represent one day's data for day number (c+1). Values in row r will represent the number of orders in the time interval number r+1 from the beginning of the day.
First, create the two-dimensional list populated with as many rows of 0s, as the number of time intervals that would fit in the work day (must be calculated). The length of each row must equal to the number of days. Then, fill the matrix with values based on the ORDERS list and return the matrix populated with numbers of total orders.
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.
e. function printHistogram(), which accepts three parameters: a two-dimensional list storing matrix values, the day number (1-based) and the length of the time interval. The function must display a histogram, as shown twice in the interaction above for column values 1 and 10. The histogram visualizes the numbers from the appropriate column of the matrix using * symbols.
Thus, when passed the order summary matrix and a day number, each * represents a single order placed in the consecutive time periods, as designated on the left of the histogram.
So, for example, the first histogram in the interaction corresponds to orders in day 1, so the first row displays 22 stars, the second - 19, and so forth.
3. There should be no code outside of function definitions, except for the definitions of the three global variables and a call to method main.