Skip to content

Additional External Program datasheets#37

Merged
katieb1 merged 4 commits intomainfrom
kb-ext-program-datasheets
Aug 28, 2025
Merged

Additional External Program datasheets#37
katieb1 merged 4 commits intomainfrom
kb-ext-program-datasheets

Conversation

@katieb1
Copy link
Member

@katieb1 katieb1 commented Aug 28, 2025

Adds stsim_DistributionValue and stsim_TransitionSizeDistribution

Summary by CodeRabbit

  • New Features

    • Added support for processing Transition Size Distribution and Distribution Value data sheets when external data is available.
    • Automatically refreshes related distributions and maps to keep scenario data current after updates.
  • Refactor

    • Simplified internal distribution handling by removing internal identifiers and key-based lookup; collection semantics streamlined.
    • Broadened internal accessibility of distribution helpers to enable reloading; no user-facing behavior changes.

@coderabbitai
Copy link

coderabbitai bot commented Aug 28, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds external-data handlers to reload transition-size distributions and distribution values; makes two distribution-provider methods internal and adds ReloadDistributionValuesFromScenario; removes TransitionSizeDistribution ID and keyed collection behavior, updating constructors and collection usage accordingly.

Changes

Cohort / File(s) Change Summary
External data handlers wiring
src/Runtime/STSimTransformer.ExtProc.cs
Adds else-if branches in ExtProcOnExternalDataReady to handle DATASHEET_TRANSITION_SIZE_DISTRIBUTION_NAME (clear/refill transition size distributions and rebuild map) and DISTRIBUTION_VALUE_DATASHEET_NAME (call DistributionProvider.ReloadDistributionValuesFromScenario to reload distribution values).
TransitionSizeDistribution: signature and model
src/Runtime/TransitionSizeDistribution.cs
Removes internal distribution ID field and public TransitionSizeDistributionId property; updates constructor to remove the ID parameter.
Collection changes for transition sizes
src/Runtime/TransitionSizeDistributionCollection.cs
Changes base from KeyedCollection<int, TransitionSizeDistribution> to Collection<TransitionSizeDistribution> and removes GetKeyForItem override (drops key-based lookup).
Construction/site updates using new constructor
src/Runtime/STSimTransformer.Collections.cs
Stops reading/using TransitionSizeDistributionId from data rows and constructs TransitionSizeDistribution with (StratumId, Iteration, Timestep, TransitionGroupId, MaximumSize, RelativeAmount) (new constructor signature).
Visibility and reload API in DistributionProvider
src/Statistics/STSimDistributionProvider.cs
Widens visibility of existing methods to internal (FillDistributionValueCollection, CreateDistributionValueMap) and adds internal ReloadDistributionValuesFromScenario() which clears/repopulates distribution values and rebuilds the value map.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 97fe7d0 and 6e119b2.

