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

Issue 693 - Rating curve retrieval #909

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

zack-rma
Copy link
Collaborator

@zack-rma zack-rma commented Oct 10, 2024

Fixes #693 - Adds support for retrieving a rating closest to a specified date.

@zack-rma zack-rma marked this pull request as ready for review October 11, 2024 17:14
Copy link
Contributor

@MikeNeilson MikeNeilson left a comment

Choose a reason for hiding this comment

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

Looks good. nitpick about variable/parameter names.

String timezone = ctx.queryParamAsClass(TIMEZONE, String.class).getOrDefault("UTC");
Instant date = null;
String specificDate = ctx.queryParam(EFFECTIVE_DATE);
Copy link
Contributor

Choose a reason for hiding this comment

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

use effectiveDate throughout. it's confusing having this go from EFFECTIVE_DATE, to specificDate, to just "date" in the later code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated to use effectiveDate and effectiveDateParam for consistency

Copy link
Collaborator

Choose a reason for hiding this comment

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

While consistency is good, I think this illuminates that the parameter is confusing on this endpoint. I recommend using a separate endpoint. I might be missing a use case where a the closest effective date to a parameter is needed, but given temporal interpolation and transitional dates, that seems to be too complicated.

Instant startInstant = null;
Instant endInstant = null;
Result<?> results = connectionResult(dsl, c ->
dsl.select(view.RATING_ID, view.EFFECTIVE_DATE, view.RATING_CODE).from(view)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It should be possible to have this query do the limit rather than pulling all records and do tinghe limit in the CDA code

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Rewrote the query and removed the difference logic from the DAO

@adamkorynta adamkorynta removed their request for review October 31, 2024 22:50
@@ -339,6 +338,10 @@ public void getAll(@NotNull Context ctx) {
+ "otherwise specified), as well as the time zone of any times in the"
+ " response. If this field is not specified, the default time zone "
+ "of UTC shall be used."),
@OpenApiParam(name = EFFECTIVE_DATE, description = "Specifies the "
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a very confusing parameter.

  • three optional date parameters are confusing
  • what happens when all three are input?
  • the ask was for the current effective date, that means the client needs to always set this parameter to now. Why not just have another endpoint that does it automatically? /{rating-id}/latest-effective
  • the "closest" effective date shouldn't return a newer effective date than what is supplied as the newer effective date is not yet in effect, though this is made more complicated by temporal interpolations and transition dates.
  • how do active ratings play an effect? I presume they would be skipped, but that's missing from the docs (even from the start/end parameters)

Additionally, you are passing this confusion into the DAO by expanding the existing DAO method instead of creating a new one, so now you have three dates in the DAO function. This makes test cases far more complicated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved functionality to its own endpoint to reduce confusion. New endpoint returns closest effective date rating where the date is not beyond the current date.

@zack-rma zack-rma requested a review from adamkorynta November 26, 2024 23:29
@@ -437,13 +436,18 @@ private String getRatingSetString(Context ctx, RatingSet.DatabaseLoadMethod meth

private RatingSet getRatingSet(Context ctx, RatingSet.DatabaseLoadMethod method,
String officeId, String rating, Instant begin,
Instant end) throws IOException, RatingException {
RatingSet ratingSet;
Instant end, boolean latest) throws IOException, RatingException {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't add a boolean to a method to change the implementation, just create a new method

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Created a new method for latest rating retrieval

@zack-rma zack-rma requested a review from adamkorynta December 2, 2024 18:01
@zack-rma
Copy link
Collaborator Author

zack-rma commented Dec 7, 2024

Build failures appear to be unrelated to this PR

RatingSet.DatabaseLoadMethod method = ctx.queryParamAsClass(METHOD,
RatingSet.DatabaseLoadMethod.class)
.getOrDefault(RatingSet.DatabaseLoadMethod.EAGER);

String body = getRatingSetString(ctx, method, officeId, rating, beginInstant, endInstant);
String body = getRatingSetString(ctx, method, officeId, rating, beginInstant, endInstant, false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The changes to this controller should be gone right? the latest option is moved to RatingLatestController

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct, I moved any remnants to the RatingLatestController and cleaned up the original controller

import org.jooq.DSLContext;


public class RatingLatestController extends RatingController implements Handler {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The inheritance doesn't make sense here, this controller is calling a different DAO method

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed unnecessary inheritance

@@ -83,11 +101,96 @@ private static String extractOfficeId(String ratingSet) throws JsonProcessingExc
return office;
}

public RatingSet retrieveLatest(RatingSet.DatabaseLoadMethod method, String officeId,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this what cwms_rating.retrieve_eff_ratings_xml does? Can you verify with Mike Perryman?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll double check with Perryman

Copy link

@perrymanmd perrymanmd Dec 11, 2024

Choose a reason for hiding this comment

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

DISREGARD THE PREVIOUS COMMENT

CORRECT COMMENT

Yes you can use cwms_rating.retrieve_eff_ratings_xml_f() to get the most recent rating by setting both p_start_date and p_end_date to sysdate (or whatever time you want the most recent rating for).

@MikeNeilson
Copy link
Contributor

Build failures appear to be unrelated to this PR

Yep, it's the usual failures from other end points.

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.

Add most recent or currently effective to cwms-data/rating/{rating-id}
5 participants