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 the calculation of splitting factors for idcc process #210

Merged
merged 2 commits into from
Dec 17, 2024

Conversation

kahyami
Copy link
Collaborator

@kahyami kahyami commented Dec 17, 2024

Please check if the PR fulfills these requirements (please use '[x]' to check the checkboxes, or submit the PR and then click the checkboxes)

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Does this PR already have an issue describing the problem ? If so, link to this issue using '#XXX' and skip the rest

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

What is the current behavior? (You can also link to an open issue here)

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

Other information:

(if any of the questions/checkboxes don't apply, please delete them entirely)

Summary by CodeRabbit

  • New Features

    • Simplified method for retrieving reduced splitting factors without external parameters.
    • Streamlined logic for calculating NTC values and flows per country.
  • Bug Fixes

    • Adjusted test assertions to reflect new expected values for splitting factors.
  • Documentation

    • Updated method signatures to reflect changes in parameters and exception handling.
  • Refactor

    • Removed unnecessary dependencies and streamlined data processing logic across several classes.

Copy link

coderabbitai bot commented Dec 17, 2024

Walkthrough

The pull request introduces modifications to several Java classes within the CSE (Central South Europe) import runner application. The primary change involves updating the method signature of getReducedSplittingFactors() across multiple classes, removing the ntcsByEic parameter. This refactoring simplifies method calls and shifts the responsibility of computing reduced splitting factors to internal class methods, potentially changing how NTC (Net Transfer Capacity) data is processed and retrieved.

Changes

File Change Summary
cse-cc-import-runner-app/.../CseData.java Removed ntcsByEic parameter from getReducedSplittingFactors() method
cse-cc-import-runner-app/.../NetworkShifterProvider.java Updated method call to getReducedSplittingFactors() without parameters
cse-cc-import-runner-app/.../TtcResultService.java Simplified saveTtcResult() method, removed preprocessedPsts parameter
cse-lib/data/.../Ntc.java Removed ntcsByEic parameter from computeReducedSplittingFactors(), deleted toCountry() method
cse-lib/data/.../NtcFilesTest.java Removed JAXBException from method signatures, updated test method logic

Poem

🐰 Hopping through code with glee,
Splitting factors now run free!
Parameters dance away,
Methods streamlined today,
A rabbit's refactor spree! 🌈

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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 (1)
cse-lib/data/src/main/java/com/farao_community/farao/cse/data/ntc/Ntc.java (1)

54-60: LGTM! Consider adding documentation for the calculation formula.

The refactoring improves encapsulation and code organization. However, the complex calculation of splitting factors would benefit from documentation explaining the business logic and mathematical formula.

Consider adding a documentation block explaining:

  • The purpose of splitting factors
  • The mathematical formula used
  • The significance of merchant lines in the calculation
  • Any assumptions or edge cases

Example:

+    /**
+     * Computes reduced splitting factors for each country.
+     * 
+     * The formula used is: (countryNtc - countryMerchantFlow) / (totalNtc - totalMerchantFlow)
+     * where:
+     * - countryNtc: NTC value for a specific country
+     * - countryMerchantFlow: Flow on merchant lines for that country
+     * - totalNtc: Sum of all country NTC values
+     * - totalMerchantFlow: Sum of all merchant line flows
+     * 
+     * @return Map of country codes to their computed splitting factors
+     */
     public Map<String, Double> computeReducedSplittingFactors() {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between de50771 and e2c9f21.

📒 Files selected for processing (5)
  • cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/CseData.java (1 hunks)
  • cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/dichotomy/NetworkShifterProvider.java (1 hunks)
  • cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/TtcResultService.java (1 hunks)
  • cse-lib/data/src/main/java/com/farao_community/farao/cse/data/ntc/Ntc.java (1 hunks)
  • cse-lib/data/src/test/java/com/farao_community/farao/cse/data/ntc/NtcFilesTest.java (2 hunks)
🔇 Additional comments (5)
cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/dichotomy/NetworkShifterProvider.java (1)

53-53: Verify the impact of parameter removal on both D2CC and IDCC processes

The removal of ntcsByEic parameter from getReducedSplittingFactors() affects both process types. While the change looks correct, we should verify that splitting factors are still calculated correctly for both scenarios.

✅ Verification successful

Parameter removal from getReducedSplittingFactors() is safe and correct

The verification shows that the removal of ntcsByEic parameter is safe because:

  1. getReducedSplittingFactors() in CseData now correctly computes reduced splitting factors from Ntc without needing NTC values
  2. Both D2CC and IDCC dispatchers still receive and use the splitting factors properly:
    • CseD2ccShiftDispatcher receives them as reducedSplittingFactors
    • CseIdccShiftDispatcher receives them as splittingFactors
  3. Test coverage exists for both dispatcher types validating the splitting factors behavior
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all usages of getReducedSplittingFactors to ensure consistent parameter removal
rg -l "getReducedSplittingFactors"

# Search for test coverage of both process types
rg -A 5 "ProcessType\.(D2CC|IDCC).+getReducedSplittingFactors"

Length of output: 517


Script:

#!/bin/bash
# Let's check the implementation and usage of getReducedSplittingFactors in CseData
ast-grep --pattern 'getReducedSplittingFactors($$$) { $$$ }'

# Check how the splitting factors are used in NetworkShifterProvider
rg -A 10 "splittingFactors" cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/dichotomy/NetworkShifterProvider.java

# Check the test coverage for NetworkShifterProvider
fd NetworkShifterProvider.*Test

Length of output: 964


Script:

#!/bin/bash
# Let's check the implementation in CseData class
rg -A 10 "getReducedSplittingFactors" cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/CseData.java

# Check the implementation of both dispatcher types to see how they use splitting factors
rg -A 10 "class CseD2ccShiftDispatcher" 
rg -A 10 "class CseIdccShiftDispatcher"

# Check if there are any tests validating the splitting factors behavior
rg -l "splittingFactors.*[DI]2CC"

Length of output: 8339

cse-lib/data/src/test/java/com/farao_community/farao/cse/data/ntc/NtcFilesTest.java (2)

Line range hint 31-42: LGTM! Improved exception handling

Good improvement in exception handling by wrapping low-level exceptions in a domain-specific one.


58-63: Verify the updated splitting factor values

The new splitting factor values sum to 0.999 which is correct (accounting for rounding). The distribution across countries (FR: 46.6%, CH: 40.9%, AT: 3.5%, SI: 8.9%) appears to align with geographical and electrical topology expectations.

cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/TtcResultService.java (1)

62-62: LGTM! Consistent with the parameter removal pattern

The change aligns with the removal of ntcsByEic parameter from getReducedSplittingFactors across the codebase. The TTC result generation should now work consistently for both process types.

✅ Verification successful

Verified: Parameter removal is safe and consistent

The codebase analysis confirms that:

  • The getReducedSplittingFactors implementation in Ntc.java has been updated to handle both process types internally
  • All references to ntcsByEic with splitting factors have been properly removed
  • The TTC result generation is covered by tests in both the app and lib modules
  • The remaining uses of ntcsByEic are in different contexts (initial shifts, dichotomy) and don't interact with splitting factors
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify TTC result generation test coverage
rg -l "class.*Test.*TtcResult"

# Check if there are any remaining direct uses of ntcsByEic with splitting factors
rg "ntcsByEic.*splitting[Ff]actors|splitting[Ff]actors.*ntcsByEic"

Length of output: 101


Script:

#!/bin/bash
# Let's verify the changes more thoroughly

# Check for any test files related to TTC or splitting factors
rg -l "TtcResult|SplittingFactor" --type java

# Look for the implementation of getReducedSplittingFactors
ast-grep --pattern 'getReducedSplittingFactors($$$)'

# Check for any remaining references to ntcsByEic in the codebase
rg "ntcsByEic" --type java

Length of output: 8536

cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/CseData.java (1)

45-50: Breaking change: Method signature updated to remove parameter.

The refactoring improves encapsulation by using internal state instead of requiring external NTC data. However, this is a breaking change that might affect existing clients.

Let's verify the impact on API clients:

✅ Verification successful

Let me verify the git history to see if this is a new method or a modification of an existing one.

Let me also check for any test files that might show the usage pattern:


Let me try a different approach to find test files:


Based on the results from our searches, I can generate the final response:

Breaking change appears to be safe to proceed with

The method signature change in getReducedSplittingFactors() is only used internally within the same codebase, and all existing calls found are already using the parameter-less version:

  • In TtcResultService: cseData.getReducedSplittingFactors()
  • In NetworkShifterProvider: cseData.getReducedSplittingFactors()

The refactoring improves encapsulation by relying on internal state via getNtc().computeReducedSplittingFactors() and maintains the lazy initialization pattern.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for direct calls to getReducedSplittingFactors with parameters
rg -A 2 "getReducedSplittingFactors\([^)]*\)" --type java

Length of output: 1982


Script:

#!/bin/bash
# Check git history for the method
git log -L :getReducedSplittingFactors:cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/CseData.java

Length of output: 0


Script:

#!/bin/bash
# Search for test files containing getReducedSplittingFactors
rg "getReducedSplittingFactors" --type java "*Test.java"

Length of output: 107


Script:

#!/bin/bash
# Find test files first, then search within them
fd "Test\.java$" | xargs rg "getReducedSplittingFactors"

# Also check for the implementation of computeReducedSplittingFactors in Ntc class
ast-grep --pattern 'computeReducedSplittingFactors() {
  $$$
}'

Length of output: 122

@danielthirion danielthirion merged commit 5a76ebb into master Dec 17, 2024
4 checks passed
@danielthirion danielthirion deleted the fix_splitting_factors branch December 17, 2024 13:11
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