Skip to content

Latest commit

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Ride Price Calculator

A Spring Boot application that calculates ride-sharing prices for Estonian cities (Tallinn, Tartu, Pärnu) based on vehicle type, live weather data, and time of day.

Features

  • Dynamic pricing — Base fees vary by city and vehicle (Car, Bike, Scooter)
  • Weather-based extras — Temperature, wind speed, and weather phenomena affect scooter and bike fares
  • Time-of-day multipliers — Rush hour (07:00–09:00, 16:00–19:00) and late night (00:00–05:00) adjustments
  • Risk score — 0–100 score indicating ride conditions based on weather
  • Live weather data — Fetches current conditions from WeatherAPI.com every 45 seconds

Tech Stack

  • Java 21 · Spring Boot 3.4 · Spring Data JPA · H2 Database
  • WeatherAPI.com for real-time weather
  • SpringDoc OpenAPI for API documentation

Prerequisites

  • Java 21 or later
  • Maven 3.6+ (or use the included Maven wrapper)

Getting Started

Run the application

cd food_delivery_app
./mvnw spring-boot:run

On Windows:

cd food_delivery_app
mvnw.cmd spring-boot:run

Access the app

URLDescription
http://localhost:8080Web UI — price calculator
http://localhost:8080/ride-priceREST API endpoint
http://localhost:8080/swagger-ui.htmlOpenAPI / Swagger docs
http://localhost:8080/h2-consoleH2 database console

Note: Weather data is imported every 45 seconds. Wait ~1 minute after startup before requesting prices.

API

GET /ride-price

Calculate ride price for a given city, vehicle, and optional ride time.

Query parameters

ParameterTypeRequiredDescription
citystringYesTallinn, Tartu, or Pärnu
vehiclestringYesCar, Bike, or Scooter
rideTimestringNoISO 8601 datetime (e.g. 2026-02-04T09:37:00.000Z). Defaults to current time.

Example request

GET /ride-price?city=Tallinn&vehicle=Car&rideTime=2026-02-04T09:37:00.000Z

Example response

{
"baseFee": 4.0,
"extraFee": 0.0,
"multiplier": 1.2,
"finalPrice": 4.8,
"riskScore": 85
}

Pricing Rules

Base fees (€)

CityCarScooterBike
Tallinn4.003.503.00
Tartu3.503.002.50
Pärnu3.002.502.00

Extra fees (Scooter & Bike only)

  • Temperature: Below -10°C: +€1.00 · -10°C to 0°C: +€0.50
  • Wind (Bike): 10–20 m/s: +€0.50 · Above 20 m/s: forbidden
  • Weather: Snow/sleet: +€1.00 · Rain: +€0.50 · Glaze/hail/thunder: forbidden

Time multipliers

  • 07:00–09:00, 16:00–19:00 → ×1.2
  • 00:00–05:00 → ×1.1
  • Other times → ×1.0

Project Structure

food_delivery_app/
├── src/main/java/com/crt/fujitsu/ride_pricing_app/
│ ├── config/ # RestTemplate, CORS
│ ├── controller/ # REST & web controllers
│ ├── dto/ # RidePriceEstimate
│ ├── exception/ # Error handling
│ ├── model/ # WeatherData entity
│ ├── repository/ # WeatherDataRepository
│ └── service_logic/ # Pricing, weather, calculators
├── src/main/resources/
│ ├── application.properties
│ └── static/index.html
└── pom.xml

Configuration

  • Database: H2 in-memory (jdbc:h2:mem:weather_database)
  • Weather API: WeatherAPI.com (key in ApiWeather.java)
  • Weather import: Every 45 seconds via @Scheduled

Running Tests

cd food_delivery_app
./mvnw test

License

MIT

About

Dynamic ride pricing system with real-time weather integration (Spring Boot)

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages