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 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
now I call Querynumberporpertyhistory service 2 times, but I concern about performance
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
}
}
Solved! Go to Solution.
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
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
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
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
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