feat: helminth losing apetite #718

Merged
Sainan merged 5 commits from helminth-apetite into main 2025-01-05 04:34:41 -08:00
Owner

Final steps for #288

Final steps for #288
coderabbitai[bot] commented 2025-01-05 00:10:11 -08:00 (Migrated from github.com)
Author
Owner

Warning

Rate limit exceeded

@Sainan has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 26 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between dd0d3b8555 and 4d2a98ffcb.

📒 Files selected for processing (1)
  • src/controllers/api/infestedFoundryController.ts (3 hunks)

Walkthrough

The pull request introduces comprehensive modifications across three files related to the inventory and resource management system. The changes primarily focus on enhancing the tracking and handling of resource conversions in the infestedFoundryController. A new import for a logger utility is added, and the logic for consuming items is significantly altered, incorporating a new variable to track the current time in Unix seconds.

A new interface, IHelminthFoodRecord, is introduced to track recently converted resources, along with updates to the inventory model to include this new schema. The IInventoryDatabase interface sees several properties updated to use MongoDB Types.ObjectId, reflecting a shift in data type representation. Overall, the modifications enhance the functionality and structure of the resource management system, with a focus on improved tracking and dynamic adjustments based on time.


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.

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.
<!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- This is an auto-generated comment: rate limited by coderabbit.ai --> > [!WARNING] > ## Rate limit exceeded > > @Sainan has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait **11 minutes and 26 seconds** before requesting another review. > > <details> > <summary>⌛ How to resolve this issue?</summary> > > After the wait time has elapsed, a review can be triggered using the `@coderabbitai review` command as a PR comment. Alternatively, push new commits to this PR. > > We recommend that you space out your commits to avoid hitting the rate limit. > > </details> > > > <details> > <summary>🚦 How do rate limits work?</summary> > > CodeRabbit enforces hourly rate limits for each developer per organization. > > Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. > > Please see our [FAQ](https://docs.coderabbit.ai/faq) for further information. > > </details> > > <details> > <summary>📥 Commits</summary> > > Reviewing files that changed from the base of the PR and between dd0d3b85556671eef093f22a95d0cb0c4137d326 and 4d2a98ffcb39f8e2bd6713789a382aa0bb6e1def. > > </details> > > <details> > <summary>📒 Files selected for processing (1)</summary> > > * `src/controllers/api/infestedFoundryController.ts` (3 hunks) > > </details> <!-- end of auto-generated comment: rate limited by coderabbit.ai --> <!-- walkthrough_start --> ## Walkthrough The pull request introduces comprehensive modifications across three files related to the inventory and resource management system. The changes primarily focus on enhancing the tracking and handling of resource conversions in the `infestedFoundryController`. A new import for a `logger` utility is added, and the logic for consuming items is significantly altered, incorporating a new variable to track the current time in Unix seconds. A new interface, `IHelminthFoodRecord`, is introduced to track recently converted resources, along with updates to the inventory model to include this new schema. The `IInventoryDatabase` interface sees several properties updated to use MongoDB `Types.ObjectId`, reflecting a shift in data type representation. Overall, the modifications enhance the functionality and structure of the resource management system, with a focus on improved tracking and dynamic adjustments based on time. <!-- walkthrough_end --> <!-- internal state start --> <!-- FAHghAtBAEAqAWBLAztF0CGA7TBXALgPYQDmAplmQE4b5kAm0AxoQLasX4Bc0ADldEIAjAFZkm+RADcyqIQE9mhetQxChifADoMiaFAB8wY+CjGAxOegAFAErQAyrnYYq84wjJ9cAGx/QqMgBHXFl8aEl8HwZoACIAMzJaHngyH1ZELHx4aB9CZEySTF4ySLJY6AB3DFRkXCEM/DpGBQjU6FxkakddLGxMLEZ0RBUsxHjEGNbsryxnIW6AdgBGAA4tOHb+RFZXRXjCJk7BeLb0OzRUIjRWXmiOLLavCb7/ZDpeVECfWhjrlDqXnMACZVutoAAxXBUGYCFT4XQ+L5kEiueiFJ7QZAlJjjRBMZjwbDkVCEASJWjQ2RoLJUZS4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1F4MIMfmRExs3MntSJ3NEBIFQsgEgPEOEMyFYi+IyDCL0JKFxgTqLjyMPGQPwLIJwDELDqVKZnlh+MgKpp2oDIlA9GkHNDsIJvVN1ALGRslApuIVxBXiQFXgAELQAAEn76h+7GAWAOazIKTm78RuauBm5eY+ajgCA7IBYHI4H9g2B0gx6KBu7LqsTXLp6nwtTZ48AMRJFV71yGSRYCG+pW5+HyC25qAO7QCfZj4Z6hidG/A8AUHMiDEczDHW7ErjH25dBFYwBN7R7YFNEF4iFXJGQD70AN74BN4eFy7QD9517nFD7XGt7LGQGepDGW7rFuCbGTHTFnEXFXFdA3H/5T634vFO7vEjHjbfHbGhZ7GNFOFeDHGp4qTz4JSL4fK3Gok+DokpYrFeBrGjHQk55TFGRYnok8DAk6Ggk4B4l96QmPZEk7H1H7EcHNFInXKX7X4z6v7dGf6RoDGvHQEfGElcZbHEnTGcmtrckUl+4ZHT78lgn8GrHClQmikO6hbhZILgkczlYnEwG/bwFlow5pzsE4F96dpe48DEGFB9qDCF4LF8gAqxSwkNEHEIktHNDXKo6xyMGY4Q7IA8nQD44MQWmE5WmESFAADc0AXRjp3y1A0ZzODouYuJgp7x3BmGLB4pdBMcJsx65sWZAZ3RGZnWchZayZqZ2p+JMhmZ2ORWAumKQEx44SSheAV4yuaCjA94i4T4L47K6uX4jCu4Ggf4h4gEoAQ484jQAA+iMMgNOYECKD5AwNOUFDCABE2ZOQAKzAgACcqw9AAALAAGz0AADMgkywh5Z5ZAx5x5qUu5GAh59AW5ywu5Z5GAiwH59AqwQg8Q15wIZ5BIR4k5aUAADOeUIKsFuTBXeSsBTPEGBe+fEMCMCBgLuVufQGBUwEINhYecsGeYsOecCMeRucBDAPeJoLOWdAuRJJMJUCudooYEAA=== --> <!-- internal state end --> <!-- tips_start --> --- 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? <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <details> <summary>🪧 Tips</summary> ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - 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](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR. ([Beta](https://docs.coderabbit.ai/early-access#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. ### Documentation and Community - Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements. </details> <!-- tips_end -->
coderabbitai[bot] (Migrated from github.com) reviewed 2025-01-05 00:20:39 -08:00
coderabbitai[bot] (Migrated from github.com) left a comment
Author
Owner