📒 Files selected for processing (2)
  • src/Runtime/STSimTransformer.ExtProc.cs (1 hunks)
  • src/Statistics/STSimDistributionProvider.cs (3 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kb-ext-program-datasheets

🪧 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.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit 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:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@katieb1 katieb1 requested a review from alexembrey August 28, 2025 18:21
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: 3

🧹 Nitpick comments (2)
src/Statistics/STSimDistributionProvider.cs (2)

56-56: Access widening OK, but document preconditions

Keeping FillDistributionValueCollection internal is fine if called only via the new reload API. Add XML doc noting the precondition m_DistributionValues.Count == 0 to prevent future misuse.


102-102: Map creation visibility change is acceptable; consider atomic publish

Internal is fine. If concurrent access ever becomes a concern, build the map in a local variable and assign to m_DistributionValueMap once to avoid transient nulls.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between cc12775 and 7b62c40.

📒 Files selected for processing (2)
  • src/Runtime/STSimTransformer.ExtProc.cs (1 hunks)
  • src/Statistics/STSimDistributionProvider.cs (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/Runtime/STSimTransformer.ExtProc.cs (3)
src/Shared/Strings.cs (1)
  • Strings (8-700)
src/Runtime/STSimTransformer.Collections.cs (1)
  • FillTransitionSizeDistributionCollection (2232-2277)
src/Statistics/STSimDistributionProvider.cs (2)
  • FillDistributionValueCollection (56-100)
  • CreateDistributionValueMap (102-111)
src/Statistics/STSimDistributionProvider.cs (1)
src/Statistics/STSimDistributionValueMap.cs (2)
  • DistributionValueCollection (34-51)
  • STSimDistributionValueMap (9-52)

Copy link
Collaborator

@alexembrey alexembrey left a comment

Choose a reason for hiding this comment

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

As per our discussion looks good

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/Runtime/TransitionSizeDistribution.cs (1)

17-27: Constructor change looks good; add invariant checks and make MinimumSize initialisation explicit

Dropping the ID simplifies usage. Please also guard inputs and set m_MinimumSize explicitly to avoid relying on default initialisation.

         public TransitionSizeDistribution(
             int? stratumId, int? iteration, int? timestep, 
             int transitionGroupId, double maximumSize, double relativeAmount)
         {
             this.m_StratumId = stratumId;
             this.m_Iteration = iteration;
             this.m_Timestep = timestep;
             this.m_TransitionGroupId = transitionGroupId;
-            this.m_MaximumSize = maximumSize;
-            this.m_RelativeAmount = relativeAmount;
+            if (maximumSize <= 0)
+            {
+                throw new ArgumentOutOfRangeException(nameof(maximumSize), "Maximum size must be > 0.");
+            }
+            if (double.IsNaN(relativeAmount) || relativeAmount < 0)
+            {
+                throw new ArgumentOutOfRangeException(nameof(relativeAmount), "Relative amount must be ≥ 0.");
+            }
+            this.m_MinimumSize = 0.0; // explicit default
+            this.m_MaximumSize = maximumSize;
+            this.m_RelativeAmount = relativeAmount;
         }
src/Runtime/STSimTransformer.Collections.cs (1)

2244-2275: Constructor call is correct; add defensive validation on row values before creating items

Prevent bad data from propagating (negative/zero sizes or amounts) and fail fast with a clear message tied to the datasheet.

             DataSheet ds = this.ResultScenario.GetDataSheet(Strings.DATASHEET_TRANSITION_SIZE_DISTRIBUTION_NAME);

             foreach (DataRow dr in ds.GetData().Rows)
             {
                 int? StratumId = null;
                 int? Iteration = null;
                 int? Timestep = null;
                 int TransitionGroupId = Convert.ToInt32(dr[Strings.DATASHEET_TRANSITION_GROUP_ID_COLUMN_NAME], CultureInfo.InvariantCulture);
                 double MaximumSize = Convert.ToDouble(dr[Strings.DATASHEET_TRANSITION_SIZE_DISTRIBUTION_MAXIMUM_AREA_COLUMN_NAME], CultureInfo.InvariantCulture);
                 double RelativeAmount = Convert.ToDouble(dr[Strings.DATASHEET_TRANSITION_SIZE_DISTRIBUTION_RELATIVE_AMOUNT_COLUMN_NAME], CultureInfo.InvariantCulture);
+                if (MaximumSize <= 0)
+                {
+                    throw new ArgumentException(ds.DisplayName + " -> Maximum area must be > 0.");
+                }
+                if (double.IsNaN(RelativeAmount) || RelativeAmount < 0)
+                {
+                    throw new ArgumentException(ds.DisplayName + " -> Relative amount must be ≥ 0.");
+                }

                 if (dr[Strings.DATASHEET_STRATUM_ID_COLUMN_NAME] != DBNull.Value)
                 {
                     StratumId = Convert.ToInt32(dr[Strings.DATASHEET_STRATUM_ID_COLUMN_NAME], CultureInfo.InvariantCulture);
                 }

                 if (dr[Strings.DATASHEET_ITERATION_COLUMN_NAME] != DBNull.Value)
                 {
                     Iteration = Convert.ToInt32(dr[Strings.DATASHEET_ITERATION_COLUMN_NAME], CultureInfo.InvariantCulture);
                 }

                 if (dr[Strings.DATASHEET_TIMESTEP_COLUMN_NAME] != DBNull.Value)
                 {
                     Timestep = Convert.ToInt32(dr[Strings.DATASHEET_TIMESTEP_COLUMN_NAME], CultureInfo.InvariantCulture);
                 }

                 TransitionSizeDistribution tsd = new TransitionSizeDistribution(
                     StratumId, Iteration, Timestep, TransitionGroupId, MaximumSize, RelativeAmount);
🧹 Nitpick comments (1)
src/Runtime/TransitionSizeDistribution.cs (1)

89-99: Validate Proportion on set to keep it within [0, 1]

Avoid accidental invalid values leaking into later calculations.

         public double Proportion
         {
             get
             {
                 return this.m_Proportion;
             }
             set
             {
-                this.m_Proportion = value;
+                if (double.IsNaN(value) || value < 0.0 || value > 1.0)
+                {
+                    throw new ArgumentOutOfRangeException(nameof(value), "Proportion must be between 0 and 1.");
+                }
+                this.m_Proportion = value;
             }
         }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7b62c40 and 97fe7d0.

📒 Files selected for processing (4)
  • src/Runtime/STSimTransformer.Collections.cs (1 hunks)
  • src/Runtime/STSimTransformer.ExtProc.cs (1 hunks)
  • src/Runtime/TransitionSizeDistribution.cs (1 hunks)
  • src/Runtime/TransitionSizeDistributionCollection.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Runtime/STSimTransformer.ExtProc.cs
🧰 Additional context used
🧬 Code graph analysis (1)
src/Runtime/TransitionSizeDistributionCollection.cs (1)
src/Runtime/TransitionSizeDistribution.cs (2)
  • TransitionSizeDistribution (6-100)
  • TransitionSizeDistribution (17-27)
🔇 Additional comments (2)
src/Runtime/TransitionSizeDistributionCollection.cs (1)

8-10: Verified removal of keyed Collection is safe
No lingering GetKeyForItem or keyed semantics for TransitionSizeDistribution; TransitionSizeDistributionMap and its usages provide efficient ID-based lookups.

src/Runtime/STSimTransformer.Collections.cs (1)

2233-2246: No clearing needed: collection is fresh on init and explicitly cleared in ext-proc. In the default spatial initialization m_TransitionSizeDistributions is newly constructed and only filled once, so the debug assert always holds. In STSimTransformer.ExtProc the code calls m_TransitionSizeDistributions.Clear() before each refill and rebuilds the map.

@katieb1 katieb1 merged commit a8e2879 into main Aug 28, 2025
1 check was pending
@katieb1 katieb1 deleted the kb-ext-program-datasheets branch August 28, 2025 19:36
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