Skip to content

Introducing DataStore and the v0.5.x line

Compare
Choose a tag to compare
@RobAtticus RobAtticus released this 15 Dec 19:35
· 67 commits to master since this release

The 0.5.x releases mark a significant change for how data is stored by the iobeam client. Users are now encouraged to use a DataStore object instead of DataPoints. DataStores use a table-like format to store data values, where series of points are columns and each row represents a specific time.

Deprecation Notice

Many of the DataPoint functions and types have been marked as deprecated in the 0.5.x releases. We will remove these classes and methods in a future release, likely 0.6.0. Please migrate your code to using DataStores as soon as possible.

Using DataStore

Users should group series together in a single DataStore where it makes sense, i.e., when two types of values are always or mostly collected together. For example, if you are collecting both temperature and humidity every 10s, you would use a single DataStore for them.

Iobeam iobeam = ... // Initialize iobeam
// Initialize DataStores
DataStore conditions = iobeam.createDataStore("temperature", "humidity");

// Called every 10s
public void addConditionsData(temperature, humidity) {
    Map<String, Object> values = new HashMap<String, Object>();
    values.put("temperature", temperature);
    values.put("humidity", humidity);
    conditions.add(values);
}

DataStores are initialized once, usually along with the Iobeam client itself. You can then add as many rows as you want to them, and when ready call send()/sendAsync() as before. You can have multiple DataStores if, for example, data is collected on different cycles. If you are also collecting battery every minute:

Iobeam iobeam = ... // Initialize iobeam
// Initialize DataStores
DataStore conditions = iobeam.createDataStore("temperature", "humidity");
DataStore battery = iobeam.createDataStore("batteryPct");

// Called every 10s
public void addConditionsData(temperature, humidity) {
    Map<String, Object> values = new HashMap<String, Object>();
    values.put("temperature", temperature);
    values.put("humidity", humidity);
    conditions.add(values);
}

// Called every minute
public void addBatteryData(percent) {
    Map<String, Object> values = new HashMap<String, Object>();
    values.put("batteryPct", percent);
    battery.add(values);
}

You can add data to a DataStore as a map (shown above), or as two arrays (columns and values), or as two Lists (columns and values). Additionally, you can optionally include the timestamp as the first argument to the add() call to set a specific time, otherwise it defaults to the value of System.currentTimeMillis().