Actionable comments posted: 1

🧹 Nitpick comments (4)
src/controllers/api/infestedFoundryController.ts (3)

76-92: Check for potential concurrency or race conditions when adding new resources.
Multiple concurrent requests might cause resources to be created twice or updated simultaneously. If concurrency can happen, consider using a more robust approach like upsert or transaction locks.


99-105: Consider modularizing the date-setting logic.
Two conditions produce two different durations for record.Date. Extracting this to a helper function (e.g., getConversionDuration(hoursRemaining)) might enhance clarity.


398-414: Correct minor spelling in function name and maintain clarity of piecewise logic.
Function name “apetiteModel” is missing an extra “p” (commonly “appetiteModel”). Also, consider adding inline comments to clarify the logic of each piecewise segment.

- const apetiteModel = (x: number): number => {
+ const appetiteModel = (x: number): number => {
src/types/inventoryTypes/inventoryTypes.ts (1)

524-524: Ensure consistency with default array handling.
RecentlyConvertedResources?: IHelminthFoodRecord[] is optional, which may lead to needing null checks. If empty arrays are always acceptable, consider using a non-optional type or a default array assignment for reliability.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 06bc0123ba and 5298d46d3f.

📒 Files selected for processing (3)
  • src/controllers/api/infestedFoundryController.ts (3 hunks)
  • src/models/inventoryModels/inventoryModel.ts (2 hunks)
  • src/types/inventoryTypes/inventoryTypes.ts (1 hunks)
🔇 Additional comments (7)
src/controllers/api/infestedFoundryController.ts (4)

11-11: Use a consistent logging practice.
The addition of the logger import is good for better observability. Ensure all critical operations are also logged consistently to help with debugging.


71-72: Confirm time unit usage.
The variable currentUnixSeconds sets a reference in seconds, which is then subtracted from or added to other time calculations. Ensure downstream logic consistently uses seconds (not milliseconds) to avoid time drift or conversion mismatches.


93-98: Validate the correctness of time-based conversions.
You're computing remaining hours as (record.Date - currentUnixSeconds) / 3600. If a wide time difference is accidentally supplied, the negative or excessively large values might yield unexpected apetiteFactor.


106-107: Watch out for integer truncation errors and large multiplications.
Using Math.trunc(snack.gain * 1000 * apetiteFactor) may cause rounding artifacts, especially when apetiteFactor is fractional. Confirm that this is the desired behavior.

src/types/inventoryTypes/inventoryTypes.ts (1)

516-519: Interface naming is concise and helpful.
This new interface IHelminthFoodRecord accurately captures the item type and the time of the last conversion. The property types are straightforward and clear.

src/models/inventoryModels/inventoryModel.ts (2)

48-49: New imports keep schema definitions consistent.
The added import of IShipExterior and IHelminthFoodRecord aligns with the new schemas. Good practice to keep all domain-specific types in a dedicated types file.


474-480: Schema definitions align well with the new interface.
The helminthFoodRecordSchema matches IHelminthFoodRecord, ensuring consistency. Ensure references to this schema within the application are properly validated or sanitized if user input is involved.

**Actionable comments posted: 1** <details> <summary>🧹 Nitpick comments (4)</summary><blockquote> <details> <summary>src/controllers/api/infestedFoundryController.ts (3)</summary><blockquote> `76-92`: **Check for potential concurrency or race conditions when adding new resources.** Multiple concurrent requests might cause resources to be created twice or updated simultaneously. If concurrency can happen, consider using a more robust approach like upsert or transaction locks. --- `99-105`: **Consider modularizing the date-setting logic.** Two conditions produce two different durations for `record.Date`. Extracting this to a helper function (e.g., `getConversionDuration(hoursRemaining)`) might enhance clarity. --- `398-414`: **Correct minor spelling in function name and maintain clarity of piecewise logic.** Function name “apetiteModel” is missing an extra “p” (commonly “appetiteModel”). Also, consider adding inline comments to clarify the logic of each piecewise segment. ```diff - const apetiteModel = (x: number): number => { + const appetiteModel = (x: number): number => { ``` </blockquote></details> <details> <summary>src/types/inventoryTypes/inventoryTypes.ts (1)</summary><blockquote> `524-524`: **Ensure consistency with default array handling.** `RecentlyConvertedResources?: IHelminthFoodRecord[]` is optional, which may lead to needing null checks. If empty arrays are always acceptable, consider using a non-optional type or a default array assignment for reliability. </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: .coderabbit.yaml** **Review profile: CHILL** **Plan: Pro** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 06bc0123baee78b6d339bea8da8c734132b49620 and 5298d46d3ff143e66ad9a4d5193a73ad8bf4323c. </details> <details> <summary>📒 Files selected for processing (3)</summary> * `src/controllers/api/infestedFoundryController.ts` (3 hunks) * `src/models/inventoryModels/inventoryModel.ts` (2 hunks) * `src/types/inventoryTypes/inventoryTypes.ts` (1 hunks) </details> <details> <summary>🔇 Additional comments (7)</summary><blockquote> <details> <summary>src/controllers/api/infestedFoundryController.ts (4)</summary> `11-11`: **Use a consistent logging practice.** The addition of the `logger` import is good for better observability. Ensure all critical operations are also logged consistently to help with debugging. --- `71-72`: **Confirm time unit usage.** The variable `currentUnixSeconds` sets a reference in seconds, which is then subtracted from or added to other time calculations. Ensure downstream logic consistently uses seconds (not milliseconds) to avoid time drift or conversion mismatches. --- `93-98`: **Validate the correctness of time-based conversions.** You're computing remaining hours as `(record.Date - currentUnixSeconds) / 3600`. If a wide time difference is accidentally supplied, the negative or excessively large values might yield unexpected `apetiteFactor`. --- `106-107`: **Watch out for integer truncation errors and large multiplications.** Using `Math.trunc(snack.gain * 1000 * apetiteFactor)` may cause rounding artifacts, especially when `apetiteFactor` is fractional. Confirm that this is the desired behavior. </details> <details> <summary>src/types/inventoryTypes/inventoryTypes.ts (1)</summary> `516-519`: **Interface naming is concise and helpful.** This new interface `IHelminthFoodRecord` accurately captures the item type and the time of the last conversion. The property types are straightforward and clear. </details> <details> <summary>src/models/inventoryModels/inventoryModel.ts (2)</summary> `48-49`: **New imports keep schema definitions consistent.** The added import of `IShipExterior` and `IHelminthFoodRecord` aligns with the new schemas. Good practice to keep all domain-specific types in a dedicated types file. --- `474-480`: **Schema definitions align well with the new interface.** The `helminthFoodRecordSchema` matches `IHelminthFoodRecord`, ensuring consistency. Ensure references to this schema within the application are properly validated or sanitized if user input is involved. </details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
coderabbitai[bot] (Migrated from github.com) commented 2025-01-05 00:20:38 -08:00
Author
Owner

🛠️ Refactor suggestion

Reevaluate default for RecentlyConvertedResources.
Currently, { default: undefined } can lead to checks for existence when pushing new items. If the intention is to always maintain an array, consider changing to { default: [] } for simpler usage.

- RecentlyConvertedResources: { type: [helminthFoodRecordSchema], default: undefined }
+ RecentlyConvertedResources: { type: [helminthFoodRecordSchema], default: [] }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

const helminthResourceSchema = new Schema<IHelminthResource>(
    {
        ItemType: String,
        Count: Number,
        RecentlyConvertedResources: { type: [helminthFoodRecordSchema], default: [] }
    },
    { _id: false }
);
_:hammer_and_wrench: Refactor suggestion_ **Reevaluate default for `RecentlyConvertedResources`.** Currently, `{ default: undefined }` can lead to checks for existence when pushing new items. If the intention is to always maintain an array, consider changing to `{ default: [] }` for simpler usage. ```diff - RecentlyConvertedResources: { type: [helminthFoodRecordSchema], default: undefined } + RecentlyConvertedResources: { type: [helminthFoodRecordSchema], default: [] } ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion const helminthResourceSchema = new Schema<IHelminthResource>( { ItemType: String, Count: Number, RecentlyConvertedResources: { type: [helminthFoodRecordSchema], default: [] } }, { _id: false } ); ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] (Migrated from github.com) reviewed 2025-01-05 00:46:46 -08:00
coderabbitai[bot] (Migrated from github.com) left a comment
Author
Owner

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/controllers/api/infestedFoundryController.ts (2)

93-93: Consider using millisecond precision for time calculations.

The current implementation might truncate sub-hour periods. Consider using milliseconds for more precise time calculations.

-                const hoursRemaining = (record.Date - currentUnixSeconds) / 3600;
+                const hoursRemaining = (record.Date - currentUnixSeconds) / 3600.0;

399-432: Enhance maintainability of the appetite model.

While the implementation is correct, consider these improvements:

  1. Extract magic numbers as named constants
  2. Convert the documentation to JSDoc format with a graph visualization
+/**
+ * Models the appetite factor based on hours remaining.
+ * The relationship is defined by a piecewise linear function:
+ *
+ * Appetite
+ * (%)  │    30 ┌────
+ *      │       │     ╲
+ *      │       │      ╲
+ *      │    15 │       ├────────┤
+ *      │       │              ╲  │
+ *      │     3 │               ╲ └────
+ *      │       └───┬───┬───┬───┬───┬─→ Hours
+ *      │          18  36     71.9
+ *
+ * @param {number} hoursRemaining - Hours remaining until next feeding
+ * @returns {number} Appetite percentage (3-30)
+ */
+const INITIAL_APPETITE = 30;
+const MINIMUM_APPETITE = 3;
+const PLATEAU_START = 18;
+const PLATEAU_END = 36;
+const FINAL_DECLINE_END = 71.9;
+const INITIAL_DECLINE_RATE = -0.84;
+const FINAL_DECLINE_RATE = -0.3327892;
+const FINAL_INTERCEPT = 26.94135;
+
 const apetiteModel = (x: number): number => {
     if (x <= 0) {
-        return 30;
+        return INITIAL_APPETITE;
     }
-    if (x < 18) {
-        return -0.84 * x + 30;
+    if (x < PLATEAU_START) {
+        return INITIAL_DECLINE_RATE * x + INITIAL_APPETITE;
     }
-    if (x <= 36) {
+    if (x <= PLATEAU_END) {
         return 15;
     }
-    if (x < 71.9) {
-        return -0.3327892 * x + 26.94135;
+    if (x < FINAL_DECLINE_END) {
+        return FINAL_DECLINE_RATE * x + FINAL_INTERCEPT;
     }
-    return 3;
+    return MINIMUM_APPETITE;
 };
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5298d46d3f and dd0d3b8555.

📒 Files selected for processing (1)
  • src/controllers/api/infestedFoundryController.ts (3 hunks)
🔇 Additional comments (1)
src/controllers/api/infestedFoundryController.ts (1)

11-11: LGTM! Good addition of logging.

The logger import enhances observability of the appetite calculations.

**Actionable comments posted: 1** <details> <summary>🧹 Nitpick comments (2)</summary><blockquote> <details> <summary>src/controllers/api/infestedFoundryController.ts (2)</summary><blockquote> `93-93`: **Consider using millisecond precision for time calculations.** The current implementation might truncate sub-hour periods. Consider using milliseconds for more precise time calculations. ```diff - const hoursRemaining = (record.Date - currentUnixSeconds) / 3600; + const hoursRemaining = (record.Date - currentUnixSeconds) / 3600.0; ``` --- `399-432`: **Enhance maintainability of the appetite model.** While the implementation is correct, consider these improvements: 1. Extract magic numbers as named constants 2. Convert the documentation to JSDoc format with a graph visualization ```diff +/** + * Models the appetite factor based on hours remaining. + * The relationship is defined by a piecewise linear function: + * + * Appetite + * (%) │ 30 ┌──── + * │ │ ╲ + * │ │ ╲ + * │ 15 │ ├────────┤ + * │ │ ╲ │ + * │ 3 │ ╲ └──── + * │ └───┬───┬───┬───┬───┬─→ Hours + * │ 18 36 71.9 + * + * @param {number} hoursRemaining - Hours remaining until next feeding + * @returns {number} Appetite percentage (3-30) + */ +const INITIAL_APPETITE = 30; +const MINIMUM_APPETITE = 3; +const PLATEAU_START = 18; +const PLATEAU_END = 36; +const FINAL_DECLINE_END = 71.9; +const INITIAL_DECLINE_RATE = -0.84; +const FINAL_DECLINE_RATE = -0.3327892; +const FINAL_INTERCEPT = 26.94135; + const apetiteModel = (x: number): number => { if (x <= 0) { - return 30; + return INITIAL_APPETITE; } - if (x < 18) { - return -0.84 * x + 30; + if (x < PLATEAU_START) { + return INITIAL_DECLINE_RATE * x + INITIAL_APPETITE; } - if (x <= 36) { + if (x <= PLATEAU_END) { return 15; } - if (x < 71.9) { - return -0.3327892 * x + 26.94135; + if (x < FINAL_DECLINE_END) { + return FINAL_DECLINE_RATE * x + FINAL_INTERCEPT; } - return 3; + return MINIMUM_APPETITE; }; ``` </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: .coderabbit.yaml** **Review profile: CHILL** **Plan: Pro** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 5298d46d3ff143e66ad9a4d5193a73ad8bf4323c and dd0d3b85556671eef093f22a95d0cb0c4137d326. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `src/controllers/api/infestedFoundryController.ts` (3 hunks) </details> <details> <summary>🔇 Additional comments (1)</summary><blockquote> <details> <summary>src/controllers/api/infestedFoundryController.ts (1)</summary> `11-11`: **LGTM! Good addition of logging.** The logger import enhances observability of the appetite calculations. </details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
coderabbitai[bot] (Migrated from github.com) commented 2025-01-05 00:46:45 -08:00
Author
Owner

⚠️ Potential issue

Remove redundant push operation.

The record is already part of the RecentlyConvertedResources array (added in lines 87-91), so pushing it again creates a duplicate entry.

-                resource.RecentlyConvertedResources.push(record);
_:warning: Potential issue_ **Remove redundant push operation.** The record is already part of the `RecentlyConvertedResources` array (added in lines 87-91), so pushing it again creates a duplicate entry. ```diff - resource.RecentlyConvertedResources.push(record); ``` <!-- This is an auto-generated comment by CodeRabbit -->
Sign in to join this conversation.
No description provided.