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?
Asked
Active
Viewed 478 times
15
-
Only for those users of which you know (and trust) the location. – R. Martinho Fernandes May 01 '11 at 00:04
-
1... and their current level of rest. :) I don't think there's and API for tapping the person's brain, but I hear Google and Apple are partnering to build one. – jefflunt May 01 '11 at 00:06
-
hahaha, my graph is going to be special. ::grin:: – Mr.Wizard May 01 '11 at 00:35
-
1@Mr.Wizard It looks like you have about two hours sleep per day. I guess a collective of writers hides behind your name. Or is Mr.Wizard = Dr.Jekyll and Mr.Hyde? – Sjoerd C. de Vries May 01 '11 at 01:01
1 Answers
13
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]
EDIT
Hourly histogram requested by Mr.Wizard:

Sjoerd C. de Vries
- 16,122
- 3
- 42
- 94
-
2
-
I don't speak Mathematica or SO API. What did you graph? Question and answer and comment creation and edition counts? – R. Martinho Fernandes May 01 '11 at 00:11
-
@Martinho I counted what's in the user timelines: posts, edits, comments or so. I haven't filtered anything (probably should do that as badges earned are in there as well). API: http://api.stackoverflow.com/1.1/usage/methods/user-timelines – Sjoerd C. de Vries May 01 '11 at 00:17
-
Sjoerd, do one that shows only hours of the day (all week days merged) for me, please. – Mr.Wizard May 01 '11 at 00:37
-
By the way, I *did* warn you: "Don't try to figure out what time zone I am on, it will only confound you." – Mr.Wizard May 01 '11 at 00:44
-
3
-
-
@Mr.Wizard Done. Yeah, you triggered me with that remark. Anyway, I'll sign-off now. It's 3 am in my TZ. – Sjoerd C. de Vries May 01 '11 at 00:57
-
1@yoda In http://stackoverflow.com/questions/5745298/how-do-i-access-the-stackoverflow-api-from-mathematica I provide a bare bones MMA 7 Import for JSON formats. I'm off to bed now. – Sjoerd C. de Vries May 01 '11 at 01:03