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

(OraklNode) Deviation Threshold based on submission interval #1767

Merged
merged 2 commits into from
Jul 10, 2024

Conversation

nick-bisonai
Copy link
Collaborator

Description

set deviation threshold based on submission interval

https://go.dev/play/p/0NuWyupgKRf

func main() {
	// Example usage
	fmt.Println(getDeviationThreshold(15 * time.Second)) // 15 seconds
	fmt.Println(getDeviationThreshold(1 * time.Hour))    // 1 hour
	fmt.Println(getDeviationThreshold(30 * time.Minute)) // 30 minutes
	fmt.Println(getDeviationThreshold(1 * time.Second))  // 1 second (extrapolation)
	fmt.Println(getDeviationThreshold(2 * time.Hour))    // 2 hours (extrapolation)
}

/*
0.05
0.01
0.030083682008368202
0.05
0.01
*/

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist before requesting a review

  • I have performed a self-review of my code.
  • If it is a core feature, I have added thorough tests.

Deployment

  • Should publish npm package
  • Should publish Docker image

@nick-bisonai nick-bisonai self-assigned this Jul 9, 2024
@nick-bisonai nick-bisonai requested a review from a team as a code owner July 9, 2024 07:39
Copy link
Contributor

coderabbitai bot commented Jul 9, 2024

Walkthrough

Walkthrough

The recent changes enhance the deviation reporting capabilities of the system by introducing a dynamic deviation threshold, which is now calculated based on the submission interval. Additionally, constants such as deviation intervals and reporting thresholds have been adjusted. These improvements are reflected in both the reporter module's core logic and its corresponding tests to ensure a robust implementation.

Changes

File Change Summary
node/pkg/reporter/reporter.go - NewReporter initializes deviationThreshold using GetDeviationThreshold.
- deviationJob updated to include deviationThreshold in GetDeviatingAggregates call.
node/pkg/reporter/types.go - Modified constants: MAX_REPORT_BATCH_SIZE (50), DEVIATION_INTERVAL (2000).
- Added constants: DEVIATION_ABSOLUTE_THRESHOLD, DECIMALS, MAX_DEVIATION_THRESHOLD, etc.
- Added deviationThreshold field to Reporter struct.
node/pkg/reporter/utils.go - Updated GetDeviatingAggregates, ShouldReportDeviation to accept threshold parameter.
- Added GetDeviationThreshold function.
node/pkg/reporter/reporter_test.go - Added TestGetDeviationThreshold function.
- Updated TestShouldReportDeviation to take an additional threshold parameter.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Reporter
    participant Utils

    Client->>Reporter: Initialize via NewReporter()
    Reporter->>Utils: Call GetDeviationThreshold(interval)
    Utils-->>Reporter: Return calculated threshold
    Reporter->>Client: Return initialized Reporter instance

    Reporter->>Utils: Call GetDeviatingAggregates(data, deviationThreshold)
    Utils-->>Reporter: Return deviating aggregates
    Reporter->>Client: Report deviations
Loading

Poem

In code's rhythm, changes flow,
Thresholds rise as moments grow.
Deviation checks anew,
Dynamic shifts brought into view.
Constants set and tests align,
Reporter’s dance, pure design.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nick-bisonai nick-bisonai marked this pull request as draft July 9, 2024 07:39
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c7cffb3 and 203ae3c.

Files selected for processing (3)
  • node/pkg/reporter/reporter.go (2 hunks)
  • node/pkg/reporter/types.go (2 hunks)
  • node/pkg/reporter/utils.go (4 hunks)
Additional comments not posted (8)
node/pkg/reporter/types.go (3)

31-32: Verify the new constant values.

The MAX_REPORT_BATCH_SIZE has been reduced from 100 to 50, and DEVIATION_INTERVAL has been increased from 1000 to 2000. Ensure these values align with the expected behavior and system requirements.


33-40: New constants added.

The new constants seem well-defined and self-explanatory. Ensure they are used correctly and consistently within the codebase.


130-131: New field added to Reporter struct.

The deviationThreshold field has been added to the Reporter struct. Ensure this field is correctly initialized and used within the codebase.

node/pkg/reporter/utils.go (3)

Line range hint 21-30:
New parameter added to GetDeviatingAggregates.

The threshold parameter has been added to GetDeviatingAggregates. Ensure this parameter is correctly passed and used within the function.


37-43: New parameter added to ShouldReportDeviation.

The threshold parameter has been added to ShouldReportDeviation. Ensure this parameter is correctly passed and used within the function.


363-372: New function GetDeviationThreshold.

The GetDeviationThreshold function is well-implemented and calculates the deviation threshold based on the submissionInterval. Ensure the logic aligns with the expected behavior.

node/pkg/reporter/reporter.go (2)

50-56: Initialize deviationThreshold in NewReporter.

The deviationThreshold is correctly initialized using the GetDeviationThreshold function and assigned to the deviationThreshold field in the Reporter struct.


318-318: Pass deviationThreshold to GetDeviatingAggregates.

The deviationThreshold is correctly passed as an argument to the GetDeviatingAggregates function.

@nick-bisonai nick-bisonai linked an issue Jul 9, 2024 that may be closed by this pull request
@nick-bisonai nick-bisonai marked this pull request as ready for review July 9, 2024 07:54
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
node/pkg/reporter/reporter_test.go (1)

510-526: LGTM! Consider adding more edge cases.

The new TestGetDeviationThreshold function comprehensively tests various scenarios for the deviation threshold calculation.

Consider adding more edge cases, such as very large or very small time durations, to ensure robustness.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 203ae3c and 9e43b52.

Files selected for processing (1)
  • node/pkg/reporter/reporter_test.go (3 hunks)
Additional comments not posted (2)
node/pkg/reporter/reporter_test.go (2)

503-508: LGTM! Verify correctness of threshold parameter.

The additions to the TestShouldReportDeviation function correctly test the ShouldReportDeviation function with the new deviation threshold parameter.

However, ensure that the threshold values used in the assertions are appropriate and reflect real-world scenarios.


553-553: LGTM! Verify correctness of threshold parameter.

The additions to the TestGetDeviatingAggregates function correctly test the GetDeviatingAggregates function with the new deviation threshold parameter.

However, ensure that the threshold values used in the assertions are appropriate and reflect real-world scenarios.

Copy link
Contributor

@Intizar-T Intizar-T left a comment

Choose a reason for hiding this comment

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

lgtm!

@nick-bisonai nick-bisonai merged commit 2426147 into master Jul 10, 2024
1 check passed
@nick-bisonai nick-bisonai deleted the feat/linear-interpolated-deviation-threshold branch July 10, 2024 05:13
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.

customizable deviation threshold per price pairs
2 participants