3

The use case is to generate a list of bug report submissions, grouped by User, of the following counts in descending order:

  • bug
  • bug + status-completed
  • bug + status-deferred
  • bug + status-bydesign
  • bug + status-declined

e.g.

user   bugs   completed   deferred  bydesign   declined
------+------+-----------+---------+----------+----------
joe    10     4            3         1          1
.....

Post your solution to this use case in the language/library syntax of your choice.

4
  • Would you be able to post Soapi.JS examples? I would myself but have limited time on my hands. Commented Aug 16, 2010 at 23:00
  • @geo - i went ahead and posted for the other questions but this one i will wait until tonight. Commented Aug 17, 2010 at 1:04
  • Great! Thanks so much. Completely unrelated, but I would love to collaborate with you on that ActionScript wrapper :) - please let me know when you have the time... I know you're quite busy. Commented Aug 17, 2010 at 2:16
  • @geo - r.e. the AS port: that sounds good. when i get the new js lib done we can start exploring options. Commented Aug 17, 2010 at 17:38

1 Answer 1

1

C# / Soapi.CS


using Soapi.CS


Site site = Context.Official.StackApps;

var bugs = new List<Question>();

// put all questions from all users which
// have tag 'bug'
site.Users.PageSize(100).PageCount(0)   // all users
    .Where(user => user.QuestionCount > 0) // that have q
    .Select(user => user.UserId) // get user_id
    .InBatches(100).ToList() // in batches of 100
    .ForEach(batch =>  
        bugs.AddRange( // q with 'bug' from this batch of 100 users
            site.Users.ById(batch).Questions
            .PageCount(0).PageSize(100)
            .Where(q => q.Tags.Contains("bug"))));


Console.WriteLine("User\t\tTotal\tResolved\rDeferred\tRTFM!\tWRYS");
Console.WriteLine("-----------------------------------------------------------");

// group, sort and dump
bugs.GroupBy(q => q.OwnerId).Select(g => new
    {
        g.First().Owner.DisplayName,
        BugCount = g.Count(),
        Resolved = g.Count(q => q.Tags.Contains("status-completed")),
        Deferred = g.Count(q => q.Tags.Contains("status-deferred")),
        ByDesign = g.Count(q => q.Tags.Contains("status-bydesign")),
        Declined = g.Count(q => q.Tags.Contains("status-declined"))
    }).OrderByDescending(item => item.BugCount)
    .ThenByDescending(item => item.Resolved)
    .ThenByDescending(item => item.Deferred)
    .ThenByDescending(item => item.ByDesign)
    .ThenByDescending(item => item.Declined)
    .ToList().ForEach(item =>
        Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}",
        item.DisplayName, item.BugCount, item.Resolved, item.Deferred,
        item.ByDesign, item.Declined));
    

Output:

User        Total    Resolved Deferred    RTFM!    WRYS
-----------------------------------------------------------
code poet    26    23    0    1    0
George Edison    12    8    0    3    0
systempuntoout    8    5    0    3    0
S.Mark    7    5    0    1    0
Dennis Williamson    6    5    0    1    0
Bill the Lizard    6    4    1    1    0
ColinD    5    5    0    0    0
Felix    4    4    0    0    0
Franci Penov    4    2    1    0    0
carson    3    3    0    0    0
Steffen Opel    3    2    0    0    0
Peter Mourfield    2    2    0    0    0
Jonathan    2    2    0    0    0
jjnguy    1    1    0    0    0
Greg Bray    1    1    0    0    0
mikej    1    1    0    0    0
coobird    1    1    0    0    0
Peter Mortensen    1    1    0    0    0
Bialecki    1    1    0    0    0
Martin Plante    1    1    0    0    0
SztupY    1    1    0    0    0
Adam Wright    1    1    0    0    0
magcius    1    1    0    0    0
Wei Hu    1    1    0    0    0
ADB    1    1    0    0    0
Farseeker    1    0    0    1    0
Matt S.    1    0    0    1    0
radius    1    0    0    1    0
Jedi Master Spooky    1    0    0    1    0
Dave DeLong    1    0    0    1    0
lfoust    1    0    0    1    0
Dave Swersky    1    0    0    1    0
RichOrr    1    0    0    1    0
Can Berk Güder    1    0    0    1    0
Artefacto    1    0    0    1    0
Jim McKeeth    1    0    0    1    0
tonklon    1    0    0    0    0
Portman    1    0    0    0    0
Shay Erlichmen    1    0    0    0    0
Nick Presta    1    0    0    0    0

