-
Notifications
You must be signed in to change notification settings - Fork 14
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
Fixes #634 - Implemented data entry date option for TS data retrieval #927
base: develop
Are you sure you want to change the base?
Changes from 5 commits
95361d7
e04b7e4
6b9a89d
b91145c
20615da
1d0d389
667248d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,7 +62,6 @@ | |
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.TimeZone; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import java.util.regex.Pattern; | ||
|
@@ -623,7 +622,7 @@ private static TimeSeries buildTimeSeries(ILocationLevelRef levelRef, Interval i | |
if (qualityCode != null) { | ||
quality = qualityCode.intValue(); | ||
} | ||
timeSeries.addValue(dateTime, value, quality); | ||
timeSeries.addValue(dateTime, value, quality, null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure this isn't a breaking change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll double check with additional test cases, but this change should not break any existing functionality. A null data entry date parameter is treated as if a standard Time-Value-Quality data entry was provided. The implementation of
The existing use cases of TimeSeries should be unaffected, as they will be handled exactly as they were before these changes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend subclassing TimeSeries instead There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would break CWMS.js, The javascript openapi generator already has trouble with our TimeSeries class given some specific assumptions the generator chose to make. |
||
} | ||
return timeSeries; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,7 @@ | |
import org.jooq.Record; | ||
import org.jooq.Record1; | ||
import org.jooq.Record3; | ||
import org.jooq.Record4; | ||
import org.jooq.Record7; | ||
import org.jooq.Result; | ||
import org.jooq.SQL; | ||
|
@@ -165,7 +166,7 @@ public String getTimeseries(String format, String names, String office, String u | |
public TimeSeries getTimeseries(String page, int pageSize, String names, String office, | ||
String units, | ||
ZonedDateTime beginTime, ZonedDateTime endTime, | ||
ZonedDateTime versionDate, boolean shouldTrim) { | ||
ZonedDateTime versionDate, boolean shouldTrim, boolean includeEntryDate) { | ||
TimeSeries retVal = null; | ||
String cursor = null; | ||
Timestamp tsCursor = null; | ||
|
@@ -237,7 +238,7 @@ public TimeSeries getTimeseries(String page, int pageSize, String names, String | |
|
||
// put all those columns together as "valid" | ||
CommonTableExpression<Record7<BigDecimal, String, String, String, String, BigDecimal, | ||
String>> valid = | ||
String>> valid = | ||
name("valid").fields("tscode", "tsid", "office_id", "loc_part", "units", | ||
"interval", "parm_part") | ||
.as( | ||
|
@@ -249,7 +250,6 @@ public TimeSeries getTimeseries(String page, int pageSize, String names, String | |
unit.as("units"), | ||
ival.as("interval"), | ||
param.as("parm_part") | ||
|
||
).from(validTs) | ||
); | ||
|
||
|
@@ -369,6 +369,8 @@ public TimeSeries getTimeseries(String page, int pageSize, String names, String | |
); | ||
}); | ||
|
||
Field<Timestamp> dataEntryDate = field("DATA_ENTRY_DATE", Timestamp.class).as("data_entry_date"); | ||
|
||
if (pageSize != 0) { | ||
SelectConditionStep<Record3<Timestamp, Double, BigDecimal>> query = | ||
dsl.select( | ||
|
@@ -391,14 +393,55 @@ public TimeSeries getTimeseries(String page, int pageSize, String names, String | |
query.limit(DSL.val(pageSize + 1)); | ||
} | ||
|
||
logger.fine(() -> query.getSQL(ParamType.INLINED)); | ||
SelectConditionStep<Record3<Timestamp, Double, BigDecimal>> finalQuery = query; | ||
logger.fine(() -> finalQuery.getSQL(ParamType.INLINED)); | ||
|
||
query.forEach(tsRecord -> timeseries.addValue( | ||
tsRecord.getValue(dateTimeCol), | ||
tsRecord.getValue(valueCol), | ||
tsRecord.getValue(qualityNormCol).intValue() | ||
) | ||
); | ||
if (includeEntryDate) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This query is doubling the time it takes to retrieve time series. Can this replace the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While it could replace the |
||
SelectConditionStep<Record4<Timestamp, Double, BigDecimal, Timestamp>> query2 = dsl.select( | ||
dateTimeCol, | ||
valueCol, | ||
qualityNormCol, | ||
dataEntryDate | ||
) | ||
.from(AV_TSV_DQU.AV_TSV_DQU) | ||
.where(dateTimeCol | ||
.greaterOrEqual(CWMS_UTIL_PACKAGE.call_TO_TIMESTAMP__2( | ||
DSL.nvl(DSL.val(tsCursor == null ? null : | ||
tsCursor.toInstant().toEpochMilli()), | ||
DSL.val(beginTime.toInstant().toEpochMilli()))))) | ||
.and(dateTimeCol | ||
.lessOrEqual(CWMS_UTIL_PACKAGE.call_TO_TIMESTAMP__2( | ||
DSL.val(endTime.toInstant().toEpochMilli()))) | ||
.and(AV_TSV_DQU.AV_TSV_DQU.CWMS_TS_ID.equalIgnoreCase(names)) | ||
.and(AV_TSV_DQU.AV_TSV_DQU.OFFICE_ID.eq(office)) | ||
.and(AV_TSV_DQU.AV_TSV_DQU.UNIT_ID.equalIgnoreCase(unit)) | ||
.and(AV_TSV_DQU.AV_TSV_DQU.VERSION_DATE.eq(versionDate == null ? null : | ||
Timestamp.from(versionDate.toInstant()))) | ||
); | ||
|
||
if (pageSize > 0) { | ||
query2.limit(DSL.val(pageSize + 1)); | ||
} | ||
query2.forEach(tsRecord -> { | ||
assert timeseries != null; | ||
timeseries.addValue( | ||
tsRecord.getValue(dateTimeCol), | ||
tsRecord.getValue(valueCol), | ||
tsRecord.getValue(qualityNormCol).intValue(), | ||
tsRecord.getValue(dataEntryDate) | ||
); | ||
}); | ||
} else { | ||
query.forEach(tsRecord -> { | ||
assert timeseries != null; | ||
timeseries.addValue( | ||
tsRecord.getValue(dateTimeCol), | ||
tsRecord.getValue(valueCol), | ||
tsRecord.getValue(qualityNormCol).intValue(), | ||
null | ||
); | ||
}); | ||
} | ||
|
||
retVal = timeseries; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a purely pedantic standpoint this should really be a parameter of the content-type, but I may have to accept the reality of this being easier for everyone.
@krowvin, we were just discussing this conceptually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Path parameters are the "what" I am retrieving, query parameters are the "how" am I adding to or filtering that data, and content-type is the "shape" that is returned. This change effects the how and given the way the column names and data array are paired together to already give this flexibility, I don't see a change in shape.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a column is definitely a change in shape. The what is a time series, the query parameters specify exactly which time series, or at least which portion of a given time series (I guess if we're being really pedantic begin and end should be in the fragment... but I digress).
While the flexibility is there, it's flexibility to change the shape. I don't totally disagree with you but given we haven't communicated that portion of the contract very well we are introducing a breaking change. We already have more than one downstream library dependent on these types.
I'm going to type up something on the wiki, or maybe discussion, for the philosophy I'm going for with these, hopefully my argument makes more sense in regards to query vs content type. Especially as it relates to some of the challenges we're currently seeing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it is not conveyed very well that one should use the columns array to determine which index to grab from the data array. I don't think that adding information to the swagger docs to communicate that should trigger a content-type change though (maybe version=2.5 but that seems like a huge headache) especially since not including the parameter to retrieve entry date keeps the array intact for backwards compatibility.
Also, I've never seen an API where the content-type changes how much extra (or less) data gets returned to the client. I'd like to see some examples. I also don't see the reason (pedantic or not) for adding begin/end as path parameters as those are filters on the time series. Everything for the identifier of the time series encompasses the time series (which is also why the date version shouldn't be in the path and is a query parameter).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: not arguing for it, but explanation of my logic on the fragement.
a time series is:
/timeseries/Alder Springs.Precip-INC.Total.1Hour.1Hour.Calc?version_date=unversioned
identifies a specific time series which is a mathematical series of data - and technically all of it. The entire series could be consider a "document", a fragment is a section within a document; traditionally we would think of lines in a file, but it applies to the time series as well. A file, after all, is just a series of lines.As I said, extremely pedantic.... admittedly almost to the point of being useless because literally no one does it that way, nor would they even if it could be proven objectively correct.
Technically the units are also representation and not identification but given how limited the use of content-type features are used it would be incredibly difficult to get people to use it; I don't even think the Swagger-UI has a mechanism to slightly tweak the content-type.
But back on the topic of what's correct for us, it seems we're all in agreement that @DanielTOsborne 's initial design is already sufficiently flexible in the current scheme and our failure was in how we documented that for the general end user.
So we leave the inclusion as a query parameter unless a better way actually comes along.