Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X
I need to find the last eventNumber value but I can’t sort the historical data finder by name:
def historicalDataItemValueCriteria = new HistoricalDataItemValueCriteria();
historicalDataItemValueCriteria.setAssetId(); //hard coded for now
//currentDataItemValueCriteria.setName("eventNumber "); //doesn't work
historicalDataItemValueCriteria.setStartDate(mStartDate); // 30 days ago
historicalDataItemValueCriteria.setEndDate(mEndDate); // today
//historicalDataItemValueCriteria.dataItemIds.push("xirgoxt4560||eventNumber ");
hfindResult = dataItemBridge.findHistoricalValues(historicalDataItemValueCriteria);
Do you have a code example for this?
I also tried current data value find but that only brings back one value and I need them all.
Also do you have an example of paging?
I can fall back to 6.5 code but it has the 1000 row limt.
It was released last year as a beta - but our 'mentor' site has proven to be quite useful. Have you had a look at https://mentor.axeda.com/magnoliaPublic/mentor/objects/DataItemBridge.html ?
All these examples are in the Axeda® Platform v2 API/Services Developer’s Reference as well.
import
static
com.axeda.sdk.v2.dsl.Bridges.*
import
com.axeda.services.v2.*
def
asset = assetBridge.
find
(
"Vending Machine 5000||A36"
)
assert
asset
def
findResult = dataItemBridge.findHistoricalValues(
new
HistoricalDataItemValueCriteria(
assetId: asset.systemId,
startDate:
new
Date() -
1
,
endDate:
new
Date()))
assert
findResult
findResult.dataItemValues.
each
{
println
(
"Historical value for ${it.dataItem.label}: ${it.value}"
) }
That's a great example but it doesn't filter by data item name.
I need to bring back the last n number of values of specific data item.
Thanks
Jay
Oh I totally missed that part of your question - sorry. I looked over the API and sadly I don't see a way to use the v2 services to filter based on data item name alone.
You will need to retrieve them all and do a simple if. I've attached the pagination examples we will ship with the next release in this post for DataItem. It will hopefully jumpstart you.
(edited - forgot how to do code blocks )
import static com.axeda.sdk.v2.dsl.Bridges.*
import com.axeda.services.v2.*
final int MAX_PAGES = 5 // guard rail, the max number of pages to retrieve
final int PAGE_SIZE = 1 // if you want to fetch all objects, set this to Constants.DEFAULT_PAGE_SIZE
int TOTAL_EXPECTED = MAX_PAGES * PAGE_SIZE
/* PLEASE READ
Please realize that if you have a very large number of objects it is not recommended to
add all of them to a result and try to return it. Use good judgement and common sense
otherwise you will potentially negatively impact the performance of your running server.
*/
// set up the criteria object - we want to find everything, so no filters
int currentPage = 1
DataItemCriteria criteria = new DataItemCriteria(pageNumber:currentPage, pageSize:PAGE_SIZE)
// do a first search to get the totalCount
FindDataItemResult initial = dataItemBridge.find(criteria)
List<DataItem> results = initial.dataItems
// iterate through all of the pages...... or until we hit the guard rail
while( initial.totalCount > currentPage * PAGE_SIZE && MAX_PAGES > criteria.pageNumber )
{
currentPage++
criteria.pageNumber = currentPage
initial = dataItemBridge.find(criteria)
results += initial.dataItems
}
// either we hit the guardrail, or we found all of them
assert results.size() == MAX_PAGES * PAGE_SIZE || results.size() == initial.totalCount
return new FindDataItemResult(totalCount:initial.totalCount, dataItems:results)
Thanks for the quick reply.
I'm doing that now but the response time is slow especially when the data item doesn't exist yet.
I'll have to find another way to filter.
Thanks
Jay