Skip to content

Data representation

liamjjmcnamara edited this page Oct 10, 2014 · 25 revisions

This page gives examples of the JSON representation for the many different entities in the SicsthSense system. The JSON is how the system describes these entities, and will be returned on GETs, they can then be modified and POSTed back to the system. The standard representation format is JSON, but CSV can be requested as described below.

User

A User is represented by the following JSON structure. Note that the only required field is username, all the rest can be filled in automatically by the system, or be assigned some default values. The fields id, creationDate and lastLogin are handled internally by the system and are read-only.

{
        "id":1,
        "openIDIdentifier":null,
        "authorities":[],
        "creationDate":1383469440445,
        "lastLogin":1383469440445,
        "openIDDiscoveryInformationMemento":null,

        "username":"[email protected]",
        "passwordDigest":null,
        "firstName":"Alice",
        "lastName":"Wonderland",
        "description":"",
        "email":null,
        "latitude":40.0,
        "longitude":18.0,
        "password":null,
        "admin":false,
        "token":null,
        "resources":[
                ...
        ]
}

Resource

A Resource is represented by the following JSON structure. Note that the only required field is label, all the rest can be filled in automatically by the system, or be assigned some default values. Also, if you would like the resource to automatically poll a remote URL, the polling_url must be set to a valid HTTP URL, and the polling_period to a positive non-zero integer representing the period of polling in seconds. The fields id, owner_id, parent_id, last_polled and last_posted are handled internally by the system and are read-only.

{
        "id":2,
        "owner_id":1,
        "parent_id":-1,
        "last_polled":0,
        "last_posted":0

        "label":"New resource",
        "description":"",
        "polling_url":null,
        "polling_authentication_key":null,
        "polling_period":0,
        "version":"1.0",
        "secret_key":"32795d7d-b875-4aff-94b3-1a32f40f1015",
}

Stream

A Stream is represented by the following JSON structure. Note that there are no required fields, all can be filled in automatically by the system, or be assigned some default values. The fields id, owner_id and resource_id are handled internally by the system and are read-only.

{
        "id":3,
        "owner_id":1,
        "resource_id":13,

        "type":"t",
        "latitude":0.0,
        "longitude":0.0,
        "description":"light measure",
        "public_access":false,
        "public_search":false,
        "frozen":false,
        "version":0
        "history_size":0,
        "last_updated":0,
        "secret_key":"8fbefad4-602c-4ce2-aecf-5f6ce16d2f3a"
}

Parser

A Parser is represented by the following JSON structure. Note that there are no required fields, all can be filled in automatically by the system, or be assigned some default values. The fields id and resource_id are handled internally by the system and are read-only. The new definition should be POSTed to http://HOST/users/_/resources/_/parsers*.

{
        "id":3,
        "resource_id":13,
        "stream_id":3,

        "input_parser":"/tets",
        "input_type":"application/json",
        "timeformat":"unix",
        "data_group":1,
        "time_group":2,
        "number_of_points":1
}

Data

Actual data payloads can be represented through any format, though the preferred one is JSON. Any type of JSON primitive value can be consumed by Resources, depending on how the parsers are configured. If Streams are being directly interacted with, the format needs to be slightly more strict. It needs to contain value and can optionally contain a timestamp value.

{
  "value": 2.5,
  "timestamp": 1384249393
}

Alternative format

If you would like data streams to be sent in CSV format, then simple append the following to the GET URL: format=csv For instance requesting the URL: http://HOST/users/1/resources/1/streams/1/data?token=KEY&limit=2&format=csv

Clone this wiki locally