GDPR Cookie Consent by Free Privacy Policy Generator
post thumb
Asset Control
by Matthias Hanitzsch-Moonlight/ on 11 Mar 2018

A Basic Java API for Asset Control - Timeseries Validation Functions

A demonstration of the Basic Java API functions to work with Timeseries Validation Functions.

Note: This article is part of a series. You may want to read the previous articles regarding how to Connect to AC and how to work with Static Data and Timeseries Data before continuing with the material below.

Retrieving Timeseries Validation Info

The Basic Java API allows you to retrieve the list of validation functions applied to an ADO in a given tree.

As validation functions may or may not have been applied, it returns an optional list of validation functions:

  Ado ado = ac.createAdo("C0.ISS.1");

  Optional<List<TsValidation>> validations = ado.getTimeseriesValidations("CONSOLIDATION_C0");
  assertThat(validations, isEmpty());

A different ADO may already have a validation function applied:

  Ado ado = ac.createAdo("C0.ISS.2");

  Optional<List<TsValidation>> possValidations = ado.getTimeseriesValidations("CONSOLIDATION_C0");
  assertThat(possValidations, isPresent());

  List<TsValidation> validations = possValidations.get();
  assertThat(validations.get(0), is(instanceOf(TsValidationNonPositive.class)));

Applying Timeseries Validation Functions

I can now apply new validation functions to an ADO in a given tree:

  Ado ado = ac.createAdo("C0.ISS.1");
  ado.addTimeseriesValidation("CONSOLIDATION_C0", new TsValidationNonPositive());
  
  Optional<List<TsValidation>> tsValidations = ado.getTimeseriesValidations("CONSOLIDATION_C0");
  assertThat(tsValidations, isPresent());
  assertThat(tsValidations.get().get(0), instanceOf(TsValidationNonPositive.class));

It is important to note that you can only apply validation functions if the datafile header exists. So, if needed, you may want to call something like the following to ensure a header is created before trying to apply validation functions:

  ado.amendTimeseriesHeaderWith("CONSOLIDATION_C0", new Attributes("CLOSE"));

Removing Timeseries Validation Functions

Of course, there is also a way to remove validation functions, either selectively or all of them:

  ado.removeTimeseriesValidation("CONSOLIDATION_C0", new TsValidationNonPositive());
  ado.removeAllTimeseriesValidations("CONSOLIDATION_C0");

Validating Timeseries Data

Once we have a validation function applied, we can see that timeseries records are being validated as we store them:

  ado.addTimeseriesValidation("CONSOLIDATION_C0", new TsValidationNonPositive());

  Attributes attrs = new Attributes("CLOSE");
  TsRecords records =
          new TsRecords(
                  new TsRecord(20180101, 235959, attrs, new Values(100.0)),
                  new TsRecord(20180102, 235959, attrs, new Values(-20.0))
          );
  ado.storeTimeseries("CONSOLIDATION_C0", records);

  TsRecords validatedRecords = ado.loadTimeseries("CONSOLIDATION_C0", 20180102, 235959, attrs);
  assertThat(validatedRecords.get(0).getValues().get(0).getStatus(), is(130));

We can also revalidate historical timeseries for an ADO in a tree over a given interval of dates:

  ado.revalidate("CONSOLIDATION_C0", 20180102, 20180131);

Thank you for reading.

In the next article of this series I am going to look at running Formula Engine code via the API.

comments powered by Disqus