Measures
and Logs


What is a measure ?

A measure is the recording of a metric data on a time basis.


A metric is a value on which an operation (sum, average, …) can be done


The recording periodicity could differ for each measure, some can record with a periodicity of 1 minute, other with a periodicity of one month, and for others the periodicity can be not regular (for instance the record of a temperature only when it’s change for more than 1°C).

The object to record can be the one of a sensor (temperature, energy, …), it could be the change of state of a device (the change to the state “on” of a light that is recorded to answer to the question how many time in the past month that light has been switched on?), it can be an object not related to a device (how many time a sequence has been run in the past month?), it can be the result of a calculation (a gateway calculates an object being the result of the combination of events and sensors, for instance, how many time a gateway has avoided a breakdown?)

The object to record can be composed of one value (a temperature), but can be composed of many values (a session in the case of an EVCS containing for a session, the duration and the energy consumed)



Implementation : a sub "measures"by ressources

Most of the time a measure is related to a resource: device, sequence, installation, …
For exemple: the measure “energy” is related to a "meter", “temperature” to a thermostat,  a "state: switched-on” to a light, ….
But a measure can also be linked to another resource: "number of time a sequence has run", "number of time a user has connected itself to an installation", …

As a result, a measure is a sub-collection of a resource

 

 

/installations/{id}/house-meters/{id}measures/{id}
/installations/{id}/thermostats/{id}/measures/{id}


A measure is composed of two sets of data

 

1 / Meta data

It describes a measure. searchable with a GET. A resource could support many measures, for instance a weather station can support a measure for the wind, the brightness and the temperature. Each of them is defined by a set of properties being the metadata describing the measure. 

 

