nguyenquanghai1993 / openhab

Automatically exported from code.google.com/p/openhab
GNU General Public License v3.0
0 stars 0 forks source link

REST interface for HISTORY query #419

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
1. Feature Description
A REST interface to allow querying historical data. This can support a charting 
user interface.

2. Example Use Case
Read back time sequence data from a queryable persistence service and return it 
via JSON to a js GUI for graphing.

I suggest that people comment on the requirements for the history service so 
that this can be agreed.  Currently, I have implemented the following -:
Input:
/rest/history/<itemname>?starttime=a&endtime=b
Where starttime and endtime are java/javascript long times (milliseconds since 
Jan 1 1970).

Output:
<history>
  <type>Item type</type>
  <name>Item name</name>
  <link>http://<address>/rest/history/itemname</link>
  <timestart>time of first record</timestart>
  <timeend>time of last record</timeend>
  <statemax>maximum value</statemax>
  <timemax>time of maximum value</timemax>
  <statemin>minimum value</statemin>
  <timemin>time of minimum value</timemin>
  <stateavg>average value over data set</stateavg>
  <datapoints>number of datapoints in the data set</datapoints>
  <data>
    <time>time of data point</time>
    <value>value of datapoint</value>
  </data>
</history>

If <itemname> is omitted from the call, then the interface returns the data 
from all items, but without the data (ie only the statistical data).

Original issue reported on code.google.com by ch...@cd-jackson.com on 22 Aug 2013 at 4:22

GoogleCodeExporter commented 8 years ago
Very nice!

Original comment by mishoboss on 23 Aug 2013 at 12:09

GoogleCodeExporter commented 8 years ago
i think that's a good dataset, maybe on request (as argument) we may skip the 
calculated values, if you have a large dataset, the maybe need long to 
calculate 

Original comment by openhab.lb on 5 Sep 2013 at 4:00

GoogleCodeExporter commented 8 years ago
maybe we can introduce different formats of the output, my servlet returns 
valid output for google chart api, different url... maybe

Original comment by openhab.lb on 5 Sep 2013 at 4:03

GoogleCodeExporter commented 8 years ago
insert, update, delete values should alse be possible

at the moment i have

{
    "name": "DB4O_Proplanta_Temperatur", 
    "state": {
        "registrationTime": 1378393614758, 
        "value": 30
    }, 
    "timestamp": 1378393614758, 
    "type": "NumberItem"
}

but there should be the information what to do with. at the moment insert new 
state

Original comment by openhab.lb on 5 Sep 2013 at 4:08

GoogleCodeExporter commented 8 years ago
Agreed - this shouldn't be just a query interface and needs to support 
insert/update/delete as you suggest.

Calculated values can be skipped - I'm not sure it's a big overhead though. The 
way I've done it they are all calculated together (ie one loop through the 
data).

Original comment by ch...@cd-jackson.com on 5 Sep 2013 at 4:29

GoogleCodeExporter commented 8 years ago
I'm currently in the process of updating what I've implemented in HABmin, and 
I've also refactored the mySQL binding to allow it to be split for the Postgres 
binding. In the process, I've added another persistence class 
(CRUDPersistenceService) that supports update and delete (as well as the 
existing store and query methods).

I'm now implementing the update/delete functionality in HABmin, and propose to 
use the same beans for update/delete as is used to get data -:
  <data>
    <time>1380718950000</time>
    <value>18.875</value>
  </data>

So, to delete, you would send a DELETE request to 
/rest/persistence/<service>/<item> with the above bean.

