Showing results for 
Search instead for 
Did you mean: 
Showing results for 
Search instead for 
Did you mean: 

Totals for daily timestamps in a stream


Totals for daily timestamps in a stream

Hi All

I am trying to figure something out, but might be over thinking it. Here is the scenario:

I collect hourly values with the Source, Timestamp and Value into a Stream.

I need to get the data from the stream to display a daily total of the values (that are hourly) for each day of the week in a bar graph.

Any advice?

Thanks in advance.



Re: Totals for daily timestamps in a stream

Hi Darryl,

This does sound like there is a straightforward answer, but I have not done it exactly. I am assuming this is a weekly process you would run, to calculate and show summed up values from the last week, by day of week.

If thats the case, I think I would:

1. Create a datashape that matches the output you want. This is probably just 7 number fields, named by day of the week, I think.

2. Create a service that returns the above datashape that:

     a. Sets 7 variables (sun, mon, tues..) to 0

     b. Queries your stream entries (with data) for the last week.

     c. Loops through them, checks the timestamp.getDay() this is the part I'm not sure ThWx is ok with, but probably is fine

     d. depending on getDay() result, add to appropriate variable from step a

     e. after loop, put those values your infotable of the right shape from step 1, so it has just the single row and return that infotable

3. In your mashup, this service feeds the bar chart, and you just have to set the widget parameters correctly

I don't know if thats too much or too little detail, but it should get you going.Let me know how you make out

Re: Totals for daily timestamps in a stream

Hi Alex

Thanks for the response.

That makes sense.

The things I am not sure how to do are:

Query the Stream entries for the last week, I have this so far: - not sure how to do it for just a day or week?

var query = {

  "filters": {

    "type": "AND",

    "filters": [


        "fieldName": "source",

        "type": "EQ",

        "value": source



        "fieldName": "Value",

        "type": "GE",

        "value": 0.001





And the loop for the timestamp.getDay(). Am stumped on this, can't find any snippets or anything on it.

Any help?



Re: Totals for daily timestamps in a stream

I would suggest opening the entities tab on the service writer, select your stream, and then select the service for QueryStreamEntriesWithData. That inserts the correct snippet, and you'll notice the service takes a StartDate and EndDate input, just use those. Your query then just focus on the value. Notice it also includes source, so you can put that there.

Not sure why you are querying for source = "", but who knows. As an aside, use the source input (and therefor design your stream schema) with the knowledge that it is the only way I know of to get increased performance in your query of the DB. Querying any other field is the exact same performance wise as writing your own loop, as I understand it.

The timestamp.getDay() just works, not sure how much other help I can be there.

Try writing this test service, and also google .getDay(), its a regular JS method.

var timestamp = new Date();

var result = timestamp.getDay();

Re: Totals for daily timestamps in a stream


Thanks, ya i have the querystreams snippet working in another service. But I am not sure how to implement the total for the day of the week.

I tried your suggestion for getDay()

and get this result:

Screen Shot 2017-10-20 at 12.10.46 PM.png

Re: Totals for daily timestamps in a stream

getDay() returns an integer, not a datetime. So change your test service output to see what it returns.

JavaScript getDay() Method


Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum! ______________________________