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 constraint violations display #1084

Merged
merged 7 commits into from
Jan 12, 2024

Conversation

mattdailis
Copy link
Collaborator

Bug Description

Screenshot 2024-01-10 at 8 22 18 PM
  1. Upload banananation
  2. Make a plan that's a week long
  3. Add a GrowBanana activity. Set itsgrowingDuration to 3d and its quantity to 1000
  4. Add the following constraint
export default (): Constraint => {
  return Real.Resource("/fruit").greaterThan(500)
}
  1. Open the constraint panel
  2. Check constraints
  3. Observe that the navbar says there are violations, and that there are red violation counts in the constraints panel, but that no red regions are highlighted on the timeline, and no violations appear when expanding the violation details in the constraints panel.

Recommended fix

A detailed reading of #1022 shows that some of the reactive variables related to constraints were rerouted, leading to some transformations to be left out of the pipeline. Concretely, the $constraintResult variable was previously responsible for translating constraint violations windows from "offset from plan start in microseconds" to "milliseconds since the unix epoch". After the above PR, this translation was no longer occurring, leading to downstream confusion.

This PR removes the $constraintResult variable entirely, moving that transformation into the $constraintResponseMap reactive variable. Any constraint code must be derived from $constraintResponseMap, without reaching around it to use the un-processed constraintResponses. To this end, this PR renames constraintResponse to rawConstraintResponses (pluralized to reflect plural usage elsewhere in the code), to hopefully make it harder to make that mistake.

textForConstraintViolation was using a brittle approach to try to find the constraint response corresponding to the given violation. This PR instead threads the constraintName through to the usage of this function, so that it can do its job without relying on global variables. This is why a number of uses of ConstraintResult were updated to ConstraintResultWithName.

Lastly, this PR changes the label in the constraints nav bar. According to the Constraints panel, a single constraint can contain many violations. The nav bar, however, only counts the number of constraints violated, and does not sum up the total number of violations. To this end, this PR rewords "Constraint violations: 5" to instead read "Constraints violated: 5"

@mattdailis mattdailis added the fix A bug fix label Jan 11, 2024
@mattdailis mattdailis requested a review from a team as a code owner January 11, 2024 04:40
@mattdailis mattdailis force-pushed the fix/constraints-violations-not-showing branch from 7681afe to bcd265f Compare January 11, 2024 22:27
@mattdailis mattdailis force-pushed the fix/constraints-violations-not-showing branch from bcd265f to dbc714c Compare January 11, 2024 22:47
Copy link
Collaborator

@duranb duranb left a comment

Choose a reason for hiding this comment

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

works great! thanks a bunch!

@mattdailis mattdailis merged commit 680cbb9 into develop Jan 12, 2024
4 checks passed
@mattdailis mattdailis deleted the fix/constraints-violations-not-showing branch January 12, 2024 03:20
@joswig joswig restored the fix/constraints-violations-not-showing branch January 16, 2024 19:19
@joswig joswig deleted the fix/constraints-violations-not-showing branch January 16, 2024 19:32
JosephVolosin pushed a commit that referenced this pull request Aug 20, 2024
* Remove needless mutation

* Attempt to simplify constraints reactive variables

* Use the word `violations` consistently

* Be robust to nullish violations

* Another nullish violations

* Add | null

* Propagate | null type
JosephVolosin pushed a commit that referenced this pull request Oct 21, 2024
* Remove needless mutation

* Attempt to simplify constraints reactive variables

* Use the word `violations` consistently

* Be robust to nullish violations

* Another nullish violations

* Add | null

* Propagate | null type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix A bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants