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

fix(mcdaStyle): 18809 don't show hexes with MCDA value === Infinity on the map #777

Conversation

albaranau
Copy link
Contributor

@albaranau albaranau commented Jun 27, 2024

https://kontur.fibery.io/Tasks/Task/FE-MCDA-hex-shows-Infinity-result-if-the-denominator-is-0-18809

UPD: It was decided to not filter out Infinity values on FE (because they can be valid in theory), and instead to try and fix this on BE/data side within MVTs. See comment: https://kontur.fibery.io/Tasks/Task/FE-MCDA-hex-shows-Infinity-result-if-the-denominator-is-0-18809/comment=23678

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling to prevent division by zero in calculations, ensuring more stable performance.
    • Marked invalid results (like Infinity) as transparent to avoid display issues.

Copy link
Contributor

coderabbitai bot commented Jun 27, 2024

Walkthrough

The recent updates to the mcdaStyle.ts file focus on enhancing the robustness of division operations by ensuring that the numerator and denominator are valid, preventing division by zero errors and handling Infinity results gracefully. This includes introducing checks to filter out scenarios where the numerator or denominator are null or 0, thus setting such results to 'transparent' to avoid invalid outcomes.

Changes

File Change Summary
src/core/logical_layers/renderers/stylesConfigs/mcda/mcdaStyle.ts Added checks in the filterSetup function to ensure numerator and denominator are not null or 0, preventing division by zero errors and handling Infinity results.

Poem

Amidst the code, where bugs might lurk,
We added checks, it's thorough work.
Division by zero, not allowed,
Now results stay clear, and we’re proud.
Infinity tamed, with care precise,
Our rabbit code, now safer, nice.
Transparent fields, errors fixed,
In lines of code, improvements mixed. 🐇✨


Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI gpt-4o model for code reviews and chat: OpenAI claims that this model is better at understanding and generating code than the previous models. We seek your feedback over the next few weeks before making it generally available.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues.
  • OSS projects are currently opted into early access features by default.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@albaranau albaranau requested a review from a team June 27, 2024 22:55
@albaranau albaranau self-assigned this Jun 27, 2024
Copy link

Language To Recheck Fuzzy Untranslated Total
ar 3 24 101 128
de 2 24 101 127
es 3 24 101 128
id 2 24 101 127
ko 3 24 101 128
uk 0 7 8 15

Copy link

github-actions bot commented Jun 27, 2024

Bundle size diff

Old size New size Diff
4.93 MB 4.93 MB 39 B (0.00%)

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: 1

Outside diff range comments (2)
src/core/logical_layers/renderers/stylesConfigs/mcda/mcdaStyle.ts (2)

Line range hint 53-53: Replace non-null assertion with optional chaining.

Using non-null assertions can lead to potential runtime errors. It's safer to use optional chaining which includes runtime checks.

- return ['/', calculateLayer(layers.at(0)!), layers.at(0)!.coefficient];
+ return ['/', calculateLayer(layers.at(0)?.), layers.at(0)?.coefficient];
Tools
Biome

[error] 103-103: Use Number.Infinity instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.Infinity instead.

(lint/style/useNumberNamespace)


Line range hint 54-56: Remove unnecessary else clause.

The else clause is redundant since all previous branches in the conditional logic break early.

- else {
-   return expressionsPaint(props);
- }
+ return expressionsPaint(props);
Tools
Biome

[error] 103-103: Use Number.Infinity instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.Infinity instead.

(lint/style/useNumberNamespace)

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between bbfd01b and 2499b8c.

Files selected for processing (1)
  • src/core/logical_layers/renderers/stylesConfigs/mcda/mcdaStyle.ts (1 hunks)
Additional context used
Biome
src/core/logical_layers/renderers/stylesConfigs/mcda/mcdaStyle.ts

[error] 53-53: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 53-53: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)


[error] 54-56: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)


[error] 103-103: Use Number.Infinity instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.Infinity instead.

(lint/style/useNumberNamespace)

@albaranau
Copy link
Contributor Author

It was decided to not filter out Infinity values on FE (because they can be valid in theory), and instead to try and fix this on BE/data side within MVTs. See comment: https://kontur.fibery.io/Tasks/Task/FE-MCDA-hex-shows-Infinity-result-if-the-denominator-is-0-18809/comment=23678

