Skip to content

Fix/raise confidence score#296

Merged
driedpampas merged 3 commits into
mainfrom
fix/raise-confidence-score
Jun 3, 2026
Merged

Fix/raise confidence score#296
driedpampas merged 3 commits into
mainfrom
fix/raise-confidence-score

Conversation

@bmbianca
Copy link
Copy Markdown
Contributor

@bmbianca bmbianca commented Jun 1, 2026

maxed the default confidence score and removed the "tu" point from the in-door map

Summary by CodeRabbit

Release Notes

  • Performance & Reliability
    • Improved location confidence evaluation with refined thresholds for more accurate positioning
    • Enhanced route calculation to optimize navigation response handling
    • Updated location clustering and data decay configuration for better service performance

@bmbianca bmbianca requested a review from a team as a code owner June 1, 2026 17:48
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

Configuration defaults for data decay are reduced. Location processing SQL is enhanced to include marked_at tracking and adjust aggregations. Routing responses exclude the user location marker point while distance calculations remain based on pre-removal state.

Changes

Data Decay Configuration and Routing Flow Refinements

Layer / File(s) Summary
Data decay configuration and defaults
src/main/java/com/p2ps/service/DataDecayService.java, src/main/resources/application.properties, src/test/java/com/p2ps/service/DataDecayServiceTest.java
Decay penalty reduced from 0.02 to 0.1, cutoff days reduced from 14 to 3, and minimum confidence floor reduced from 0.15 to 0.05 across @Value annotations, configuration properties, and test expectations.
Location clustering SQL and confidence thresholds
src/main/java/com/p2ps/service/LocationProcessorWorker.java, src/test/java/com/p2ps/service/LocationProcessorWorkerTest.java
Low-confidence threshold and minimum ping count constants are adjusted. Scheduled and rapid recalculation SQL queries are updated to propagate marked_at through clustering, set confidence_score to constant 1.0, compute last_seen from maximum cluster timestamp, and derive last_updated from last_seen instead of NOW().
Routing flow refactor: user location handling and response assembly
src/main/java/com/p2ps/service/RoutingService.java, src/main/java/com/p2ps/service/RoutingAsyncService.java, src/test/java/com/p2ps/controller/RoutingControllerTest.java, src/test/java/com/p2ps/service/RoutingServiceTest.java
RoutingService eager and lazy route paths both exclude the user location marker point from response routes while preserving distance calculations from the pre-removal route state. RoutingAsyncService integrates audio instruction enrichment and applies the same user location removal before constructing the final UI payload. Route size assertions and response compositions are updated across all routing tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • P2P-Shopping/server#170: Decay configuration defaults are adjusted for the data-decay job flow introduced in this PR.
  • P2P-Shopping/server#279: LocationProcessorWorker center recalculation and confidence/ping count computation patterns overlap directly.
  • P2P-Shopping/server#231: RoutingServiceTest expectations for calculateOptimalRoute behavior and route composition changes are affected similarly.

Suggested reviewers

  • driedpampas
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Fix/raise confidence score' is vague and generic, lacking specificity about which confidence scores are being modified and what concrete changes are made. Consider a more descriptive title such as 'Update location confidence thresholds and routing response formatting' that clearly indicates the scope of changes across multiple services.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/raise-confidence-score

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 2, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
76.7% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
src/test/java/com/p2ps/service/DataDecayServiceTest.java (1)

34-39: ⚡ Quick win

Assert the new 3-day cutoff in this regression test.

This test was updated for the new penalty/floor, but it still accepts any LocalDateTime, so it will pass even if executeDataDecay() keeps using the old 14-day window. Please capture the cutoff argument and assert it is approximately now().minusDays(3).

Proposed test change
+import org.mockito.ArgumentCaptor;
+
 import java.time.LocalDateTime;
 
