Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/rework mai6 template #854

Merged
merged 12 commits into from
Jan 23, 2025
Merged

Feature/rework mai6 template #854

merged 12 commits into from
Jan 23, 2025

Conversation

pgasheev
Copy link
Contributor

@pgasheev pgasheev commented Jan 17, 2025

Добавил в шаблон MAI6 возможность выбирать scale для физической величины. В зависимости от значения виртуального параметра подствляются каналы/параметры с нужным scale. Тикет: https://wirenboard.youtrack.cloud/issue/FW-6

Было:
image

Стало:
image

Summary by CodeRabbit

Release Notes for wb-mqtt-serial v2.153.2

  • New Features

    • Added physical value scaling support for WB-MAI6 template.
    • Enhanced channel configuration with more detailed physical value conversion options.
  • Improvements

    • Updated configuration parameters for more precise channel value representation.
    • Added localization support for new scaling features.
  • Documentation

    • Updated translations for physical value scaling in English and Russian.

@pgasheev pgasheev requested review from a team, KraPete and sikmir as code owners January 17, 2025 07:54
Copy link

coderabbitai bot commented Jan 17, 2025

Walkthrough

This pull request introduces version 2.153.2 of the wb-mqtt-serial package, focusing on enhancing the WB-MAI6 template configuration. The primary change involves adding a scale for physical values in the template, which allows for more detailed representation and conversion of channel measurements. The modifications include updating the JSON configuration template with new parameters for physical value scaling, conversion entries, and localized translations for both English and Russian languages.

Changes

File Change Summary
debian/changelog Added new version 2.153.2, attributed to Pavel Gasheev on January 22, 2025
templates/config-wb-mai6.json.jinja - Added physical value scale parameters
- Updated channel conversion entries
- Modified parameter groups
- Enhanced translations for scaling options

Sequence Diagram

sequenceDiagram
    participant Config as WB-MAI6 Configuration
    participant Channel as Input Channel
    participant Scale as Physical Value Scaler

    Config->>Channel: Define Channel Parameters
    Channel->>Scale: Apply Physical Value Scale
    Scale-->>Channel: Return Scaled Value
    Channel-->>Config: Update Configuration
Loading

Possibly related PRs

  • Feature/fw 274 mcm debounce #855: The changes in this PR involve the WB-MCM8 template, specifically updating the maximum debounce time, which is related to the handling of physical values in device templates, similar to the scaling enhancements introduced in the main PR for the WB-MAI6 template.

Suggested reviewers

  • KraPete
  • sikmir

Poem

🐰 A rabbit's tale of scaling might,
Where numbers dance in pure delight,
WB-MAI6 now can measure true,
With scales that bring a clearer view!
Precision hops from line to line, 🔢
A template's magic, oh so fine! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (Beta)
  • @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.

Copy link

@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: 0

🧹 Nitpick comments (2)
templates/config-wb-mai6.json.jinja (2)

275-291: Add description for physical value scale parameters.