@albaranau albaranau closed this Jun 28, 2024
@albaranau albaranau reopened this Jun 28, 2024
@albaranau albaranau marked this pull request as draft June 28, 2024 18:04
@albaranau albaranau marked this pull request as draft June 28, 2024 18:04
@albaranau albaranau requested review from Komzpa June 28, 2024 18:06
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: 1

Outside diff range comments (2)
src/core/logical_layers/renderers/stylesConfigs/mcda/mcdaStyle.ts (2)

Line range hint 62-62: Replace non-null assertion with optional chaining.

The non-null assertion here is flagged as unsafe. Using optional chaining (?.) is a safer alternative that also handles cases where the object might be undefined.

- return ['/', calculateLayer(layers.at(0)!), layers.at(0)!.coefficient];
+ return ['/', calculateLayer(layers.at(0)?.), layers.at(0)?.coefficient];

Line range hint 63-65: Remove unnecessary else clause.

Since the previous branches (if conditions) handle all cases that break out of the function early, the else clause is redundant and can be omitted for cleaner code.

- } else {
-   return ['/', ['+', ...layers.map(calculateLayer)], sumBy(layers, 'coefficient')];
- }
+ return ['/', ['+', ...layers.map(calculateLayer)], sumBy(layers, 'coefficient')];
Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 2499b8c and 0e586cd.

Files selected for processing (1)
  • src/core/logical_layers/renderers/stylesConfigs/mcda/mcdaStyle.ts (1 hunks)
Additional context used
Biome
src/core/logical_layers/renderers/stylesConfigs/mcda/mcdaStyle.ts

[error] 62-62: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 62-62: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)


[error] 63-65: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)

@albaranau albaranau marked this pull request as ready for review July 2, 2024 09:00
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

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 0e586cd and 1d78110.

Files selected for processing (1)
  • src/core/logical_layers/renderers/stylesConfigs/mcda/mcdaStyle.ts (1 hunks)

@albaranau albaranau requested a review from vkozio July 2, 2024 09:03
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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 1d78110 and 15272b8.

Files selected for processing (1)
  • src/core/logical_layers/renderers/stylesConfigs/mcda/mcdaStyle.ts (1 hunks)
Additional comments not posted (4)
src/core/logical_layers/renderers/stylesConfigs/mcda/mcdaStyle.ts (4)

Line range hint 53-60: LGTM!

The linearNormalization function is well-implemented and handles the normalization of layer values correctly.


Line range hint 62-91: LGTM!

The sentimentPaint function is well-implemented and generates the paint properties correctly based on the MCDA result and color configuration.


Line range hint 93-115: LGTM!

The expressionsPaint function is well-implemented and generates the paint properties correctly based on the MCDA result and expression configuration.


Line range hint 117-162: LGTM!

The createMCDAStyle function is well-implemented and creates the MCDA style configuration correctly based on the provided configuration.

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

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 15272b8 and e96ebaa.

Files ignored due to path filters (1)
  • src/core/logical_layers/renderers/stylesConfigs/mcda/__snapshots__/mcdaStyle.test.ts.snap is excluded by !**/*.snap, !**/*.snap
Files selected for processing (1)
  • src/core/logical_layers/renderers/stylesConfigs/mcda/mcdaStyle.ts (2 hunks)
Additional comments not posted (2)
src/core/logical_layers/renderers/stylesConfigs/mcda/mcdaStyle.ts (2)

46-50: Add checks for null values in the denominator.

The added condition for checking zero in the denominator is good. However, consider adding checks for null values to make the function more robust.

-      // this checks for 0 in denominator (0 in denominator makes the result === Infinity)
+      // this checks for 0 or null in the denominator (which causes the result to be Infinity or invalid)
       notEqual(featureProp(axis[1]), 0),
+      notEqual(featureProp(axis[1]), null),

51-51: Use Number.POSITIVE_INFINITY for consistency.

To align with modern JavaScript standards, use Number.POSITIVE_INFINITY instead of Infinity.

-      ['==', ['var', 'mcdaResult'], Infinity],
+      ['==', ['var', 'mcdaResult'], Number.POSITIVE_INFINITY],

@albaranau albaranau merged commit 2c9a174 into main Jul 2, 2024
7 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.

3 participants