I've also added additional services to get the list of current persistence 
services, and a list of all items currently being stored by those services.  
I've currently documented what I've done on the HABmin wiki page 
(https://github.com/cdjackson/HABmin/wiki/REST-Persistence).

Original comment by ch...@cd-jackson.com on 3 Oct 2013 at 1:27

GoogleCodeExporter commented 8 years ago
does create already work ?

Original comment by openhab.lb on 7 Oct 2013 at 8:46

GoogleCodeExporter commented 8 years ago
If you mean does is work in the REST JAR on the HABmin site, then no - not yet 
(or maybe I should say, it's not tested). It's implemented, but I've not yet 
tested it as I've been completely refactoring the persistence interface to 
remove the pass through PersistenceExtensions and go directly to the database 
service (much cleaner).

However, since this doesn't interface directly to the database, we need a new 
service class that addes update and delete, and the persistence services that 
support update/delete would need to be changed to extend this class rather than 
the current QueryablePersistenceService. DB4O should be ok, and it is a simple 
task to just change the class and add the two members.

Last week I submitted a pull request for a new persistence service class 
(CRUDPersistenceService) which adds the update and delete methods to the 
existing QueryablePersistenceService (as well as a getRecordCount method to get 
the number of records for a given item). This is currently awaiting approval by 
Kai.

Original comment by ch...@cd-jackson.com on 7 Oct 2013 at 9:45

GoogleCodeExporter commented 8 years ago
ok...

Original comment by openhab.lb on 7 Oct 2013 at 6:50

GoogleCodeExporter commented 8 years ago
do you have an url for me to checkout  ?

Original comment by openhab.lb on 7 Oct 2013 at 6:52

GoogleCodeExporter commented 8 years ago
URL for what?

My github clone is at 
https://github.com/cdjackson/openhab
Note that there are quite a few branches as I'm branching a separate branch for 
each issue I'm working on to make the pull requests easier to manage.

The pull request for the updated CRUDPersistenceService is at 
https://github.com/openhab/openhab/pull/24
I'm very keen to get this into the main repository as I've refactored the mysql 
service based on this and it's needed by Ingo to port to the postgressql 
service...

HABmin is at https://github.com/cdjackson/HABmin

Let me know if that doesn't answer what you're after.

Original comment by ch...@cd-jackson.com on 7 Oct 2013 at 7:03

GoogleCodeExporter commented 8 years ago
i like postgressql too ;-)

Original comment by openhab.lb on 7 Oct 2013 at 9:05

GoogleCodeExporter commented 8 years ago
Just for reference, there is some further discussion ongoing here regarding 
adding update/delete services -:
https://github.com/openhab/openhab/pull/24

Original comment by ch...@cd-jackson.com on 17 Oct 2013 at 11:49

GoogleCodeExporter commented 8 years ago
hi cdjackson,

i have read the issue on git hub, i still would like to store values to db, 
should i work as you do ? work on my copy of openhab, or an copy/trunk of 
habmin ?

Original comment by openhab.lb on 19 Nov 2013 at 12:01

GoogleCodeExporter commented 8 years ago
what do you think ?

Original comment by openhab.lb on 19 Nov 2013 at 12:02

GoogleCodeExporter commented 8 years ago
I agree that writing to the db should be allowed, and I was thinking that based 
on Kais comments that he thought it should be a separate interface, that we 
could/should define a new interface for more direct access into the database. 
I'm still not sure that this will be acceptable, but it may make sense anyway.

 
If you want to fork HABmin, that's fine. Currently the openhab side is in a 
state of transition as I'm waiting for Kai to approve the dynamic sitemap 
changes. Once this is done, then I'll release a version of HABmin that is a 
separate bundle (ie not included in the REST bundle). This is all complete, so 
just waiting on the sitemap changes to be merged - I hope this will be very 
soon as I've had no feedback on this for a few days.

 
Likewise with the javascript side of HABmin - feel free to fork the code and 
play with it. If your changes are of general use then I'd love to merge them 
into HABmin.

 
Can you give me a better idea of what you want to do (just an outline) and I 
could comment on how I think is best from HABmin perspective. If it's something 
that would be a general benefit, then I might be able suggest how to modify 
HABmin so that your changes can be easily integrated. Alternatively, you can 
keep it separate and use the HABmin source - up to you really, but I'm 
certainly happy to accept any contributions with HABmin :)

 
Chris
 

Original comment by ch...@cd-jackson.com on 21 Nov 2013 at 1:38

GoogleCodeExporter commented 8 years ago
Migrated to https://bugs.eclipse.org/bugs/show_bug.cgi?id=423547

Original comment by kai.openhab on 8 Dec 2013 at 8:14

GoogleCodeExporter commented 8 years ago
May I ask what's the star of this?
Has this been integrated into openHAB 1.4?

Manfred

Original comment by manfb...@gmail.com on 25 May 2014 at 10:16