While the implementation is solid, consider adding a description field to explain:

  • How the scale affects measurements
  • When to use different scales
  • Examples of typical use cases
 {
     "id": "in{{ ch_num }}_physical_value_scale",
     "title": "physical_value_scale_title",
     "group": "gg_in{{ ch_num }}_p_value",
     "order": 1,
     "readonly": true,
+    "description": "Defines the scale multiplier for converting raw values. Choose x1 for whole numbers, x0.1 for tenths, x0.01 for hundredths, or x0.001 for thousandths precision.",
     "enum": [1, 10, 100, 1000],

Also applies to: 612-628


913-945: Consider optimizing channel updates.

The implementation creates separate channels for each scale, which could impact performance when many channels are active. Consider:

  1. Using a single channel with dynamic scale updates
  2. Adding a note about performance implications in the template description

Also applies to: 1059-1076

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 749a11f and a59db8a.

📒 Files selected for processing (1)
  • templates/config-wb-mai6.json.jinja (28 hunks)
🔇 Additional comments (3)
templates/config-wb-mai6.json.jinja (3)

53-82: Well-structured UI group organization!

The new groups for value conversion and channels are logically organized and maintain a clean UI by disabling redundant titles.


1206-1209: Comprehensive translation coverage!

The new translations are well-organized and maintain consistency with the existing localization style.

Also applies to: 1331-1334


293-332: Consider improving parameter visibility logic.

The current implementation creates multiple min/max parameters for different scales, which could be confusing in the UI if the conditions aren't mutually exclusive. Consider:

  1. Adding validation to ensure only one scale's parameters are visible at a time
  2. Using dynamic updates to adjust the min/max ranges when scale changes

Run this script to verify the condition logic:

Also applies to: 630-669

✅ Verification successful

Visibility logic is correctly implemented - no changes needed

The current implementation ensures mutually exclusive visibility through:

  • Default case (undefined scale) showing only scale=1 parameters
  • Defined scales showing only matching scale parameters
  • Additional type validation ensuring parameters appear only for supported types
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential condition overlap in scale parameters
# Look for patterns where multiple scale conditions could be true simultaneously

rg -U "condition.*?physical_value_scale.*?\n.*?\{.*?\}" | grep -B1 "condition"

Length of output: 78


Script:

#!/bin/bash
# Find all template files and check scale-related conditions
echo "=== Template files ==="
fd -e jinja

echo -e "\n=== Scale conditions ==="
rg "physical_value_scale" -A 2 -B 2

echo -e "\n=== Scale parameters ==="
rg "\"scale\":" -A 2 -B 2

Length of output: 91169

Copy link

@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: 0

🧹 Nitpick comments (3)
templates/config-wb-mai6.json.jinja (3)

275-291: Good implementation of physical value scaling!

The scale parameter is well-designed with appropriate ranges and readonly protection. Consider adding a description field to explain the impact of each scale on the measurement range and precision.

 {
     "id": "in{{ ch_num }}_physical_value_scale",
     "title": "physical_value_scale_title",
     "group": "gg_in{{ ch_num }}_p_value",
     "order": 1,
     "readonly": true,
+    "description": "Defines the scale and precision of measurements. Higher scales provide finer precision but smaller range.",
     "enum": [1, 10, 100, 1000],
     "enum_titles": [
         "x1: [-32768; 32766]",

293-332: Robust implementation of scaled min/max parameters!

The implementation handles all scale factors correctly while maintaining backward compatibility. The ranges and defaults are appropriate for each scale.

Consider extracting the common condition parts into a Jinja2 macro to reduce code duplication:

+{% macro scale_condition(ch_num, value_scale) -%}
+(
+    {%- if value_scale == 1 -%}
+    isDefined(in{{ ch_num }}_physical_value_scale)==0||
+    {%- endif -%}
+    in{{ ch_num }}_physical_value_scale=={{value_scale}})&&({{ format_list(ch_num, TYPES_WITH_MIN_MAX, "in%s_type==%s") }})
+{%- endmacro %}

 {
     "id": "in{{ ch_num }}_min",
     ...
-    "condition": "(
-        {%- if value_scale == 1 -%}
-        isDefined(in{{ ch_num }}_physical_value_scale)==0||
-        {%- endif -%}
-        in{{ ch_num }}_physical_value_scale=={{value_scale}})&&({{ format_list(ch_num, TYPES_WITH_MIN_MAX, "in%s_type==%s") }})"
+    "condition": "{{ scale_condition(ch_num, value_scale) }}"

Line range hint 1-1354: Excellent implementation of physical value scaling!

The changes provide a robust and backward-compatible solution for scaling physical values. The implementation is well-structured with proper organization of groups, parameters, channels, and translations.

Consider documenting the following aspects in the project's technical documentation:

  1. The relationship between physical value scales and measurement accuracy
  2. Guidelines for selecting appropriate scales based on sensor types
  3. Impact on data resolution and storage requirements
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a59db8a and 9d449b9.

📒 Files selected for processing (1)
  • templates/config-wb-mai6.json.jinja (28 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (3)
templates/config-wb-mai6.json.jinja (3)

53-82: Well-structured group organization!

The new groups for physical value conversion and channels are logically organized and follow consistent naming conventions. The UI options to disable titles help reduce visual clutter in the interface.


Line range hint 747-1077: Consistent channel configuration with scale support!

The channel configurations are well-aligned with the parameter changes. The group assignments and scale-specific conditions are implemented correctly.


Line range hint 1206-1334: Complete and consistent translations!

All new fields have appropriate translations in both English and Russian, maintaining consistency in terminology across the interface.

Copy link

@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: 0

🧹 Nitpick comments (3)
templates/config-wb-mai6.json.jinja (3)

275-291: Consider adding parameter documentation.

While the implementation is correct, adding a description field to explain the purpose and impact of the physical value scale would improve user understanding. For example:

 {
     "id": "in{{ ch_num }}_physical_value_scale",
     "title": "physical_value_scale_title",
     "group": "gg_in{{ ch_num }}_p_value",
     "order": 1,
     "readonly": true,
+    "description": "Defines the scale factor for converting raw values to physical quantities. Higher scales provide better precision for smaller values.",
     "enum": [1, 10, 100, 1000],
     "enum_titles": [
         "[-32768; 32766]",

Also applies to: 612-628


Line range hint 747-1077: Consider reducing channel definition duplication.

The channel definitions for P and N channels contain significant duplication. Consider extracting common properties into Jinja2 macros:

{% macro create_channel(name, type, format, scale, group, condition) %}
{
    "name": "{{ name }}",
    "type": "{{ type }}",
    "reg_type": "input",
    "format": "{{ format }}",
    "scale": {{ scale }},
    "group": "{{ group }}",
    "condition": "{{ condition }}"
}
{% endmacro %}

This would make the template more maintainable and reduce the chance of inconsistencies.


Line range hint 1-1354: Consider template modularization for better maintainability.

The template is becoming quite large and complex. Consider splitting it into smaller, focused templates:

  1. Create separate templates for P and N channel configurations
  2. Extract common parameter definitions into reusable includes
  3. Move translations to separate files

This would improve maintainability and make the template easier to understand and modify.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9e7cb1f and b7bec21.

📒 Files selected for processing (1)
  • templates/config-wb-mai6.json.jinja (28 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (3)
templates/config-wb-mai6.json.jinja (3)

53-82: Well-structured UI group organization!

The new groups for physical value conversion and channels are logically organized and follow a consistent pattern for both P and N channels.


293-332: Consider handling undefined scales more robustly.

The current implementation assumes scale=1 as the fallback when physical_value_scale is undefined. While this works, it could be more explicit:

  1. Consider adding a comment explaining this default behavior
  2. Consider adding validation to ensure physical_value_scale can't be undefined for other scales

This would make the code more maintainable and prevent potential issues if the parameter structure changes in the future.

Also applies to: 630-669


Line range hint 1206-1334: Comprehensive translation coverage!

All new UI elements have proper translations in both English and Russian, maintaining consistency with the existing translation patterns.

@pgasheev pgasheev merged commit 1e31677 into master Jan 23, 2025
14 checks passed
@pgasheev pgasheev deleted the feature/rework-mai6-template branch January 23, 2025 14:00
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.

3 participants