Skip to content

Add function to calculate nitrogen balance#134

Merged
SvenVw merged 143 commits into
developmentfrom
add-calculate-nitrogen-balance
May 27, 2025
Merged

Add function to calculate nitrogen balance#134
SvenVw merged 143 commits into
developmentfrom
add-calculate-nitrogen-balance

Conversation

@SvenVw
Copy link
Copy Markdown
Collaborator

@SvenVw SvenVw commented Apr 30, 2025

Summary by CodeRabbit

  • New Features

    • Introduced comprehensive nitrogen balance tools covering supply, removal, and volatilization for agricultural fields.
    • Added new soil analysis parameters: organic carbon, carbon/nitrogen ratio, bulk density, and total nitrogen content.
    • Enhanced field data with geographic centroid coordinates.
    • Expanded cultivation catalogue with crop rotation, yield, harvest index, nitrogen content, residue nitrogen, and nitrogen fixation attributes.
    • Added nitrogen supply calculations from fertilizers (mineral, manure, compost, other), biological fixation, atmospheric deposition, and soil mineralization.
    • Added nitrogen removal calculations from harvests and crop residues, including ammonia volatilization estimates.
    • Enabled public access to additional types for cultivations, harvests, fields, and soil analyses.
    • Added functions to collect input data and perform nitrogen balance calculations with detailed error handling.
  • Bug Fixes

    • Improved harvest component data access to handle singular harvestable objects, ensuring accurate yield and nitrogen display.
  • Refactor

    • Standardized and renamed data structures and types for cultivations, harvests, fertilizers, soil analyses, and fields.
    • Updated interfaces and type declarations for consistency and clarity.
    • Changed cultivation and harvest data structures to use singular objects instead of arrays where appropriate.
    • Adjusted build configs for environment-aware source maps; added dependencies for date handling, decimal arithmetic, and geospatial processing.
  • Tests

    • Added extensive test suites covering nitrogen balance calculations, soil property conversions, supply/removal modules, volatilization, and data collection to ensure accuracy and robustness.
  • Chores

    • Updated dependencies and build configurations for improved development experience.
    • Enhanced cultivation catalogue data validation, including crop rotation value checks.
    • Improved documentation and descriptions for soil parameters and cultivation data.

@SvenVw SvenVw added this to the Alpha release milestone Apr 30, 2025
@SvenVw SvenVw self-assigned this Apr 30, 2025
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 30, 2025

🦋 Changeset detected

Latest commit: 3bee620

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@svenvw/fdm-core Minor
@svenvw/fdm-calculator Minor
@svenvw/fdm-app Patch
@svenvw/fdm-data Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@SvenVw SvenVw linked an issue Apr 30, 2025 that may be closed by this pull request
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2025

Walkthrough

This update introduces a comprehensive nitrogen balance calculation feature for agricultural fields and farms. It adds new soil and cultivation properties, expands type definitions, updates database schemas, and implements detailed calculation modules, including supply, removal, and volatilization of nitrogen. Extensive test suites and utility functions support robust data processing and validation.

Changes

