{"id":4785,"date":"2017-03-10T14:19:34","date_gmt":"2017-03-10T14:19:34","guid":{"rendered":"http:\/\/www.dyalog.com\/blog\/?p=4785"},"modified":"2017-03-10T14:19:34","modified_gmt":"2017-03-10T14:19:34","slug":"charting-reaction-times-on-the-raspberry-pi","status":"publish","type":"post","link":"https:\/\/www.dyalog.com\/blog\/2017\/03\/charting-reaction-times-on-the-raspberry-pi\/","title":{"rendered":"Charting Reaction Times on the Raspberry Pi"},"content":{"rendered":"<p>Earlier this week I <a title=\"micro:bit Reaction Timer in APL on the Pi and BBC micro:bit\" href=\"http:\/\/www.dyalog.com\/blog\/2017\/03\/microbit-reaction-timer-in-apl-on-the-pi-and-bbc-microbit\/\">collected some reaction timer data on my Pi using the BBC micro:bit as an input device<\/a>. I only produced an &#8220;ASCII art&#8221; chart at the time:<\/p>\n<pre><code class=\" language-apl\">\u00a0 \u00a0 \u00a0 times\u2190ReactionTimer.Play\r\n      times\r\n251 305 294 415 338 298 294 251 378\r\n      ReactionTimer.AsciiChart times\r\n425| \r\n400|    * \r\n375|         *\r\n350+ \r\n325|     * \r\n300|  * \r\n275|   *  ** \r\n250+ *      * \r\n<\/code><\/pre>\n<p>Retro is back in style \u2013 but of course I should point out that we can produce &#8220;proper&#8221; graphics using <a href=\"http:\/\/www.sharpplot.com\" target=\"_blank\">SharpPlot<\/a>, a cross-platform graphics package that is included with Dyalog APL on all platforms. I&#8217;ve enhanced the <code>ReactionTimer<\/code> namespace with a function called <code>SPHistogram<\/code>. If you are using RIDE as the front end to APL on the Pi, this will render output from SharpPlot in a window:<\/p>\n<pre><code class=\" language-apl\">    ReactionTimer.SPHistogram times<\/code><\/pre>\n<p><a href=\"http:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2017\/03\/SPReactionTimes.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-4786 size-full\" src=\"http:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2017\/03\/SPReactionTimes.png\" alt=\"Reaction Time Histogram\" width=\"786\" height=\"493\" \/><\/a><\/p>\n<p>The original ASCII chart simply plotted the observations in the order that they occurred. Above, the shaded areas show how many observations there were in each bucket (2 between 250ms and 275ms, 3 between 275ms and 300ms, and so on). At the same time, the individual observations can be seen along the X axis as vertical red lines. It is a little unfortunate\u00a0that, presumably due to some artifact of the timing process, the values 251 and 294 occur twice &#8211; and these lines are drawn on top of each other.<\/p>\n<p>The example highlights one of the things that makes SharpPlot a bit special: We have overlaid a histogram showing the frequency of reactions in each bucket, and used a &#8220;scatterplot&#8221; to where the Y value is always 0, to mark the individual observations along the X axis.<\/p>\n<pre><code class=\" language-apl\">     \u2207 SPHistogram times;heading;renderHtml;sp;svg;z \r\n[1]   heading\u2190'Reaction Times' \r\n[2]   renderHtml\u21903500\u2336 \u235d Render HTML in Window \r\n[3] \r\n[4]   :If 0=\u2395NC'#.SharpPlot' \u22c4 #.\u2395CY'sharpplot.dws' \u22c4 :EndIf\r\n[5] \r\n[6]   sp\u2190\u2395NEW #.SharpPlot(432 250) \r\n[7]   sp.Heading\u2190heading \r\n[8] \r\n[9]   \u235d Draw histogram \r\n[10]  sp.ClassInterval\u219025 \r\n[11]  sp.SetXTickMarks 25 \r\n[12]  sp.HistogramStyle\u2190#.HistogramStyles.SurfaceShading \r\n[13]  sp.SetFillStyles #.FillStyle.Opacity30 \r\n[14]  sp.DrawHistogram\u2282times \r\n[15] \r\n[16]  \u235d Add observations using ScatterPlot \r\n[17]  sp.SetMarkers #.Marker.UpTick \r\n[18]  sp.SetPenWidths 1 \r\n[19]  sp.SetMarkerScales 3 \r\n[20]  sp.DrawScatterPlot(times\u00d70)(times) \r\n[21] \r\n[22]  \u235d Render SVG and display in window \r\n[23]  svg\u2190sp.RenderSvg #.SvgMode.FixedAspect \r\n[24]  z\u2190heading renderHtml svg \r\n     \u2207 \r\n<\/code><\/pre>\n<p>Hopefully the code is more or less self-explanatory, but if you&#8217;d like to learn more about SharpPlot there is excellent documentation at <a href=\"http:\/\/www.sharpplot.com\" target=\"_blank\">http:\/\/sharpplot.com<\/a>. The documentation is actually written for C# users, but there is an illustration of how to translate the documentation to APL (and VB) at\u00a0<a href=\"http:\/\/www.sharpplot.com\/Languages.htm\" target=\"_blank\">http:\/\/www.sharpplot.com\/Languages.htm<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Earlier this week I collected some reaction timer data on my Pi using the BBC micro:bit as an input device. I only produced an &#8220;ASCII art&#8221; chart at the time: \u00a0 \u00a0 \u00a0 times\u2190ReactionTimer.Play times 251 305 294 415 338 &hellip; <a href=\"https:\/\/www.dyalog.com\/blog\/2017\/03\/charting-reaction-times-on-the-raspberry-pi\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,8,27,9,31],"tags":[],"class_list":["post-4785","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-apl-language","category-cxo","category-raspberry-pi","category-sharpplot"],"_links":{"self":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/4785","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/comments?post=4785"}],"version-history":[{"count":14,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/4785\/revisions"}],"predecessor-version":[{"id":4813,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/4785\/revisions\/4813"}],"wp:attachment":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/media?parent=4785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/categories?post=4785"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/tags?post=4785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}