Can I check with the Stackoverflow API which SO answerers are sleep-deprived?

前端 未结 1 583
萌比男神i
萌比男神i 2021-02-05 13:32

In how-do-i-access-the-stackoverflow-api-from-mathematica I outlined how one could use the SO API to get Mathematica to make some interesting reputation graphs of top answerers.

1条回答
  •  逝去的感伤
    2021-02-05 14:11

    Certainly, for instance using this MMA8 code:

    getActionDates[userID_Integer] :=
     Module[{total},
      total = 
       "total" /. 
        Import["http://api.stackoverflow.com/1.1/users/" <> 
          ToString[userID] <> "/timeline?pagesize=1&page=1", "JSON"];
      DateList[# + AbsoluteTime["January 1, 1970"]] & /@ Join @@
        Table[
         "creation_date" /. ("user_timelines" /. 
            Import["http://api.stackoverflow.com/1.1/users/" <> 
              ToString[userID] <> "/timeline?pagesize=100&page=" <> 
              ToString[p], "JSON"])
         , {p, Ceiling[total/100]}
         ]
      ]
    
    makeWeekHistogram[userID_Integer] :=
     Module[{dates2Positions},
      dates2Positions = 
       ToExpression[
           DateString[#, {"{", "DayNameShort", "+", "Hour", "+", "Minute",
              "/60./.{Sun->0,Mon->24,Tue->2*24,Wed->3*24,Thu->4*24,Fri->5*\
    24,Sat->6*24}}"}]] & /@ getActionDates[userID] // Flatten; 
      Histogram[dates2Positions, {1}, "Count", 
       GridLines -> {Table[24 i, {i, 1, 6}], None}, 
       BaseStyle -> {FontFamily -> "Arial-Bold", FontSize -> 16}, 
       FrameTicks -> {{Automatic, 
          None}, {{{12, "Sun"}, {24 + 12, "Mon"}, {2 24 + 12, 
            "Tue"}, {3 24 + 12, "Wed"}, {4 24 + 12, "Thu"}, {5 24 + 12, 
            "Fri"}, {6 24 + 12, "Sat"}}, None}}, 
       FrameLabel -> {"Day of week", "Number of actions", 
         First["display_name" /. ("users" /. 
             Import["http://api.stackoverflow.com/1.1/users/" <> 
               ToString[userID], "JSON"])], ""}, Frame -> True, 
       PlotRangePadding -> 0]
      ]
    
       makeDayHistogram[userID_Integer] :=
     Module[{dates2Positions},
      dates2Positions = 
       ToExpression[DateString[#, {"Hour", "+", "Minute", "/60."}]] & /@ 
         getActionDates[userID] // Flatten; 
      Histogram[dates2Positions, {1}, "Count", 
       FrameTicks -> {{Automatic, 
          None}, {Table[{i + 0.5, i}, {i, 0, 20, 5}], None}}, 
       BaseStyle -> {FontFamily -> "Arial-Bold", FontSize -> 16}, 
       FrameLabel -> {"Hour", "Number of actions", 
         First["display_name" /. ("users" /. 
             Import["http://api.stackoverflow.com/1.1/users/" <> 
               ToString[userID], "JSON"])], ""}, Frame -> True, 
       PlotRangePadding -> 0]
      ]
    

    Of course, we only have server time and dates, but the pattern should tell something about localisation, not? Although... Mr.Wizard... you got no life!

    makeWeekHistogram[353410]
    

    enter image description here

    enter image description here

    enter image description here

    EDIT
    Hourly histogram requested by Mr.Wizard:

    enter image description here

    0 讨论(0)
提交回复
热议问题