Requests generated


#   Result  Protocol    Host    URL Body    Caching Content-Type    Process Comments    Custom  
1   200 HTTP    api.stackapps.com   /1.0/users?pagesize=100&key=foo-bar-fu  34,613  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
2   200 HTTP    api.stackapps.com   /1.0/users?page=2&pagesize=100&key=foo-bar-fu   29,504  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
3   200 HTTP    api.stackapps.com   /1.0/users?page=3&pagesize=100&key=foo-bar-fu   25,438  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
4   200 HTTP    api.stackapps.com   /1.0/users?page=4&pagesize=100&key=foo-bar-fu   30,203  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
5   200 HTTP    api.stackapps.com   /1.0/users?page=5&pagesize=100&key=foo-bar-fu   25,295  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
6   200 HTTP    api.stackapps.com   /1.0/users?page=6&pagesize=100&key=foo-bar-fu   27,335  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
7   200 HTTP    api.stackapps.com   /1.0/users?page=7&pagesize=100&key=foo-bar-fu   26,925  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
8   200 HTTP    api.stackapps.com   /1.0/users?page=8&pagesize=100&key=foo-bar-fu   26,285  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
9   200 HTTP    api.stackapps.com   /1.0/users?page=9&pagesize=100&key=foo-bar-fu   24,423  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
10  200 HTTP    api.stackapps.com   /1.0/users?page=10&pagesize=100&key=foo-bar-fu  27,587  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
11  200 HTTP    api.stackapps.com   /1.0/users?page=11&pagesize=100&key=foo-bar-fu  25,370  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
12  200 HTTP    api.stackapps.com   /1.0/users?page=12&pagesize=100&key=foo-bar-fu  27,376  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
13  200 HTTP    api.stackapps.com   /1.0/users?page=13&pagesize=100&key=foo-bar-fu  26,470  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
14  200 HTTP    api.stackapps.com   /1.0/users?page=14&pagesize=100&key=foo-bar-fu  27,049  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
15  200 HTTP    api.stackapps.com   /1.0/users?page=15&pagesize=100&key=foo-bar-fu  25,317  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
16  200 HTTP    api.stackapps.com   /1.0/users?page=16&pagesize=100&key=foo-bar-fu  24,794  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
17  200 HTTP    api.stackapps.com   /1.0/users?page=17&pagesize=100&key=foo-bar-fu  23,604  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
18  200 HTTP    api.stackapps.com   /1.0/users?page=19&pagesize=100&key=foo-bar-fu  25,732  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
19  200 HTTP    api.stackapps.com   /1.0/users?page=18&pagesize=100&key=foo-bar-fu  25,322  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
20  200 HTTP    api.stackapps.com   /1.0/users?page=21&pagesize=100&key=foo-bar-fu  20,903  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
21  200 HTTP    api.stackapps.com   /1.0/users?page=20&pagesize=100&key=foo-bar-fu  24,952  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
22  200 HTTP    api.stackapps.com   /1.0/users?page=22&pagesize=100&key=foo-bar-fu  19,586  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
23  200 HTTP    api.stackapps.com   /1.0/users?page=24&pagesize=100&key=foo-bar-fu  19,628  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
24  200 HTTP    api.stackapps.com   /1.0/users?page=25&pagesize=100&key=foo-bar-fu  21,179  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
25  200 HTTP    api.stackapps.com   /1.0/users?page=23&pagesize=100&key=foo-bar-fu  19,149  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
26  200 HTTP    api.stackapps.com   /1.0/users?page=26&pagesize=100&key=foo-bar-fu  19,142  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
27  200 HTTP    api.stackapps.com   /1.0/users?page=27&pagesize=100&key=foo-bar-fu  22,512  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
28  200 HTTP    api.stackapps.com   /1.0/users?page=28&pagesize=100&key=foo-bar-fu  20,692  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
29  200 HTTP    api.stackapps.com   /1.0/users?page=30&pagesize=100&key=foo-bar-fu  7,239   private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
30  200 HTTP    api.stackapps.com   /1.0/users?page=29&pagesize=100&key=foo-bar-fu  17,528  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
31  200 HTTP    api.stackapps.com   /1.0/users/18;2;14;11;51;23;33;8;448;17;30;43;199;56;40;13;39;29;5;9;19;32;127;28;1026;2894;20;26;52;37;816;825;956;377;1241;570;1290;171;1048;192;700;1265;614;839;431;113;295;222;4;1049;1031;42;1395;186;664;1394;638;1263;939;680;757;358;451;424;1303;449;756;2287;693;938;150;151;234;2192;2296;140;339;91;138;553;375;1174;1221;1978;2442;2883;44;239;109;169;505;2734;1270;525;1578;2083;1942;2203;2300;2118/questions?pagesize=100&key=foo-bar-fu  14,688  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
32  200 HTTP    api.stackapps.com   /1.0/users/18;2;14;11;51;23;33;8;448;17;30;43;199;56;40;13;39;29;5;9;19;32;127;28;1026;2894;20;26;52;37;816;825;956;377;1241;570;1290;171;1048;192;700;1265;614;839;431;113;295;222;4;1049;1031;42;1395;186;664;1394;638;1263;939;680;757;358;451;424;1303;449;756;2287;693;938;150;151;234;2192;2296;140;339;91;138;553;375;1174;1221;1978;2442;2883;44;239;109;169;505;2734;1270;525;1578;2083;1942;2203;2300;2118/questions?page=2&pagesize=100&key=foo-bar-fu   14,521  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
33  200 HTTP    api.stackapps.com   /1.0/users/18;2;14;11;51;23;33;8;448;17;30;43;199;56;40;13;39;29;5;9;19;32;127;28;1026;2894;20;26;52;37;816;825;956;377;1241;570;1290;171;1048;192;700;1265;614;839;431;113;295;222;4;1049;1031;42;1395;186;664;1394;638;1263;939;680;757;358;451;424;1303;449;756;2287;693;938;150;151;234;2192;2296;140;339;91;138;553;375;1174;1221;1978;2442;2883;44;239;109;169;505;2734;1270;525;1578;2083;1942;2203;2300;2118/questions?page=3&pagesize=100&key=foo-bar-fu   14,226  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
34  200 HTTP    api.stackapps.com   /1.0/users/18;2;14;11;51;23;33;8;448;17;30;43;199;56;40;13;39;29;5;9;19;32;127;28;1026;2894;20;26;52;37;816;825;956;377;1241;570;1290;171;1048;192;700;1265;614;839;431;113;295;222;4;1049;1031;42;1395;186;664;1394;638;1263;939;680;757;358;451;424;1303;449;756;2287;693;938;150;151;234;2192;2296;140;339;91;138;553;375;1174;1221;1978;2442;2883;44;239;109;169;505;2734;1270;525;1578;2083;1942;2203;2300;2118/questions?page=4&pagesize=100&key=foo-bar-fu   14,146  private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
35  200 HTTP    api.stackapps.com   /1.0/users/18;2;14;11;51;23;33;8;448;17;30;43;199;56;40;13;39;29;5;9;19;32;127;28;1026;2894;20;26;52;37;816;825;956;377;1241;570;1290;171;1048;192;700;1265;614;839;431;113;295;222;4;1049;1031;42;1395;186;664;1394;638;1263;939;680;757;358;451;424;1303;449;756;2287;693;938;150;151;234;2192;2296;140;339;91;138;553;375;1174;1221;1978;2442;2883;44;239;109;169;505;2734;1270;525;1578;2083;1942;2203;2300;2118/questions?page=5&pagesize=100&key=foo-bar-fu   9,958   private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
36  200 HTTP    api.stackapps.com   /1.0/users/298;1177;1179;1911;2134;2618;636;1856;1986;2679;267;1771;705;1230;1339;1416;2139;2951;587;168;216;1097;892;2532;2616;2222;866;1304;2829;2517;2662;1384;1711;1918;2603;564;1044;2125;1924;1849;1232;667;2418;2467;70;2292;1009;1689;1749;1676;2735/questions?pagesize=100&key=foo-bar-fu  8,925   private     application/json; charset=utf-8 jetbrains.resharper.taskrunner.msil:3848            
     

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .