#C14191. Transaction Data Summary

    ID: 43813 Type: Default 1000ms 256MiB

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:

  1. The total revenue (i.e. the sum of total_price over all transactions).
  2. The product that generated the highest revenue over all transactions.
  3. The number of transactions per day. The date is taken as the first 10 characters of the timestamp.
  4. A daily summary in CSV format containing three columns: date, daily_revenue (the sum of total_price for that day), and highest_selling_product (the product with the highest revenue on that day).

Your program should print the results to standard output in the following order:

  1. A line with the total revenue in the format: Total Revenue: X
  2. A line with the highest revenue product in the format: Highest Revenue Product: Y
  3. A line with daily transactions as a JSON formatted dictionary, for example: Daily Transactions: {"2023-10-01": 2, "2023-10-02": 2}
  4. An empty line.
  5. 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:

  1. A line: Total Revenue: X, where X is the total revenue (a float value).
  2. A line: Highest Revenue Product: Y, where Y is the product name with the highest total revenue.
  3. A line: Daily Transactions: Z, where Z is a JSON formatted dictionary mapping each date (YYYY-MM-DD) to its number of transactions.
  4. A blank line.
  5. The daily summary CSV output containing the header "date,daily_revenue,highest_selling_product" followed by one record per day in chronological order.
## sample
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>