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

[AERIE-2145] Gaps in external profiles #397

Merged
merged 8 commits into from Nov 7, 2022

Conversation

JoelCourtney
Copy link
Contributor

@JoelCourtney JoelCourtney commented Oct 20, 2022

  • Tickets addressed: AERIE-2145
  • Review: By commit
  • Merge strategy: Merge (no squash)

Description

by commit:

  1. The nullableP parser currently cannot unparse nulls because it throws a NoSuchElementException when unwrapping. The workaround is to throw a ClassCastException which the chooseP parser will catch try the next option. @Twisol was this the intended pattern? I don't see another way to do it, but throwing for control flow on the happy path seems iffy.
  2. This allows the dynamics in ProfileSets to be Optional. This allows external dataset profiles to have gaps, but also requires all segments of simulated profiles to be wrapped in Optional.of(). Also, the Post/GetProfileSegmentsActions were updated to write to the new is_gap column of the profile_segment table.
  3. Due to conversions between our many formats for representing profiles, the duration of the last segment is lost when storing and retrieving from the database. This isn't an issue for simulated profiles because they end at the plan horizon, but external profiles can end in the middle of the plan. So I've added an extra gap segment at the end of all profiles to keep the duration. This required a small change in the UI here.

Verification

I'm in progress writing an e2e test(s) for this.

Documentation

I have added tutorial docs for uploading external datasets and using them in constraints. I will add a page for scheduling when we enable that.

Future work

  • assignGaps
  • assignGaps
  • visual representation of violation gaps in UI
  • assignGaps

@Twisol
Copy link
Contributor

Twisol commented Oct 20, 2022

  1. @Twisol was this the intended pattern?

I'm not sure what you mean here. The develop implementation of nullableP invokes Optional::get, which will of course throw on empty. This doesn't seem to be a problem with the parser system itself.

Here is a custom parser (no combinators) that I think should work. I haven't tested this, and I'm not confident that my getSchema() uses the right JSON-Schema syntax, but it's the basic idea.

    return new JsonParser<>() {
      @Override
      public JsonObject getSchema(final SchemaCache anchors) {
        return Json.createObjectBuilder()
            .add("any", Json.createArrayBuilder()
                .add(JsonValue.NULL)
                .add(parser.getSchema()))
            .build();
      }

      @Override
      public JsonParseResult<Optional<T>> parse(final JsonValue json) {
        if (json.getValueType() == JsonValue.ValueType.NULL) return JsonParseResult.success(Optional.empty());

        return parser.parse(json).mapSuccess(Optional::of);
      }

      @Override
      public JsonValue unparse(final Optional<T> value) {
        return value.map(parser::unparse).orElse(JsonValue.NULL);
      }
    };

@JoelCourtney JoelCourtney changed the title Feat/aerie 2145 external profile gaps [AERIE-2145] external profile gaps Oct 20, 2022
@JoelCourtney JoelCourtney changed the title [AERIE-2145] external profile gaps [AERIE-2145] Gaps in external profiles Oct 20, 2022
@JoelCourtney
Copy link
Contributor Author

@Twisol When unparsing chooseP(A, B), choose's unparser will only check B's unparser if a ClassCastException is thrown. In cases where the Java types associated with A and B are different, this is fine because the exception will be caused by chooseP itself. But in this case, both A and N operate on Optional<T>, so the only way for A to tell chooseP to try B when it encounters Optional.empty() is to manually throw a ClassCastException.

@JoelCourtney JoelCourtney force-pushed the feat/AERIE-2145--external-profile-gaps branch from 6da5ada to cd1f393 Compare October 20, 2022 22:54
@JoelCourtney JoelCourtney temporarily deployed to e2e-test October 20, 2022 22:54 Inactive
@Twisol
Copy link
Contributor

Twisol commented Oct 20, 2022

Right. Because chooseP depends on class casts to pick the right parser, it isn't appropriate for this case. Put another way, the individual parsers are supposed to convert to and from values of some type, but one of them only handles some of them (failing on the rest) and the other is lossy because it sends everything to null (and then back to empty).

The individual parsers ought to be total and lossless, so chooseP is not a good combinator to use to decompose this problem with.

@Twisol
Copy link
Contributor

Twisol commented Oct 20, 2022

I really want a proper sumP akin to productP but with Either instead of Pair. Unfortunately there are serious ergonomics issues with the design I've tried up to this point. And I don't think it would help in this particular situation (since it uses a tag field to disambiguate).

