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 Data

Details how to use the Basic Java API to work with timeseries data.

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 before continuing with the material below.

Loading timeseries data

To load the timeseries of an ADO I create an instance of it using its ID. Then I call loadTimeseries(tree, startDate, endDate, attributes) to retrieve a TsRecords instance.

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

  TsRecords records = ado.loadTimeseries("CONSOLIDATION_C0", 20180319, 20180319,
                              new Attributes("C0#TS001"));
  assertThat(records.size(), is(1));

  TsRecord record = records.get(0);
  assertThat(record.getDate(), is(20180319));
  assertThat(record.getTime(), is(235959));
  assertThat(record.getValues().get(0), is(ValueFactory.createValue(123.5)));

You will see that you can supply the start and end dates as simple integer values. And you may be familiar with this from Formula Engine code. I find it very convenient and have adopted this into the Java API.

The Attributes class lets you define a list of one or more attributes that you are interested in. There is no need to list DATE and TIME as these are assumed to be key attributes anyway.

The TsRecords class has a method size() to check the number of records returned. Individual records can be accessed using get(index). Date and time are available via getters, again returning integers.

You can access the values of the requested attributes via getValues(). This returns an instance of type Values of which individual values can be retrieved by index.

Updating timeseries data

To store or update timeseries data I need to create a TsRecords instance. To this end, I can simply supply a list of TsRecord instances to its constructor.

Each TsRecord takes a date and time as simple integer values, followed by the list of attributes and values.

Please note: All records need to have the same set of attributes. And the number of values has to match the number of attributes in each record. Otherwise an exception will be thrown.

    Attributes attrs = new Attributes("C0#TS001");
    TsRecords records = 
            new TsRecords(
                    new TsRecord(20180101, 235959, attrs, new Values(100.0)),
                    new TsRecord(20180102, 235959, attrs, new Values(200.0))
            );
    ado.storeTimeseries("CONSOLIDATION_C0", records);

Once you have created a TsRecords instance you can simply store it in the specified tree.

And finally, the Basic Java API contains a method to delete all of an ADO’s timeseries in a tree:

  ado.deleteTimeseries("CONSOLIDATION_C0");

Thank you for reading.

You may want to learn about Timeseries Validation Functions next.

comments powered by Disqus