This project implements a Delivery Fare Estimation System capable of processing large volumes of GPS data to calculate fare estimates for courier deliveries. It's designed to handle big chunk of input data efficiently using concurrent processing.
- Filters invalid GPS data points based on speed thresholds
- Calculates fares based on distance, time, and moving/idle states
- Applies different rates for day and night times
- Handles minimum fare and flag charge
- Utilizes concurrent processing for high performance
- Provides CPU and memory profiling options
- Go 2.0 or higher
- Git
-
Clone the repository:
git clone https://github.com/n9e6y/snappBoxChallengeForAlgorithmArena.git cd snappBoxChallengeForAlgorithmArena -
Build the project:
go build -o SBCFAA cmd/main.go
Run the fare estimator with the following command:
./SBCFAA -input <input_file_path> -output <output_file_path> [options]
-input: Path to the input CSV file (required)-output: Path for the output CSV file (default: "fare_estimates.csv")-cpuprofile: Write CPU profile to file-memprofile: Write memory profile to file
./SBCFAA -input sample_data.csv -output fare_estimate.csv
The input CSV file should have the following format:
id_delivery,lat,lng,timestamp
1,40.7128,-74.0060,1609459200
1,40.7129,-74.0061,1609459260
2,40.7130,-74.0062,1609459320
...
id_delivery: Unique identifier for each deliverylat: Latitude of the GPS pointlng: Longitude of the GPS pointtimestamp: Unix timestamp of the GPS point
The output CSV file will have the following format:
id_delivery,fare_estimate
1,15.75
2,22.30
...
- Flag charge: 1.30
- Minimum fare: 3.47
- Moving rate (day, 05:00-00:00): 0.74 per km
- Moving rate (night, 00:00-05:00): 1.30 per km
- Idle rate: 11.90 per hour
- Moving speed threshold: 10.0 km/h
- The system uses concurrent processing to handle large datasets efficiently.
- For very large input files, consider using the profiling options to optimize performance.
To run the unit tests:
go test ./...
To run tests with coverage:
go test ./... -cover