Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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. Could this API also be used to provide some privacy-invading insights in the answerers' nocturnal habits?

like image 313
Sjoerd C. de Vries Avatar asked May 01 '11 00:05

Sjoerd C. de Vries


1 Answers

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

like image 177
Sjoerd C. de Vries Avatar answered Oct 31 '22 07:10

Sjoerd C. de Vries