File(s) / Grouped Path(s) Change Summary
fdm-core/src/field.*, fdm-core/src/harvest.*, fdm-core/src/cultivation.*, fdm-core/src/soil.*, fdm-core/src/fertilizer.* Renamed interfaces/types for consistency; added new properties (e.g., b_centroid, m_cropresidue); updated function signatures and return types to match new structures; extended data models for soil, cultivation, and fertilizer.
fdm-core/src/db/schema.ts Added new enums and columns to support crop rotation, yield, nitrogen fixation, and extended soil analysis parameters.
fdm-core/src/index.ts Exported additional types for public API surface.
fdm-core/src/cultivation.test.ts, fdm-core/src/harvest.test.ts, fdm-core/src/field.test.ts, fdm-core/src/soil.test.ts Updated/extended tests for new and renamed properties.
fdm-core/src/timeframe.d.ts Refactored Timeframe type definition.
fdm-data/src/cultivations/catalogues/brp.ts, fdm-data/src/cultivations/d.ts Added validation and new properties for crop rotation and nitrogen metrics in cultivation catalogue.
fdm-app/app/components/custom/harvest/list.tsx, fdm-app/app/components/custom/harvest/types.tsx, fdm-app/app/routes/farm.$b_id_farm.$calendar.field.$b_id.cultivation.$b_lu.harvest.$b_id_harvesting.tsx, fdm-app/app/routes/farm.create.$b_id_farm.$calendar.cultivations.$b_lu_catalogue.crop.harvest.$b_id_harvesting.tsx Refactored harvest data access from arrays to singular objects; removed obsolete interface.
fdm-calculator/package.json, fdm-calculator/rollup.config.js Added dependencies (date-fns, decimal.js, geotiff); improved build/source map configuration.
fdm-calculator/src/balance/nitrogen/index.ts, fdm-calculator/src/balance/nitrogen/types.d.ts, fdm-calculator/src/balance/nitrogen/input.ts, fdm-calculator/src/balance/nitrogen/removal/index.ts, fdm-calculator/src/balance/nitrogen/removal/harvest.ts, fdm-calculator/src/balance/nitrogen/removal/residue.ts, fdm-calculator/src/balance/nitrogen/supply/index.ts, fdm-calculator/src/balance/nitrogen/supply/fixation.ts, fdm-calculator/src/balance/nitrogen/supply/deposition.ts, fdm-calculator/src/balance/nitrogen/supply/mineralization.ts, fdm-calculator/src/balance/nitrogen/supply/fertilizers/index.ts, fdm-calculator/src/balance/nitrogen/supply/fertilizers/mineral.ts, fdm-calculator/src/balance/nitrogen/supply/fertilizers/manure.ts, fdm-calculator/src/balance/nitrogen/supply/fertilizers/compost.ts, fdm-calculator/src/balance/nitrogen/supply/fertilizers/other.ts, fdm-calculator/src/balance/nitrogen/volatization/index.ts, fdm-calculator/src/balance/nitrogen/volatization/residues.ts Implemented nitrogen balance calculation modules: supply, removal, fixation, deposition, mineralization, volatilization, and supporting types.
fdm-calculator/src/conversions/soil.ts Added soil property conversion functions (organic carbon, organic matter, C/N ratio, bulk density).
fdm-calculator/src/index.ts Exported new nitrogen balance calculation and input functions/types.
fdm-calculator/src/balance/nitrogen/*.test.ts, fdm-calculator/src/conversions/soil.test.ts Added extensive test suites for all new calculation and conversion modules.
fdm-docs/package.json Reformatted browserslist for readability.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant Calculator
    participant CoreDB
    participant PublicData

    User->>App: Request nitrogen balance for farm
    App->>Calculator: collectInputForNitrogenBalance(farmId, timeframe)
    Calculator->>CoreDB: getFields, getCultivations, getHarvests, getSoilAnalyses, getFertilizerApplications, getFertilizers, getCultivationsFromCatalogue
    CoreDB-->>Calculator: Returns all required data
    Calculator->>Calculator: Assemble NitrogenBalanceInput
    App->>Calculator: calculateNitrogenBalance(NitrogenBalanceInput)
    Calculator->>PublicData: Fetch deposition raster (GeoTIFF)
    Calculator->>Calculator: Compute supply, removal, volatilization per field
    Calculator->>Calculator: Aggregate to farm-level balance
    Calculator-->>App: Return NitrogenBalanceNumeric
    App-->>User: Display nitrogen balance results
Loading

Possibly related PRs

  • Add soil analyses management #108: Introduces soil analyses management features including renamed arguments and new functions for current soil data retrieval; shares soil analysis data structure enhancements with this PR.
  • Add cultivations #9: Adds initial cultivation CRUD operations and catalogue extensions, overlapping with cultivation-related data model changes in this PR.
  • Add field management and soil analysis features #30: Adds new soil analysis properties and related functions, directly connected to soil analysis features and schema changes in this PR.

Poem

Hop, hop, a rabbit’s delight—
Nitrogen balance now shines bright!
With soil and crops, we count and weigh,
New types and tests lead the way.
Fields and farms in harmony dance,
Thanks to this code, crops get their chance!
🥕✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4961a84 and 3bee620.

⛔ Files ignored due to path filters (4)
  • fdm-core/src/db/migrations/0005_glorious_sugar_man.sql is excluded by !fdm-core/src/db/migrations/**
  • fdm-core/src/db/migrations/meta/0005_snapshot.json is excluded by !fdm-core/src/db/migrations/**
  • fdm-core/src/db/migrations/meta/_journal.json is excluded by !fdm-core/src/db/migrations/**
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • fdm-calculator/src/balance/nitrogen/supply/fertilizers/other.ts (1 hunks)
  • fdm-calculator/src/balance/nitrogen/types.d.ts (1 hunks)
  • fdm-core/src/index.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • fdm-calculator/src/balance/nitrogen/supply/fertilizers/other.ts
  • fdm-core/src/index.ts
  • fdm-calculator/src/balance/nitrogen/types.d.ts
✨ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

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

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2025

Codecov Report

Attention: Patch coverage is 94.35939% with 70 lines in your changes missing coverage. Please review.

Project coverage is 93.43%. Comparing base (24f0886) to head (3bee620).
Report is 144 commits behind head on development.

Files with missing lines Patch % Lines
...lculator/src/balance/nitrogen/supply/deposition.ts 70.76% 19 Missing ⚠️
fdm-core/src/cultivation.ts 50.00% 14 Missing ⚠️
...ator/src/balance/nitrogen/supply/mineralization.ts 82.19% 13 Missing ⚠️
fdm-calculator/src/balance/nitrogen/index.ts 95.72% 10 Missing ⚠️
...dm-calculator/src/balance/nitrogen/supply/index.ts 89.79% 5 Missing ⚠️
fdm-data/src/cultivations/catalogues/brp.ts 79.16% 4 Missing and 1 partial ⚠️
fdm-calculator/src/conversions/soil.ts 97.29% 2 Missing ⚠️
fdm-calculator/src/index.ts 0.00% 2 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff               @@
##           development     #134      +/-   ##
===============================================
+ Coverage        92.99%   93.43%   +0.44%     
===============================================
  Files               47       65      +18     
  Lines             6135     7327    +1192     
  Branches           698      899     +201     
===============================================
+ Hits              5705     6846    +1141     
- Misses             429      479      +50     
- Partials             1        2       +1     
Flag Coverage Δ
fdm-calculator 95.12% <95.30%> (+2.44%) ⬆️
fdm-core 93.12% <89.23%> (+0.17%) ⬆️
fdm-data 92.92% <79.16%> (-1.90%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

total: residues.total, // Ammonia total should include residues total
fertilizers: {
total: Decimal(0), // Fertilizers volatilization not yet implemented
mineral: {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

you might set it to the lowest value (EF or CAN) rather than zero.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This would lead to provide a wrong number as answer, better to give no answer until the calculation rules are clear for all sitatuations

},
manure: {
total: Decimal(0),
applications: [],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same here, you might select the value for most commont slurry and application technology as default EF.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This would lead to provide a wrong number as answer, better to give no answer until the calculation rules are clear for all sitatuations

Comment thread fdm-calculator/src/conversions/soil.ts
Comment thread fdm-core/src/db/schema.ts
"multiple",
])
export const rotationEnum = fdmSchema.enum("b_lu_croprotation", [
"other",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

name croprotation might be confusing here, since these are more crop categories than a rotation class, isn't? Might be renamed later

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Please provide a better name, changing later is more complicated

Copy link
Copy Markdown
Collaborator

@gerardhros gerardhros left a comment

Choose a reason for hiding this comment

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

Well done Sven. See some minor comments

Copy link
Copy Markdown
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

♻️ Duplicate comments (2)
fdm-calculator/src/conversions/soil.ts (1)

69-87: Past review comments successfully addressed.

The JSDoc documentation now correctly specifies that a_n_rt is in mg N/kg soil, and the /1000 conversion properly converts to g N/kg soil for the C/N ratio calculation. The implementation is correct and the boundary constraints (5-40) are appropriate for agricultural soils.

fdm-core/src/cultivation.ts (1)

111-116: 🛠️ Refactor suggestion

[DUPLICATE COMMENT] Consider adding validation for nitrogen-related parameters.

As noted in previous reviews, the new nitrogen-related parameters (b_lu_croprotation, b_lu_yield, b_lu_hi, b_lu_n_harvestable, b_lu_n_residue, b_n_fixation) lack validation. Consider adding range checks to ensure data integrity before database insertion.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e8e60fc and b13f518.

📒 Files selected for processing (9)
  • .changeset/clear-guests-taste.md (1 hunks)
  • .changeset/fine-symbols-taste.md (1 hunks)
  • .changeset/swift-colts-watch.md (1 hunks)
  • .changeset/true-windows-scream.md (1 hunks)
  • fdm-calculator/src/balance/nitrogen/index.test.ts (1 hunks)
  • fdm-calculator/src/balance/nitrogen/input.ts (1 hunks)
  • fdm-calculator/src/balance/nitrogen/volatization/residues.ts (1 hunks)
  • fdm-calculator/src/conversions/soil.ts (1 hunks)
  • fdm-core/src/cultivation.ts (21 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • .changeset/true-windows-scream.md
  • .changeset/fine-symbols-taste.md
  • fdm-calculator/src/balance/nitrogen/volatization/residues.ts
  • .changeset/swift-colts-watch.md
  • fdm-calculator/src/balance/nitrogen/input.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
fdm-calculator/src/conversions/soil.ts (1)
fdm-core/src/db/schema.ts (1)
  • soilAnalysisTypeSelect (531-531)
🪛 LanguageTool
.changeset/clear-guests-taste.md

[uncategorized] ~5-~5: This verb does not appear to agree with the subject. Consider using a different form.
Context: ...s property of cultivation catalogue. It represent the amount of nitrogen that can be fixa...

(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)

🪛 GitHub Check: codecov/patch
fdm-calculator/src/conversions/soil.ts

[warning] 122-122: fdm-calculator/src/conversions/soil.ts#L122
Added line #L122 was not covered by tests


[warning] 125-125: fdm-calculator/src/conversions/soil.ts#L125
Added line #L125 was not covered by tests

fdm-core/src/cultivation.ts

[warning] 758-771: fdm-core/src/cultivation.ts#L758-L771
Added lines #L758 - L771 were not covered by tests

🔇 Additional comments (8)
fdm-calculator/src/conversions/soil.ts (3)

13-30: LGTM! Well-implemented organic carbon calculation.

The function correctly implements the standard soil science conversion from organic matter to organic carbon content. The use of Decimal.js for precision, proper null handling, and realistic boundary constraints (0.1-600 g C/kg soil) demonstrate good implementation practices.


40-57: LGTM! Proper inverse calculation implementation.

The function correctly implements the mathematical inverse of calculateOrganicCarbon. The boundary constraints (0.5-75%) are appropriate for soil organic matter percentages, and the implementation follows the same quality patterns as the previous function.


100-129: Address test coverage gaps for boundary conditions.

The bulk density calculation logic is well-implemented with appropriate formulas for different soil types. However, the upper and lower boundary clamping conditions (lines 122 and 125) lack test coverage.

Please add test cases to cover the boundary conditions:

// Test case for upper boundary (> 3 kg/m³)
it('should clamp bulk density to maximum of 3 kg/m³', () => {
  // Test with very low organic matter that would produce high density
  const result = calculateBulkDensity(0.1, 'klei');
  expect(result).toBe(3);
});

// Test case for lower boundary (< 0.5 kg/m³)  
it('should clamp bulk density to minimum of 0.5 kg/m³', () => {
  // Test with very high organic matter that would produce low density
  const result = calculateBulkDensity(75, 'dekzand');
  expect(result).toBe(0.5);
});
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 122-122: fdm-calculator/src/conversions/soil.ts#L122
Added line #L122 was not covered by tests


[warning] 125-125: fdm-calculator/src/conversions/soil.ts#L125
Added line #L125 was not covered by tests

fdm-calculator/src/balance/nitrogen/index.test.ts (1)

1-197: LGTM! Well-structured test suite with comprehensive coverage.

The test file demonstrates excellent practices:

  • Comprehensive mock data including all nitrogen-related properties
  • Proper error handling validation
  • Realistic test values (addressing previous feedback)
  • Good separation of concerns with focused test cases
  • Proper type checking in assertions

The tests effectively validate the nitrogen balance calculation functionality and integration with the updated data model.

fdm-core/src/cultivation.ts (4)

158-159: LGTM! Consistent integration of crop residue flag.

The m_cropresidue property has been properly integrated across all cultivation functions:

  • Parameter documentation updated
  • Database operations include the field
  • Function signatures consistently updated
  • Return types properly reflect the new property

This provides valuable information for nitrogen balance calculations regarding crop residue management.

Also applies to: 170-170, 279-279, 354-354, 441-441, 495-495, 587-587, 720-720, 872-872, 886-886, 1009-1009


758-771: LGTM! Harvest structure successfully updated to single object.

The change from harvestables array to single harvestable object has been implemented correctly:

  • Proper object structure with nested harvestable_analyses array
  • All required fields included in the mapping
  • Field selection appears complete (addressing previous review concerns)

This aligns with the broader data model updates mentioned in the AI summary.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 758-771: fdm-core/src/cultivation.ts#L758-L771
Added lines #L758 - L771 were not covered by tests


15-19: LGTM! Improved type safety with proper type imports.

The replacement of generic return types with specific interfaces (Cultivation, CultivationPlan, CultivationCatalogue) enhances type safety and code clarity. This addresses previous concerns about type annotations.

Also applies to: 44-44, 331-331, 409-409, 554-554


597-597:

Details

✅ Verification successful

Verify that b_id_harvestable field selection resolves previous runtime issue.

The b_id_harvestable field is now included in the select clause, which should resolve the previous issue where this field was undefined at runtime. This field is properly used in the harvest mapping on line 759.


🏁 Script executed:

#!/bin/bash
# Verify that b_id_harvestable is properly selected and used
ast-grep --pattern $'b_id_harvestable: schema.harvestables.b_id_harvestable'

Length of output: 77


I couldn’t locate any instances of that snippet using ast-grep. Let’s search the file directly and inspect the nearby lines to confirm that b_id_harvestable is indeed selected and used:


🏁 Script executed:

#!/bin/bash
# Search for any occurrences of b_id_harvestable
rg -n "b_id_harvestable" fdm-core/src/cultivation.ts

# Show lines 580–620 to inspect the select clause around line 597
sed -n '580,620p' fdm-core/src/cultivation.ts

Length of output: 2978


Confirmed: b_id_harvestable is properly selected and used

I’ve verified that in fdm-core/src/cultivation.ts:

  • Line 597: the SELECT clause includes
    b_id_harvestable: schema.harvestables.b_id_harvestable
  • Line 759: the harvest mapping uses
    b_id_harvestable: curr.b_id_harvestable

This ensures the field is no longer undefined at runtime.

Comment thread .changeset/clear-guests-taste.md Outdated
SvenVw and others added 2 commits May 27, 2025 10:28
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Sven Verweij <37927107+SvenVw@users.noreply.github.com>
Copy link
Copy Markdown
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: 4

🧹 Nitpick comments (6)
fdm-calculator/src/balance/nitrogen/supply/fertilizers/other.ts (1)

11-11: Fix typo in documentation.

The documentation contains a typo: "nnot of any type type" should be corrected.

- * This function iterates through the provided fertilizer applications, identifies those that are nnot of any type type,
+ * This function iterates through the provided fertilizer applications, identifies those that are not mineral, manure, or compost,
fdm-calculator/src/balance/nitrogen/supply/fertilizers/index.ts (2)

43-43: Fix typo in comment.

-    // Calculate the amount of Nitrogen supplied by othyer fertilizers
+    // Calculate the amount of Nitrogen supplied by other fertilizers

60-60: Add missing semicolon.

-        other: fertilizersSupplyOther
+        other: fertilizersSupplyOther,
fdm-calculator/src/balance/nitrogen/types.d.ts (3)

73-73: Fix typo in documentation.

-         * A detailed list of individual other fertilzer applications.
+         * A detailed list of individual other fertilizer applications.

131-131: Use consistent spelling for mineralization.

The codebase uses both "mineralisation" and "mineralization". For consistency, standardize on one spelling (preferably "mineralization" as used elsewhere).

-    mineralisation: NitrogenSupplyMineralization
+    mineralization: NitrogenSupplyMineralization
-    mineralisation: NitrogenSupplyMineralizationNumeric
+    mineralization: NitrogenSupplyMineralizationNumeric

Also applies to: 435-435


423-424: Remove duplicate comment.

-// Numeric version of NitrogenSupplyMineralization
 // Numeric version of NitrogenSupplyMineralization
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 52cc48b and 4961a84.

📒 Files selected for processing (5)
  • fdm-calculator/src/balance/nitrogen/supply/fertilizers/index.test.ts (1 hunks)
  • fdm-calculator/src/balance/nitrogen/supply/fertilizers/index.ts (1 hunks)
  • fdm-calculator/src/balance/nitrogen/supply/fertilizers/other.test.ts (1 hunks)
  • fdm-calculator/src/balance/nitrogen/supply/fertilizers/other.ts (1 hunks)
  • fdm-calculator/src/balance/nitrogen/types.d.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • fdm-calculator/src/balance/nitrogen/supply/fertilizers/index.test.ts
🧰 Additional context used
🧬 Code Graph Analysis (3)
fdm-calculator/src/balance/nitrogen/supply/fertilizers/other.test.ts (2)
fdm-calculator/src/balance/nitrogen/types.d.ts (2)
  • FieldInput (340-359)
  • FertilizerDetail (378-385)
fdm-calculator/src/balance/nitrogen/supply/fertilizers/other.ts (1)
  • calculateNitrogenSupplyByOtherFertilizers (18-69)
fdm-calculator/src/balance/nitrogen/supply/fertilizers/other.ts (1)
fdm-calculator/src/balance/nitrogen/types.d.ts (3)
  • FieldInput (340-359)
  • FertilizerDetail (378-385)
  • NitrogenSupplyFertilizers (17-78)
fdm-calculator/src/balance/nitrogen/types.d.ts (1)
fdm-calculator/src/index.ts (2)
  • NitrogenBalanceInput (7-7)
  • NitrogenBalanceNumeric (8-8)
🔇 Additional comments (1)
fdm-calculator/src/balance/nitrogen/supply/fertilizers/other.test.ts (1)

1-87: Well-structured and comprehensive test suite!

The test cases effectively cover all scenarios: empty input, normal calculations, and error handling. The mathematical calculations are correct and the use of Decimal.js ensures precision.

Comment thread fdm-calculator/src/balance/nitrogen/supply/fertilizers/other.ts Outdated
Comment thread fdm-calculator/src/balance/nitrogen/supply/fertilizers/other.ts Outdated
Comment thread fdm-calculator/src/balance/nitrogen/supply/fertilizers/other.ts Outdated
Comment thread fdm-calculator/src/balance/nitrogen/types.d.ts
SvenVw and others added 6 commits May 27, 2025 11:07
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Sven Verweij <37927107+SvenVw@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Sven Verweij <37927107+SvenVw@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Sven Verweij <37927107+SvenVw@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add function to calculate nitrogen balance

2 participants