Skip to content

Commit

Permalink
Fix for TotalSummary
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael-hettich committed Sep 28, 2023
1 parent 7268941 commit 9f57bfa
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions Core.Arango.DevExtreme/ArangoTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,53 @@ public async Task<DxLoadResult> ExecuteAsync<T>(IArangoContext arango,

var query = queryBuilder.ToString();


if (HasGrouping)
{
var res = await arango.Query.ExecuteAsync<JObject>(handle, query, Parameter,
cancellationToken: cancellationToken);

var groupData = BuildGrouping(this, res);

return new DxLoadResult
var dxRes = new DxLoadResult
{
Data = groupData,
// Experimental
TotalCount = _loadOption.RequireTotalCount ? groupData.Sum(x=> x.Count ?? 0) : -1,
GroupCount = _loadOption.RequireGroupCount ? groupData.Count : -1,
};

if (_loadOption.TotalSummary?.Any() == true)
{
dxRes.Summary = Summaries.Select((x, idx) =>
{
try
{

if (x.StartsWith("SUM") || x.StartsWith("COUNT"))
return groupData.Sum(y => y.Summary[idx] ?? 0m);
if (x.StartsWith("MAX"))
return groupData.Max(y => y.Summary[idx] ?? 0m);
if (x.StartsWith("MIN"))
return groupData.Min(y => y.Summary[idx] ?? 0m);
if (x.StartsWith("AVG"))
{
return groupData.Average(y => (y.Summary[idx] ?? 0m));
}


return 0m;
}
catch (Exception)
{
return (decimal?) 0m;
}
}).ToArray();


}


return dxRes;
}
else
{
Expand Down

0 comments on commit 9f57bfa

Please sign in to comment.