Skip to content

Conversation

@DTTerastar
Copy link
Collaborator

@DTTerastar DTTerastar commented Mar 16, 2025

Fixes "Cannot Save Calibration" when used in HA AddOn

Summary by CodeRabbit

  • New Features

    • Introduced enhanced signal optimization options with multi-step and weighted adjustment methods for improved performance.
    • Upgraded the calibration interface to retrieve node settings dynamically, resulting in more accurate signal displays.
  • Refactor

    • Streamlined the optimization process by removing redundant background tasks.
    • Updated default configuration parameters to refine signal threshold settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 16, 2025

📝 Walkthrough

Walkthrough

The changes update the RSSI prediction calculation in the optimization model and introduce several new optimizer classes implementing the IOptimizer interface. Updates include switching from an asynchronous background evaluation to a synchronous update in the optimization runner, refining configuration parameter limits, and enhancing the calibration UI with dynamic node settings retrieval and usage in RSSI calculations. Stability-related functions have been removed from the UI component.

Changes

File(s) Change Summary
src/Models/OptimizationResults.cs Added a Serilog using directive and updated the default pathLossExponent from 3 to 2.7, affecting the RSSI prediction calculation.
src/Optimizers/JointRxAdj...cs,
src/Optimizers/TwoStageRxAdjAbsorptionOptimizer.cs,
src/Optimizers/WeightedJointRxAdjAbsorptionOptimizer.cs
Added new optimizer classes implementing the IOptimizer interface. Each class uses the Nelder-Mead simplex method with detailed logging to optimize RSSI and absorption parameters.
src/Optimizers/OptimizationRunner.cs Removed the background re-evaluation task and modified the control flow to update the best result synchronously within the main optimization loop.
src/config.example.yaml Removed tx_ref_rssi_min and tx_ref_rssi_max parameters; updated rx_adj_rssi_min from -15 to -5 and rx_adj_rssi_max from 20 to 25.
src/ui/src/routes/calibration/[id]/+page.svelte Introduced a nodeSettings cache and fetchNodeSettings function to dynamically retrieve node settings. Updated the refRssi calculation to use the absorption value from the settings and removed functions related to stability labels and colors.

Sequence Diagram(s)

sequenceDiagram
    participant Runner as OptimizationRunner
    participant Optimizer as Optimizer (Joint/TwoStage/WeightedJointRx)
    participant Config as Configuration
    participant Logger as Logger

    Runner->>Optimizer: Optimize(OptimizationSnapshot)
    Optimizer->>Config: Retrieve configuration values
    Optimizer->>Optimizer: Evaluate objective function (Nelder-Mead simplex)
    Optimizer->>Logger: Log debug info and errors
    Optimizer-->>Runner: Return OptimizationResults
    Runner->>Runner: Update best result synchronously
Loading
sequenceDiagram
    participant Page as Calibration Page
    participant API as Node Settings API
    participant Cache as nodeSettings Cache

    Page->>API: fetchNodeSettings(nodeId)
    API-->>Page: Return Node Setting Data
    Page->>Cache: Update nodeSettings cache
    Page->>Page: Recalculate refRssi using fetched absorption value
Loading

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@DTTerastar DTTerastar temporarily deployed to CI - release environment March 16, 2025 07:41 — with GitHub Actions Inactive
@DTTerastar DTTerastar enabled auto-merge (squash) March 16, 2025 07:41
Copy link
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.

Actionable comments posted: 2

🧹 Nitpick comments (5)
src/Optimizers/WeightedJointRxAdjAbsorptionOptimizer.cs (2)

19-27: Consider null-checking optimization config more explicitly.
Currently, if _state.Config or _state.Config.Optimization is unexpectedly null, the code proceeds with default bounds but doesn't explicitly inform the user. An explicit null check (with a warning log or early return) could improve clarity and prevent silent fallback.


34-36: Reduce log verbosity for repeated per-node debug statements.
Excessively granular logs inside nested loops and iteration steps (e.g., lines 35, 36, 64–65) may generate large log volumes in production, impacting performance. Consider using a higher log level or aggregating data in fewer log entries.

Also applies to: 65-65

src/Optimizers/JointRxAdjAbsorptionOptimizer.cs (1)

