Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ services:
- "8080:8080"
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/analytics_db_dev
SPRING_DATASOURCE_USERNAME: analytics_user
SPRING_DATASOURCE_PASSWORD: password
SPRING_DATASOURCE_USERNAME: postgres
SPRING_DATASOURCE_PASSWORD: 123
SPRING_RABBITMQ_HOST: rabbitmq # RabbitMQ container name or use its IP if needed
SPRING_RABBITMQ_PORT: 5672
SPRING_RABBITMQ_USERNAME: guest
Expand All @@ -23,8 +23,8 @@ services:
- "5432:5432"
environment:
POSTGRES_DB: analytics_db_dev
POSTGRES_USER: analytics_user
POSTGRES_PASSWORD: password
POSTGRES_USER: postgres
POSTGRES_PASSWORD: 123
volumes:
- db_data:/var/lib/postgresql/data

Expand All @@ -47,4 +47,3 @@ services:

volumes:
db_data:

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public interface CourierRepository extends JpaRepository<Courier, Long> {
+ "LEFT JOIN orders o "
+ "ON c.id = o.courier_id "
+ "AND o.final_status_timestamp BETWEEN :startDate AND :endDate "
+ "AND o.status IN ('COMPLETED', 'FAILED') "
+ "GROUP BY c.id, c.name "
+ "ORDER BY courierId", nativeQuery = true)
List<CourierPerformanceProjection> findCourierPerformanceBetweenDates(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public List<CourierSuccessRateResponse> getCourierSuccessRate(
.courierId(data.getCourierId())
.courierName(data.getCourierName())
.successRate(
MetricCalculator.calculatePercentage(
MetricCalculator.calculateRate(
data.getCompletedCount(),
data.getDeliveryCount()))
.build())
Expand Down Expand Up @@ -81,7 +81,7 @@ public List<CourierPerformanceReportResponse> getCourierPerformanceReport(
.courierName(data.getCourierName())
.deliveryCount(data.getDeliveryCount())
.successRate(
MetricCalculator.calculatePercentage(
MetricCalculator.calculateRate(
data.getCompletedCount(),
data.getDeliveryCount()))
.averageRating(data.getAverageRating())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
public final class MetricCalculator {
private static final int DEFAULT_SCALE = 2;

private static final BigDecimal ONE_HUNDRED = new BigDecimal("100");

private MetricCalculator() {
throw new UnsupportedOperationException(
"This is a utility class and cannot be instantiated");
Expand All @@ -25,7 +23,7 @@ private MetricCalculator() {
* @return The calculated percentage as a BigDecimal, or BigDecimal.ZERO
* if the denominator is zero.
*/
public static BigDecimal calculatePercentage(final long numerator,
public static BigDecimal calculateRate(final long numerator,
final long denominator, final int scale,
final RoundingMode roundingMode) {
if (denominator == 0) {
Expand All @@ -35,7 +33,6 @@ public static BigDecimal calculatePercentage(final long numerator,
return BigDecimal.ZERO;
}
return BigDecimal.valueOf(numerator)
.multiply(ONE_HUNDRED)
.divide(BigDecimal.valueOf(denominator), scale, roundingMode);
}

Expand All @@ -47,9 +44,9 @@ public static BigDecimal calculatePercentage(final long numerator,
* @return The calculated percentage (scale 2, HALF_UP rounding), or
* BigDecimal.ZERO if denominator is zero.
*/
public static BigDecimal calculatePercentage(final long numerator,
public static BigDecimal calculateRate(final long numerator,
final long denominator) {
return calculatePercentage(numerator, denominator, DEFAULT_SCALE,
return calculateRate(numerator, denominator, DEFAULT_SCALE,
RoundingMode.HALF_UP);
}
}
Loading