Odata for returning aggregated summary of entities - odata

Is there any recommendation on how URL for API returning aggregated values and response from API should be.
for example: publisher has multiple authors and we want to return total amount of sale from all the authors (or filter for authors to consider for getting sum).
Thanks

Related

Microsoft Graph API : Criteria for "relevanceScore" of scoredEmailAddresses object

what is the internal logic to calculate the "relevanceScore" field of people resource in Microsoft graph api ? any documentation around it publicly available ??
According to this page,
The relevance score of the email address. A relevance score is used as a sort key, in relation to the other returned results. A higher relevance score value corresponds to a more relevant result. Relevance is determined by the user’s communication and collaboration patterns and business relationships.

OData paging with skip and top - how to know that there is no more data?

I have OData source, that implements $skip and $top parameters.
There are x number of entities that are returned. Say, I have only 250 entities. And then I try to do the paging like this:
https://example.com/EntitySet?$top=30&$skip=220
If my skip goes beyond the number of total entities, I eventually get timeout from service.
Is there a parameter or data, that would inform me that there are no more items? Is there something that can/should be implemented on OData side, that gets returned instead of timeout?
For OData 2.0 and OData 3.0 protocols:
You should use: $inlinecount=allpages
http://services.odata.org/OData/OData.svc/Products$inlinecount=allpages&$top=5&$format=json
Identifies the first 5 Product Entries and
includes a count of the total number of Product Entries.
For OData 4.0, you can read the nextLink annotation embeded in the response. (See example here)
4.5.5 Annotation odata.nextLink The odata.nextLink annotation indicates that a response is only a subset of the requested collection
of entities or collection of entity references. It contains a URL that
allows retrieving the next subset of the requested collection.
If you add &$count=true to your uri the service will include a total count in the response. The json response will include a "#odata.count" property. This property indicates the total number of entities.
That way you can check if you've received all entities.

Syntax for Aggregating a Filtered Dataset in OData v4 Spec using $apply

Suppose I am querying a dataset called Sales with the following schema:
id (int)
price (decimal)
active (bit)
Using the $apply query option and the aggregate transformation of the OData v4 spec, what would be the syntax for finding the average price for only active Sales?
$apply supports both aggregation and filter transformations, but I can't figure out how to combine them or if you're even allowed to do so.
Thanks!
$apply=filter(Status eq 1)/aggregate(price with average as averagePrice)
maybe you can refer the existing test:
https://github.com/OData/WebApi/blob/master/OData/test/E2ETest/WebStack.QA.Test.OData/Aggregation/AggregationTests.cs
https://github.com/OData/WebApi/blob/master/OData/test/UnitTest/System.Web.OData.Test/OData/Query/ApplyQueryOptionTest.cs

How do I get current courses for a user in Desire2Learn's Valence API? What can we do to fetch when courses are in thousands?

We need to find all the courses for a user whose startDate is less than today's date and endDate is greater than today's date. We are using API
/d2l/api/lp/{ver}/enrollments/myenrollments/?orgUnitTypeId=3
In one particular case I have more than 18 thousand courses against one user. The service can not return 18 thousand records at one go, I can only get 100 records at a time, so I need to use bookmark fields to fetch data in set of 100 records. Bookmark is the courseId of the last 100th record that we fetched, to get next set of 100 records.
/d2l/api/lp/{ver}/enrollments/myenrollments/?orgUnitTypeId=3&bookmark=12528
I need to repeat the loop 180 times, which results in "Request time out" error.
I need to filter the record on the basis of startDate and endDate, no sorting criteria is mentioned which can sort the data on the basis of startDate or endDate. Can anyone help me to find out the way to sort these data, or tell any other API which can do such type of sorting?
Note: All the 18 thousand records has property "IsActive":true
Rather than getting to the list of org units by user, you can try getting to the user by the list of org units. You could try using /d2l/api/lp/{ver}/orgstructure/{orgUnitId}/descendants/?ouTypeId={courseOfferingType} to retrieve the entire list of course offering IDs descended from the highest common ancestor known for the user's enrollments. You can then loop through /d2l/api/lp/{ver}/courses/{orgUnitId} to fetch back the course offering info for each one of those org units to pre-filter and cut out all the course offerings you don't care about based on dates. Then, for the ones left, you can check for the user's enrollment in each one of those to figure out which of your smaller set the user matches with.
This will certainly result in more calls to the service, not less, so it only has two advantages I can see:
You should be able to get the entire starting set of course offerings you need off the hop rather than getting it back in pages (although it's entirely possible that this call will get turned into a paging call in the future and the "fetch all the org units at once" nature it currently has deprecated).
If you need to do this entire use-case for more than one user, you can fetch the org structure data once, cache it, and then only do queries for users on the subset of the data.
In the mean time, I think it's totally reasonable to request an enhancement on the enrollments calls to provide better filtering (active/nonactive, start-dates, end-dates, and etc): I suspect that such a request might see more traction than a request to give control to clients over paging (i.e. number of responses in each page frame).

Filter an OData query based on a link count?

Given a structure where two types are exposed in an OData system with a master/detail relationship:
Order
- OrderDetails
How would you filter a query of orders based upon the count of associated OrderDetails? In my head, it's something along the lines of
/Orders$filter=count(OrderDetails) eq 0
But, of course there's no count function. So, how would you produce a list of orders which had no OrderDetails?
Very similar question to this one: Collection Exists Criteria in WCF Data Services
Currently the OData protocol doesn't support any operator/query to do that. The best solution is to expose a service operation which exposes this kind of operation from the server directly.

Resources