@JoelCourtney JoelCourtney temporarily deployed to e2e-test October 21, 2022 00:50 Inactive
@JoelCourtney JoelCourtney force-pushed the feat/AERIE-2145--external-profile-gaps branch from 1801fa6 to 24fa340 Compare October 21, 2022 00:51
@JoelCourtney JoelCourtney temporarily deployed to e2e-test October 21, 2022 00:51 Inactive
@JoelCourtney JoelCourtney force-pushed the feat/AERIE-2145--external-profile-gaps branch from 24fa340 to d57569a Compare October 25, 2022 20:48
@JoelCourtney JoelCourtney temporarily deployed to e2e-test October 25, 2022 20:48 Inactive
@JoelCourtney JoelCourtney force-pushed the feat/AERIE-2145--external-profile-gaps branch from d57569a to 3338057 Compare October 25, 2022 21:23
@JoelCourtney JoelCourtney temporarily deployed to e2e-test October 25, 2022 21:23 Inactive
@JoelCourtney JoelCourtney force-pushed the feat/AERIE-2145--external-profile-gaps branch from 3338057 to 8a83c9d Compare October 25, 2022 21:26
@JoelCourtney JoelCourtney temporarily deployed to e2e-test October 25, 2022 21:26 Inactive
@JoelCourtney
Copy link
Contributor Author

JoelCourtney commented Oct 25, 2022

@Twisol just for the sake of getting something working, I reworked it to add chooseWithPredicateP with allows each variant to decide whether it can be unparsed from the given value. There's a wee bit of "Don't Repeat Yourself Except When You Need To" because for the life of me I can't figure out how to map a generic varargs to another varargs array without losing all the type information. Thoughts on this solution?

@Twisol
Copy link
Contributor

Twisol commented Oct 25, 2022

Did you have a chance to evaluate my alternative solution from before?

@JoelCourtney
Copy link
Contributor Author

Wow. That there the whole time? I completely missed it. Please hold

@JoelCourtney JoelCourtney force-pushed the feat/AERIE-2145--external-profile-gaps branch from 8a83c9d to 2dc8c3a Compare October 25, 2022 21:44
@JoelCourtney JoelCourtney temporarily deployed to e2e-test October 25, 2022 21:44 Inactive
@JoelCourtney
Copy link
Contributor Author

That'll do it 🤦 . Thanks!

@Twisol
Copy link
Contributor

Twisol commented Oct 25, 2022

Glad to be of assistance :)

Copy link
Collaborator

@mattdailis mattdailis left a comment

Choose a reason for hiding this comment

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

Key:
🔻 Issues to address before merge

🔶 Requests that should not block merge, but should at least be discussed

🔵 Recommendations that can be ignored if desired

@JoelCourtney JoelCourtney force-pushed the feat/AERIE-2145--external-profile-gaps branch from bb0ecae to a63d716 Compare October 28, 2022 17:31
@JoelCourtney JoelCourtney temporarily deployed to e2e-test October 28, 2022 17:31 Inactive
Copy link
Contributor

@pcrosemurgy pcrosemurgy left a comment

Choose a reason for hiding this comment

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

Nice work! Sounds like e2e tests will be added to this PR prior to merge.

@JoelCourtney
Copy link
Contributor Author

Uncovered a problem while testing, somewhere along the way it makes an assumption that the external dataset starts at plan start. Will fix.

@camargo camargo added the feature A new feature or feature request label Nov 2, 2022
@JoelCourtney JoelCourtney force-pushed the feat/AERIE-2145--external-profile-gaps branch from a63d716 to 4318e40 Compare November 2, 2022 23:43
@JoelCourtney JoelCourtney force-pushed the feat/AERIE-2145--external-profile-gaps branch from 4318e40 to c01bb13 Compare November 3, 2022 00:19
@JoelCourtney JoelCourtney temporarily deployed to e2e-test November 3, 2022 00:19 Inactive
@JoelCourtney
Copy link
Contributor Author

JoelCourtney commented Nov 3, 2022

  • Fixed problem that was forcing datasets to start at the plan start.
  • Added e2e test
    • It doesn't test the full process of adding and querying an external dataset because the code for retrieving datasets is not exposed as a hasura action. So instead it uploads a dataset and queries it directly from hasura's autogenerated plan_dataset_by_pk query.
    • This tests that we correctly store datasets that don't start at the plan start, and that we store gaps in the middle of profiles.
  • Added tutorial docs
  • Switched to using a duration column on the profile table instead of an extra segment.

@pcrosemurgy pcrosemurgy self-requested a review November 3, 2022 01:15
Copy link
Contributor

@pcrosemurgy pcrosemurgy left a comment

Choose a reason for hiding this comment

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

Re-reviewing after the recent fixes, documentation, and e2e tests. Looks good to me!

@JoelCourtney JoelCourtney force-pushed the feat/AERIE-2145--external-profile-gaps branch from c01bb13 to ac73b4a Compare November 3, 2022 16:59
@JoelCourtney JoelCourtney temporarily deployed to e2e-test November 3, 2022 17:00 Inactive
@JoelCourtney JoelCourtney force-pushed the feat/AERIE-2145--external-profile-gaps branch from ac73b4a to 7c4582f Compare November 7, 2022 18:33
@JoelCourtney JoelCourtney temporarily deployed to e2e-test November 7, 2022 18:33 Inactive
@JoelCourtney JoelCourtney merged commit 4f254ae into develop Nov 7, 2022
@JoelCourtney JoelCourtney deleted the feat/AERIE-2145--external-profile-gaps branch November 7, 2022 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature or feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants