#C14191. Transaction Data Summary
Transaction Data Summary
Transaction Data Summary
You are given a CSV formatted transaction record on standard input. Each record contains the following columns:
transaction_id
timestamp
(format: YYYY-MM-DD HH:MM:SS)product_name
quantity
total_price
Your task is to process the CSV data and compute:
- The total revenue (i.e. the sum of
total_price
over all transactions). - The product that generated the highest revenue over all transactions.
- The number of transactions per day. The date is taken as the first 10 characters of the timestamp.
- A daily summary in CSV format containing three columns:
date
,daily_revenue
(the sum of total_price for that day), andhighest_selling_product
(the product with the highest revenue on that day).
Your program should print the results to standard output in the following order:
- A line with the total revenue in the format:
Total Revenue: X
- A line with the highest revenue product in the format:
Highest Revenue Product: Y
- A line with daily transactions as a JSON formatted dictionary, for example:
Daily Transactions: {"2023-10-01": 2, "2023-10-02": 2}
- An empty line.
- The daily summary CSV output (including the header) with one record per day in chronological order.
If any of the required columns are missing, your program should throw an error (print an error message and exit).
Note: Use LaTeX format for any formulas. For example, the total revenue can be represented as \(R = \sum_{i=1}^{n} p_i\) where \(p_i\) is the total price of the \(i\)th transaction.
inputFormat
The input is given via standard input (stdin) and consists of a CSV content with a header row. The columns are:
- transaction_id
- timestamp
- product_name
- quantity
- total_price
You can assume that each value is well formatted. There will be at least one record.
outputFormat
Print to standard output (stdout) the following:
- A line:
Total Revenue: X
, where X is the total revenue (a float value). - A line:
Highest Revenue Product: Y
, where Y is the product name with the highest total revenue. - A line:
Daily Transactions: Z
, where Z is a JSON formatted dictionary mapping each date (YYYY-MM-DD) to its number of transactions. - A blank line.
- The daily summary CSV output containing the header "date,daily_revenue,highest_selling_product" followed by one record per day in chronological order.
transaction_id,timestamp,product_name,quantity,total_price
1,2023-10-01 08:00:00,Product A,2,20.0
2,2023-10-01 09:00:00,Product B,1,30.0
3,2023-10-02 10:00:00,Product A,1,10.0
4,2023-10-02 11:00:00,Product C,1,40.0
5,2023-10-03 12:00:00,Product B,2,60.0
Total Revenue: 160.0
Highest Revenue Product: Product B
Daily Transactions: {"2023-10-01": 2, "2023-10-02": 2, "2023-10-03": 1}
date,daily_revenue,highest_selling_product
2023-10-01,50.0,Product B
2023-10-02,50.0,Product C
2023-10-03,60.0,Product B
</p>