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

Switch TimeSeries to nanosecond precision #3281

Merged
merged 21 commits into from
Feb 11, 2025
Merged

Switch TimeSeries to nanosecond precision #3281

merged 21 commits into from
Feb 11, 2025

Conversation

rolnico
Copy link
Member

@rolnico rolnico commented Jan 21, 2025

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Does this PR already have an issue describing the problem?
No

What kind of change does this PR introduce?
Feature

What is the current behavior?
TimeSeries time precision is currently limited to millisecond.
TimeSeries internal time values are stored in a Long variable.

What is the new behavior (if this is a feature change)?
TimeSeries time precision is now limited to nanosecond.
TimeSeries internal time values are stored in an Instant variable (using a long for second precision + an int for the second to nano precision).
Micro and Nano TimeFormat have been added.

By default, the new methods that have a TimeFormat parameter uses TimeFormat.MILLIS to keep backward compatibility.

Does this PR introduce a breaking change or deprecate an API?

  • Yes
  • No

If yes, please check if the following requirements are fulfilled

  • The Breaking Change or Deprecated label has been added
  • The migration steps are described in the following section

What changes might users need to make in their application due to this PR? (migration steps)

The interface TimeSeriesIndex has new methods that you have to implement, should you implement this interface:

  • void writeJson(JsonGenerator generator, TimeSeries.TimeFormat format)
  • String toJson(TimeSeries.TimeFormat format)

Since time is now managed by using Instant instead of long variables, a few methods have been deprecated and will be removed in a future release:

Class Deprecated method New method
TimeSeriesIndex and all classes implementing this interface long getTimeAt(int point) Instant getInstantAt(int point)
AbstractPoint and all classes extending this abstract class public long getTime() public Instant getInstant()
IrregularTimeSeriesIndex public IrregularTimeSeriesIndex(long[] times) public IrregularTimeSeriesIndex(Instant[] instants)
RegularTimeSeriesIndex public RegularTimeSeriesIndex(long startTime, long endTime, long spacing) public RegularTimeSeriesIndex(Instant startInstant, Instant endInstant, Duration timeStep)
RegularTimeSeriesIndex public long getStartTime() public Instant getStartInstant()
RegularTimeSeriesIndex public long getEndTime() public Instant getEndInstant()
RegularTimeSeriesIndex public long getSpacing() public Instant getTimeStep()
DoublePoint public DoublePoint(int index, long time, double value) public DoublePoint(int index, Instant instant, double value)
StringPoint public StringPoint(int index, long time, String value) public StringPoint(int index, Instant instant, String value)

Following the change of underlying date-time variable format (from long to Instant), the TimeSeriesIndex.toJson and TimeSeriesIndex.writeJson exported formats have been changed to allow nano-second precision while keeping the backward compatibility, thanks to a new enum TimeSeriesIndex.ExportFormat:

  • Old format that will still be used when timeFormat = TimeSeriesIndex.ExportFormat.MILLISECONDS (default value) for backward compatibility:
{
  "startTime" : 1420070400000,
  "endTime" : 1420074000000,
  "spacing" : 900000
}
  • New format that will be used when timeFormat = TimeSeriesIndex.ExportFormat.NANOSECONDS:
{
  "startInstant" : 1420070400000000000,
  "endInstant" : 1420074000000000000,
  "timeStep" : 900000000000
}

Other information:

@rolnico rolnico self-assigned this Jan 21, 2025
Signed-off-by: Nicolas Rol <[email protected]>
# Conflicts:
#	time-series/time-series-api/src/main/java/com/powsybl/timeseries/IrregularTimeSeriesIndex.java
#	time-series/time-series-api/src/main/java/com/powsybl/timeseries/TimeSeries.java
#	time-series/time-series-api/src/test/java/com/powsybl/timeseries/TimeSeriesTest.java
Signed-off-by: Nicolas Rol <[email protected]>
Signed-off-by: Nicolas Rol <[email protected]>
Signed-off-by: Nicolas Rol <[email protected]>
Signed-off-by: Nicolas Rol <[email protected]>
Signed-off-by: Nicolas Rol <[email protected]>
@rolnico rolnico marked this pull request as ready for review January 22, 2025 12:06
Signed-off-by: Nicolas Rol <[email protected]>
Signed-off-by: Nicolas Rol <[email protected]>
Signed-off-by: Nicolas Rol <[email protected]>
Signed-off-by: Nicolas Rol <[email protected]>
Signed-off-by: Nicolas Rol <[email protected]>
Signed-off-by: Nicolas Rol <[email protected]>
Signed-off-by: Nicolas Rol <[email protected]>
@olperr1 olperr1 merged commit 1d22961 into main Feb 11, 2025
8 checks passed
@olperr1 olperr1 deleted the nro/nanoseconds_ts branch February 11, 2025 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants