A Spring Boot application that provides heatmap data for answer rates, exposing a secure REST endpoint backed by an in-memory H2 database.
- Prerequisites
- Installation
- Configuration
- Running the Application
- API Usage
- Testing
- Mock Data Generation
- Notes
- Java 17 or higher
- Gradle Wrapper (included)
- Docker & Docker Compose (optional, for containerized deployment)
-
Clone the repository
git clone https://github.com/Ahmed-aleryani/onoff-heatmap-assignment.git cd onoff-heatmap-assignment -
Build the project
./gradlew build
- Default Basic Auth credentials:
- Username:
admin - Password:
admin
- Username:
- Override via environment variables or in
application-*.yml:HEATMAP_USER- usernameHEATMAP_PASS- password
Settings live in /src/main/resources/:
application.yml(default) (in-memory H2)application-local.yml(in-memory H2)application-prod.yml(file-based H2)
Activate a profile:
./gradlew bootRun --args='--spring.profiles.active=<local|prod|delete option to use default>'
# or
java -jar build/libs/heatmap-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod./gradlew bootRunApplication runs on http://localhost:8080
# Build the Docker image
docker build -t heatmap .
# Run the container (foreground mode to see logs)
docker run -p 8080:8080 heatmap
# Or run in background mode
docker run -d -p 8080:8080 heatmapThe application will be available at http://localhost:8080
# Build the Docker image
docker build -t heatmap .
# Run the container with production profile
docker run -d -p 8080:9090 \
-e SPRING_PROFILES_ACTIVE=prod \
-e SPRING_DATASOURCE_URL=jdbc:h2:file:./data/heatmap \
-e SPRING_DATASOURCE_USERNAME=sa \
-e SPRING_DATASOURCE_PASSWORD=password \
-e SPRING_H2_CONSOLE_ENABLED=true \
-e HEATMAP_USER=admin \
-e HEATMAP_PASS=admin \
-v $(pwd)/data:/app/data \
heatmapNote: In production mode, the application runs on port 9090 and persists data to a local data directory.
GET /api/heatmap/answer-rate
Query Parameters:
dateInput(required):YYYY-MM-DDnumberOfShades(required): 3–10startHour(optional): 0–23 (default: 0)endHour(optional): 0–23 (default: 23)
Response: JSON array of hourly objects with fields:
hour(Integer)answeredCalls(Integer)totalCalls(Integer)rate(Float, percentage)shade(String, 1–N)
curl -X GET "http://localhost:8080/api/heatmap/answer-rate?dateInput=2025-04-28&numberOfShades=5&startHour=0&endHour=23" \
-H "Accept: application/json" \
-u "admin:admin"Run all tests with Gradle:
./gradlew testGenerate coverage report:
./gradlew test jacocoTestReportTest reports: build/reports/tests/test/index.html
A Python script generates sample call logs for 3 days:
src/main/resources/dataGenerator.py
cd src/main/resources
python dataGenerator.pyThis produces data.sql for populating the H2 database.
- In-memory H2 is used by default for local dev.
- Secure credentials via environment variables—never commit secrets.
- For any issues or questions, please open an issue in the repository.