groupBy multiple

Oct 30, 2013 at 8:49 AM
Edited Oct 30, 2013 at 8:51 AM
Hello. I like your project. It's good! I have some problem of groupby
I have json object
[{"day":30,"week":40,"year":2013,"month":9,
"users":
[{"uid":"eab94452-46ad-4906-8e82-336af58b98e9","FIO":"FIO1","times":21300,"id":9152},      {"uid":"c420058a-9ee3-414c-8aa9-fa001f60455f","FIO":"FIO2","times":16500,"id":9077},{"uid":"dfec73c3-7ad2-4dfa-ab63-a54c673a01dd","FIO":"FIO2","times":2700,"id":8953}]},{"day":1,"week":40,"year":2013,"month":10,"
users":
[{"uid":"9ebf7d10-7cba-4f7d-8cca-53287ab1fa03","FIO":"FIO1","times":33900,"id":9193},{"uid":"1e529eb9-4516-4867-af6b-7c4640ea138d","FIO":"FIO1","times":12600,"id":8615},{"uid":"62230d7b-a0a5-40d4-be47-16a7a6bac200","FIO":"FIO2", "id":8953}]}]
I want to group by month, then inside query users group by FIO.

I create query
var list = $linq(jobjects).groupBy(function (m) { return months[m.month] + ' ' + m.year; }, "w => w.users").select(
        function (x) {
            return {
                type: '3',
                title: x.key,
                users: $linq(x.values).groupBy("s => s.FIO", "s=>s.times").select(
                       function (s) { return { FIO: s.key, times: $linq(s.values).sum("w=>w") } }
                ).toArray()
            };
        }).toArray();
}})}}

).ToArray();
But I don't get that what i want.
Please, can you help me.
Oct 30, 2013 at 11:06 AM
I've done
var list = $linq(jobjects).groupBy(function (m) { return months[m.month] + ' ' + m.year; }, "w => w.users").select(
        function (x) {
            var arrayusers = new Array();
            $linq(x.values).foreach(function (u) { arrayusers = arrayusers.concat(u) });
            return {
                type: '3',
                title: x.key,
                users: $linq(arrayusers).groupBy("w => w.FIO", "w => w.times").select(function(t) {return {FIO:t.key, times:$linq(t.values).sum("s=>s")}}).toArray()
            };
        }).toArray();
Coordinator
Oct 30, 2013 at 5:49 PM
Another way of expressing this linq query is to use:
var list = $linq(jobjects).groupBy(function (m) { return months[m.month] + ' ' + m.year; }, "w => w.users").select(
    function (x) {
        return {
            type: '3',
            title: x.key,
            users: $linq(x.values)
                .selectMany("u => u")
                .groupBy("w => w.FIO", "w => w.times")
                .select(function(t) {return {FIO:t.key, times:$linq(t.values).sum("s=>s")}}).toArray()
        };
    }).toArray();
This uses "selectMany" in place of the building of the "arrayusers" array.
Oct 31, 2013 at 8:52 AM
Thanks a lot!