80-83: Log the exception details for non-convergence.
Catching MaximumIterationsException is good, but currently the exception (ex) isn’t logged. Including ex.Message or ex.ToString() helps diagnose convergence failures.

catch (MaximumIterationsException ex)
{
    Log.Error("Non-convergence for {0}: {1}", g.Key.Id, ex.Message);
}
src/Optimizers/TwoStageRxAdjAbsorptionOptimizer.cs (2)

41-46: Validate threshold for “close nodes” in Stage 1.
You currently filter nodes by distance <= 5.0. While this may be a sensible default, consider making that threshold configurable or documented, as different deployments might need different “close node” ranges.


32-110: Explore merging two-stage logic with other optimizers or supporting concurrency.
The two-step approach is conceptually distinct, but still shares substantial overlaps (Nelder-Mead usage, repeated distance calculations, bounds checks, etc.) with the other optimizers. Introducing concurrency for each stage or reusing shared calculation utilities might yield performance benefits and easier maintainability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b4feb2d and d27ba1a.

📒 Files selected for processing (7)
  • src/Models/OptimizationResults.cs (2 hunks)
  • src/Optimizers/JointRxAdjAbsorptionOptimizer.cs (1 hunks)
  • src/Optimizers/OptimizationRunner.cs (2 hunks)
  • src/Optimizers/TwoStageRxAdjAbsorptionOptimizer.cs (1 hunks)
  • src/Optimizers/WeightedJointRxAdjAbsorptionOptimizer.cs (1 hunks)
  • src/config.example.yaml (1 hunks)
  • src/ui/src/routes/calibration/[id]/+page.svelte (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Deploy to Docker add-on with tag
  • GitHub Check: Analyze (csharp)
🔇 Additional comments (13)
src/Models/OptimizationResults.cs (2)

2-2: Added Serilog import for improved logging

The addition of Serilog supports better logging capabilities in the optimization process.


26-26: Improved signal propagation modeling with updated path loss exponent

Changing the default path loss exponent from 3 to 2.7 more accurately reflects real-world signal propagation in typical indoor environments, likely improving RSSI prediction accuracy.

src/Optimizers/OptimizationRunner.cs (2)

26-28: Documentation of removed background task

Good practice to document the removal of functionality with explanatory comments.


54-56: Simplified optimization flow with synchronous baseline calculation

The change from an asynchronous background re-evaluation task to a synchronous calculation in the main optimization loop eliminates potential race conditions and ensures evaluations always use current data.

src/config.example.yaml (1)

33-34: Adjusted RSSI adjustment limits to improve calibration

The changes to RSSI adjustment limits (increasing minimum from -15 to -5, and maximum from 20 to 25) better accommodate the variety of real-world signal environments encountered by users, likely addressing the "Cannot Save Calibration" issue by allowing a more appropriate range of values.

src/ui/src/routes/calibration/[id]/+page.svelte (8)

7-7: Updated type imports to support node settings

Adding the NodeSetting type import enables the new node settings functionality in the calibration UI.


15-17: Added node settings cache for optimization

Creating a cache for node settings avoids redundant API calls and improves performance during calibration.


30-42: Implemented node settings fetch with proper error handling

The fetchNodeSettings function properly retrieves node-specific settings from the API with appropriate error handling and maintains reactivity through reference updates.


133-146: Dynamic node settings retrieval during calibration

The enhanced reactive statement now fetches node settings on demand while setting node inclusion defaults, ensuring all required data is available for accurate RSSI calculations.


255-260: Improved RSSI reference calculation using node-specific absorption

The updated calculation now uses the actual absorption value from each node's settings instead of a hard-coded default, making the calibration more accurate for each specific environment.


460-464: Conditional display of estimated distance based on node-specific absorption

The UI now correctly uses node-specific absorption values when displaying estimated distances, providing more accurate information to users during calibration.


469-469: Simplified RSSI display

Improved the RSSI display with better formatting for readability.


472-472: Enhanced RSSI@1m calculation with node-specific absorption

The estimated RSSI@1m calculation now correctly uses each node's specific absorption value, ensuring consistency with the backend calculation model.

@DTTerastar DTTerastar merged commit fbe3f86 into main Mar 16, 2025
8 checks passed
@DTTerastar DTTerastar deleted the fix-device-calibration branch March 16, 2025 07:56
@DTTerastar
Copy link
Collaborator Author

Fixes #1027

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