Skip to content
Julien Eberle edited this page Aug 11, 2015 · 3 revisions

Data Modelling

GSN supports some basic data modelling by providing a way to attach models to a data-stream. The virtual sensor gsn.vsensor.ModellingVirtualSensor has an array of model classes and each time a new StreamElement arrives, it is forwarded to the models for keeping them up-to-date. The models implement the gsn.utils.models.AbstractModel class. They can have parameters and those are passed through the virtual sensor at initialization time. The example below shows how to define a virtual sensor with two very simple model initialized with different parameters.

<virtual-sensor name="model_example" priority="10">
  <processing-class>
    <class-name>gsn.vsensor.ModellingVirtualSensor</class-name>
    <init-params>
        <param name="model">gsn.utils.models.DummyModel,gsn.utils.models.DummyModel</param> <!-- class names of the model to load, separated by , -->
        <param name="model.0.default">10</param>
        <param name="model.1.default">20</param>
    </init-params>
    <output-structure>
        <field name="value" type="integer" />
    </output-structure>
  </processing-class>

To be as generic as possible a model can be defined as a function formula, where the Xi and Yj are the domain of any field that can be contained in a StreamElement. Therefore the query over models is implemented by passing a StreamElement containing the n fields of the query and returning the result in a new one.

To access a model and for making a query the easiest way is to get the corresponding modelling virtual sensor and asking for the given model. A web interface has also been defined and using the following url allows making query from outside of GSN.

/modeldata?vs=model_example&models=1&format=xml&latitude=43.2&longitude=8.54&humidity=64

In this example, we query the second model of the virtual sensor we defined above and pass the latitude, longitude and humidity as arguments. The result is encoded in xml like this:

<results><stream-element timestamp="2013-03-01 12:50:51.806 CET">
  <field name="value" type="numeric">20</field>
</stream-element></results>

It is also possible to get a json output:

[{timestamp:1362142251806,fields:[{name:"value",type:"numeric",value:"20"},]},]

Another way of visualizing data from models is to generate a Grid. If the model is taking latitude and longitude as parameters, a grid can be built with the GridModelVS and then displayed with a GridRenderer.

Clone this wiki locally