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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

How to use "maxItems" in query parameter of Querynumberporpertyhistory service

AL_10742319
5-Regular Member

How to use "maxItems" in query parameter of Querynumberporpertyhistory service

how to set "maxItems" into query input in service 
example
I need to query data from Start(8:00) - End(9:00) maxItems = undefined
and I need to query data from Start(undefined) - End(8:00) maxItems = 1

AL_10742319_0-1720170873290.png

now I call Querynumberporpertyhistory service 2 times, but I concern about performance 

AL_10742319_1-1720170931951.png

is possible to call 1 time and use query parameter in Querynumberporpertyhistory
now I try, maxItems is not work but timestamp is work
{
"filters": {
"type": "Between",
"fieldName": "timestamp",
"from": 1720054800000,
"to": 1720058400000,
"maxItems": 1,
"oldestFirst": false
}
}

ACCEPTED SOLUTION

Accepted Solutions

Hi @AL_10742319 

 

For this use case, we have to query 2 times for values logged in Value Stream. And QueryNumberPropertyHistory limited to 1 row should not take more time to get data from DB.

 

If it is critical to have previous value, you can create a Stream to store values using custom script and property DataChange event. In stream, you can store previous value and timestamp whenever new value comes from sensor.

 

Check more about stream here -ThingWorx Tutorials: Introduction to Streams - PTC Community

 

/VR

 

 

View solution in original post

3 REPLIES 3

Hi @AL_10742319 

 

Why do you want to query 2 times. In first query you have all required data.

 

You can take 1st entry timestamp value by below code.

 

 

let sensorDataAcutalFirst = sensorDataActual.rows[sensorDataActual.length - 1].value

 

 

which gives you 1st data entry value.

 

Or instead of querying data again for the same start timestamp. You can use Query Snippet to filter InfoTable data

 

let params = {
	t: undefined /* INFOTABLE */,
	query: undefined /* QUERY */
};

// result: INFOTABLE
let result = Resources["InfoTableFunctions"].Query(params);

 

 

And it is not possible to include maxItems in Query. More about Query parameters - Query Parameter for Query Services (ptc.com)

 

/VR

 

AL_10742319
5-Regular Member
(To:Velkumar)

Hello @Velkumar 
thank you for replying
if I need to get all data between 08-07-2024 8:00AM to 08-07-2024 12:00pM
I call 1st query, but it does not return value period 08-07-2024 8:00AM until First Row(08-07-2024 8:09 AM)
when I put to LineChart Widget it's not display correctly

AL_10742319_2-1720421323172.png

 

then I call 2nd query for get first value of before 08-07-2024 8:00AM assume value that return is of time 08-07-2024 8:00AM

and combine with first infotable

AL_10742319_1-1720420446112.png

 


Let's say that our sensors change infrequently.
And if I choose the start time The first record may be very far from start time that selected.
For example, the data was updated at 7:50 and 8:30, and I choose start 8:00, meaning we got first value at 8:30. and don't know value at 8:00-8:30
Because of this problem, I had to do it 2 time.

Hi @AL_10742319 

 

For this use case, we have to query 2 times for values logged in Value Stream. And QueryNumberPropertyHistory limited to 1 row should not take more time to get data from DB.

 

If it is critical to have previous value, you can create a Stream to store values using custom script and property DataChange event. In stream, you can store previous value and timestamp whenever new value comes from sensor.

 

Check more about stream here -ThingWorx Tutorials: Introduction to Streams - PTC Community

 

/VR

 

 

Announcements


Top Tags