The meta-data describing a measure are :

  • Name : a friendly name (example : external wind”, “indoor temperature”)
  • Type : Use to regroup measures in categories describing its format and potential operations (speed, temperature)
  • Unit : for a type, different units can exist (Temperature can use Celsius or Fahrenheit as unit, Speed can use m/s or Km/h or mph
  • Periodicity :  indicate at which periodicity the values are recorded

In case of our weather station, we have three measures :

 

GET/installations/{id}/weather-station/{id}/measures/{1}=>   
             <={“id”:”1”,“name”:wind”,”type”:”speed”,”unit”:”mph”,”periodicity”:”on-change”}
GET/installations/{id}/weather-station/{id}/measures/{2}=>   
             <={“id”:”2”,“name”:”sunight”,”type”:”brightness”,”unit”:”lux”,”periodicity”:”minutes”}
GET/installations/{id}/weather-station/{id}/measures/{3}=>   
             <={“id”:”3”,“name”:”rain”,”type”:”rainfall”,”unit”:”mm”,”periodicity”:”minutes”}
GET/installations/{id}/lights/{id}/measures/{1}=>                   
             <={“id”:”1”,“name”:switched-on”,”type”:”boolean”,”unit”:”boolean”,”periodicity”:”on-change”}


Note :  A measure can return per timestamp one or several values. The unit is only for the first one (the most important one).


2 / Value data

In order to interrogate the values, a specific query language is available.
Here under are the keywords to use in order to interrogate a measure data

 

  • start-date  (mandatory)
  • end-date   (mandatory in order to avoid a return with too many values)
  • [step]        (optional : minute, month, year, etc …)

For a MEASURE, different operations are available such as average, sum, min-max, count, list.


 

[POST/installations/{id}/weather-station/{id}/measures/{1}/operators/average
          {“start-date”:”01/01/2018”,”end-date”:”31/01/2018”}
POST/installations/{id}/lights/{id}/measures/{2}/operators/count          
          {“start-date”:”01/01/2018”,”end-date”:”31/01/2018”,”step”:”month”}


Note : if no [step] is specified, it will take the periodicity set by default in the device


As a developer, any operations can be used on a MEASURE (average, sum, count, etc…), but sometimes the return can have no real meaning. 
For instance, if an average operation is made on a boolean data (the switched-on of a light) the data will be returned but will have no real meaning. 
Knowing that a light has switched-on 0,654 times on average for the past month could not be explicit.



An example with Domovea installation composed by three devices :


  • One energy meter with one sensor which measure energy with a periodicity of one value per minute
  • One weather station with three sensors (temperature, brightness, wind)
  • One light with no sensor but with the state of the light that is recorded

The major endpoints of that installation are:

/installations/{id}
/installations/{id}/lights/{id}
/installations/{id}/house-meters/{id}
/installations/{id}/weather-stations/{id}


So the first thing to do is knowing which kind of meta-data is measure for those devices.
In a postman software I use a GET function


 Input

Output

GET /installation/[id]/lights/{id}/measures

[

{"id":"1","name":

"switeched-on",

"type":"boolean",

"periodicity":"on-change"

}

]


Now that I know what to call, I can use "Post" operation:



 Input

Output

POST /installations/{id}/measures/{1}/operators/count

{"start-date":"01/01/2018","end-date":"01/01/2019","step":"day"}

[

{"date":"xxxxxx";"value":yyyy}

{"date":"xxxxxx";"value":yyyy}

......

]

 
 

POST /installations/{id}/weather-stations/{id}/measures/{id}/operators/average

{"start-date":"01/01/2018","end-date":"01/01/2019","step":"month"}

 

[

{"date":"xxxxxx";"value":yyyy}

{"date":"xxxxxx";"value":yyyy}

......

]

 

GET /installations/{id}/changing-stations/{id}/measures

 

[

{"id" : "1",  "name":"energy","type":"energy","unit":"kWh","periodicity":"5 minutes"}

{"id":"2","name":"cost","type":"energy-cost","unit":"euro","periodicity":"5 minutes"}

]

 

What is a log ?



A log is the recording of a non-metric data on a time basis. 
A non-metric is a value on which operations (sum, average, …) cannot be done
It follows the same characteristics than a MEASURE about periodicity, and number of properties (1 or many) per LOG



 

Implementation : a sub collection « logs » by ressources

 

Most of the time a log is related to a resource being a device, a sequence, an installation…

For the devices, the log can be an error number and an error message, it can be an event such as an alarm alert, the change of an installation/configuration property.
Important the major difference between a log and a measure is the fact that a log is a non-metric data on which no calculation can be done.
As a result, a,log is a sub-collection of a resource, for example :


/installations/{id}/house-meters/{id}/logs
/installations/{id}/thermostats/{id}/logs/{id}


A log is composed of two set of data

1 / Meta Data

 

The meta-data = describing a log. searchable with a GET
The values-data = the data log . Searchable with a POST /OPERATORS and a specific QUERY LANGUAGE

 

The meta-data describing a log is composed by :

  • A complete name : “errors”, “car plug/unplugged”
  • A Periodicity :  indicate at which periodicity the values are recorded

In the case of our charging-stations, we have two logs :


GET/installations/{id}/charging-stations/{id}/logs/{1}=> <=“id”:”1”,“name”:”errors”,”periodicity”:”on-change”}
      GET/installations/{id}/charging-stations/{id}/logs/{2}=> <={“id”:”2”,“name”:”car plug/unplug”,”periodicity”:”on-change”}


2 / Value Data

 

In order to interrogate the values, a specific query language is available.
Here under are the keywords to use in order to interrogate a measure data

  • start-date  (mandatory)
  • end-date   (mandatory in order to avoid a return with too many values)

On a LOG, two operations are available list and count.


POST/installations/{id}/charging-stations/{id}/logs/{1}/operators/list  {“start-date”:”01/01/2018”,”end-date”:”31/01/2018”}
POST/installations/{id}/charging-stations/{id}/logs/{1}/operators/count  {“start-date”:”01/01/2018”,”end-date”:”31/01/2018”, “step”:”month”}

GET/installations/{id}/charging-stations/{id}/logs=> <=“[
                                                          {“id”:”1”,“name”:”errors”,”periodicity”:”on-change”}  
                                                          {“id”:”2”,“name”:”car plug/unplug”,”periodicity”:”on-change”}                                                                                      ]
POST/installations/{id}/charging- stations{id}/logs/{1}/operators/list  {“start-date”:”01/01/2018”,”end-date”:”01/01/2019”}   => <=“[                          
                                                            {“date”:”xxxxxx”,”error-code”:”x”,”error-text”:"content”},                                                                  {“date”:”xxxxxx”,”error-code”:”x”,”error-text”:”content”},                                                                   ]
POST/installations/{id}/charging-stations{id}/logs/{1}/operators/count  {“start-date”:”01/01/2018”,”end-date”:”01/01/2019”,”step”:”month =>  <=“[             
                                                                               {“date”:”xxxxxx”,”value”:yyyy},                                                                                                         {“date”:”xxxxxx”,”value”:yyyy},                                                                                                          .......                                                                                                                                                 ]