@@
     void shouldExecuteDataDecayAndCallRepositoryWithCorrectPenalty() {
         Double expectedPenalty = 0.1;
         Double expectedMinConfidenceFloor = 0.05;
+        LocalDateTime beforeCall = LocalDateTime.now();
 
         when(repository.applyDecayToOldRecords(eq(expectedPenalty), any(LocalDateTime.class), eq(expectedMinConfidenceFloor)))
                 .thenReturn(5);
 
         dataDecayService.executeDataDecay();
+        LocalDateTime afterCall = LocalDateTime.now();
 
-        verify(repository).applyDecayToOldRecords(eq(expectedPenalty), any(LocalDateTime.class), eq(expectedMinConfidenceFloor));
+        ArgumentCaptor<LocalDateTime> cutoffCaptor = ArgumentCaptor.forClass(LocalDateTime.class);
+        verify(repository).applyDecayToOldRecords(eq(expectedPenalty), cutoffCaptor.capture(), eq(expectedMinConfidenceFloor));
+
+        LocalDateTime capturedCutoff = cutoffCaptor.getValue();
+        LocalDateTime minExpected = beforeCall.minusDays(3);
+        LocalDateTime maxExpected = afterCall.minusDays(3);
+        org.junit.jupiter.api.Assertions.assertFalse(capturedCutoff.isBefore(minExpected));
+        org.junit.jupiter.api.Assertions.assertFalse(capturedCutoff.isAfter(maxExpected));
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/test/java/com/p2ps/service/DataDecayServiceTest.java` around lines 34 -
39, The test currently stubs and verifies
repository.applyDecayToOldRecords(eq(expectedPenalty), any(LocalDateTime.class),
eq(expectedMinConfidenceFloor)) so it won't catch if executeDataDecay() still
uses the old 14-day cutoff; change the test to capture the LocalDateTime
argument passed to repository.applyDecayToOldRecords (use an
ArgumentCaptor<LocalDateTime> or verify with an argThat) after calling
dataDecayService.executeDataDecay(), then assert the captured cutoff is
approximately Instant.now().minus(3, DAYS) (or LocalDateTime.now().minusDays(3))
within a small tolerance (e.g. a few seconds) while keeping the same checks for
expectedPenalty and expectedMinConfidenceFloor.
src/main/java/com/p2ps/service/RoutingService.java (1)

99-105: ⚡ Quick win

Extract the user_loc removal into a shared helper.

This exact block is duplicated three times (eager here, lazy at Lines 144-147, and RoutingAsyncService Lines 72-75). Centralizing it on RoutingService (which the async service already resolves as a bean) keeps the invariant in one place.

♻️ Suggested helper
/** Removes the leading user marker point (issue: redundant with blue ping). */
void stripUserPoint(List<RoutePoint> route) {
    if (!route.isEmpty() && "user_loc".equals(route.getFirst().getItemId())) {
        route.removeFirst();
    }
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/com/p2ps/service/RoutingService.java` around lines 99 - 105,
Duplicate logic that removes the leading "user_loc" point appears in
RoutingService (optimizedRoute) and RoutingAsyncService; extract it into a
single helper on RoutingService named stripUserPoint(List<RoutePoint> route)
that checks route.isEmpty() and compares route.getFirst().getItemId() to
"user_loc" then removes the first element; replace the three inlined blocks (the
one using optimizedRoute in RoutingService, the lazy block around Lines 144-147,
and the one in RoutingAsyncService) with calls to
RoutingService.stripUserPoint(...) so the invariant is centralized and both
services use the same bean method.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/main/java/com/p2ps/service/RoutingService.java`:
- Around line 99-105: Duplicate logic that removes the leading "user_loc" point
appears in RoutingService (optimizedRoute) and RoutingAsyncService; extract it
into a single helper on RoutingService named stripUserPoint(List<RoutePoint>
route) that checks route.isEmpty() and compares route.getFirst().getItemId() to
"user_loc" then removes the first element; replace the three inlined blocks (the
one using optimizedRoute in RoutingService, the lazy block around Lines 144-147,
and the one in RoutingAsyncService) with calls to
RoutingService.stripUserPoint(...) so the invariant is centralized and both
services use the same bean method.

In `@src/test/java/com/p2ps/service/DataDecayServiceTest.java`:
- Around line 34-39: The test currently stubs and verifies
repository.applyDecayToOldRecords(eq(expectedPenalty), any(LocalDateTime.class),
eq(expectedMinConfidenceFloor)) so it won't catch if executeDataDecay() still
uses the old 14-day cutoff; change the test to capture the LocalDateTime
argument passed to repository.applyDecayToOldRecords (use an
ArgumentCaptor<LocalDateTime> or verify with an argThat) after calling
dataDecayService.executeDataDecay(), then assert the captured cutoff is
approximately Instant.now().minus(3, DAYS) (or LocalDateTime.now().minusDays(3))
within a small tolerance (e.g. a few seconds) while keeping the same checks for
expectedPenalty and expectedMinConfidenceFloor.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 94221905-3145-4143-85db-7aedb6a167d5

📥 Commits

Reviewing files that changed from the base of the PR and between 741c3b5 and 1fdd766.

📒 Files selected for processing (9)
  • src/main/java/com/p2ps/service/DataDecayService.java
  • src/main/java/com/p2ps/service/LocationProcessorWorker.java
  • src/main/java/com/p2ps/service/RoutingAsyncService.java
  • src/main/java/com/p2ps/service/RoutingService.java
  • src/main/resources/application.properties
  • src/test/java/com/p2ps/controller/RoutingControllerTest.java
  • src/test/java/com/p2ps/service/DataDecayServiceTest.java
  • src/test/java/com/p2ps/service/LocationProcessorWorkerTest.java
  • src/test/java/com/p2ps/service/RoutingServiceTest.java

@driedpampas driedpampas merged commit 7d0d621 into main Jun 3, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants