Tracks
/
Ballerina
/
Exercises
/
CSV Fuel Allowance

# CSV Fuel Allowance

Medium

## Instructions

### Problem statement

Every employee of ABC Corp receives an unlimited fuel allowance. Employees are required to send a record every time they fill up their vehicles. These records are appended to the same CSV file and processed at the month's end.

As a member of the digital operations team, your task is to read this CSV file and write the results to another CSV file. The output file should contain an entry for each employee with the following details:

• Employee number
• Number of gas fill-ups
• Total fuel cost
• Total gallons
• Total miles accrued

You are given two string arguments.

1. Input CSV file path
2. Output CSV file path

The input CSV file has n lines, and each line takes the following form.

Column name Ballerina type
employee_id int
gallons decimal
gas_price(USD) decimal

The output file should contain an entry for each employee, sorted in ascending order by the employee_id. Each line takes the following form:

Column name Ballerina type
employee_id int
gas_fill_up_count int
total_fuel_cost(USD) decimal
total_gallons decimal
total_miles_accrued int

### Constraints

• Number of lines n in the input CSV file: 2 <= n <= 1000
• Number of employees in the company: 97
• Gas price is per gallon
• No missing fill-up records

### Example 1

• Input: example01_input.csv
2312,230,18.561,4.56
2312,500,19.345,4.89
• Output: example01_output.csv
2312,2,179.23521,37.906,270

### Example 2

• Input: example02_input.csv
2413,04089,21.682,3.46
3423,06582,15.248,4.56
2413,04127,04.221,3.40
2413,04349,11.192,4.10
3423,06767,08.696,3.34
2413,04547, 09.197,2.90
• Ouput: example02_output.csv
2413,4,161.92962,46.292,458
3423,2,98.57552,23.944,185

Edit via GitHub