All posts by Neil

WSOP Update

Been out in Vegas for a week, played three WSOP events: the shootout, the “turbo” (still has 30 minute levels), and a regular NLHE. Ran well; got third on my table at the shootout (which isn’t in the money – only first is), and min-cashed the other two.

Back to Austin for a break; then next up: WSOP Seniors June 19th.

Showing off with shell “nr” (NumerousApp) command

I wrote some scripts demonstrating what you can do with all the bits and pieces I have now for manipulating NumerousApp metrics from python and shell.

In particular, I was interested in finding the maximum value of one of my metrics:3626358291300704487 (this is the actual NumerousApp metric ID)

I have already installed the python numerous client library and the corresponding shell command “nr” that goes with it (see the github page for details). I also already have my NUMEROUSAPIKEY environment variable set and exported. With all that in place I can read the current value of the metric from a shell prompt like this:

% nr 3626358291300704487

I can read the event stream with the “-E” option:

% nr -E 3626358291300704487

Each line of that output is a (somewhat) human-readable display of a value update event on the metric and looks something like this:

4 @ 2015-05-27T20:12:09.375Z by 9310717522265
3 @ 2015-05-27T19:12:09.348Z by 9310717522265 
2 @ 2015-05-27T18:12:09.207Z by 9310717522265 
1 @ 2015-05-27T17:12:09.373Z by 9310717522265 
0 @ 2015-05-27T15:42:11.373Z by 9310717522265 
518 @ 2015-05-27T14:42:09.254Z by 9310717522265 
517 @ 2015-05-27T13:42:09.116Z by 9310717522265 
516 @ 2015-05-27T12:42:09.317Z by 9310717522265 ...

Rather than parse that output I can ask the “nr” command to only print the value field for each of the events:

% nr -E '3626358291300704487[value]'

From there it’s a simple task to write an awk script that will display the maximum found on stdin:

awk 'BEGIN {max=-999999999} {if ($1>max) {max=$1}} END {print max}'

NOTE: In my script the awk command is all on one line. It’s likely showing up in your browser broken into multiple lines; you need to be careful about those line breaks if you are cutting and pasting this example from your browser display.

That script returns the wrong result if all the input values are negative and below the initial value in the BEGIN statement, so you could do it this way if you prefer:

awk 'BEGIN {max="NOTHING"} {if (max=="NOTHING") max = $1; if ($1>max) {max=$1}} END {print max}'

Again be wary of poorly-located line breaks in your browser display if you copy/paste this.

Given those pieces, finding the max value is a simple pipeline:

% nr -E '3626358291300704487[value]' |
awk 'BEGIN {max="NOTHING"} {if (max=="NOTHING") max = $1; if ($1>max) {max=$1}} END {print max}'

Pretty cool, or maybe somewhat demented.

Sometimes you might not have awk (some linux distributions don’t install it by default), so you could also compute the max with a python program. We know python is on the machine or none of this works, so here’s a version using a python program for the max:

MAXPGM="import sys
maxv = None
for x in sys.stdin:
    try:
        xval = int(x)
    except ValueError:
        xval = float(x)
    if maxv is None or xval > maxv:
       maxv = xval

print(maxv)
"

nr -E '3626358291300704487[value]' | python -c "$MAXPGM"

Making this a script with more general options is left as an exercise for the reader.

Of course if we are going  to the trouble of writing a python program we might want to go ahead and write the entire script in python, which might arguably have been simpler. But, this example notwithstanding, it’s still fun to hack around and see how many powerful things you can do with the “nr” command and some shell.

NumerousApp Server API Performance

I added yet another numerous metric, this time tracking the performance of the NumerousApp server itself:  http://n.numerousapp.com/m/1dlt3ykfq5vqs

It’s measured using this python code:

import numerous

nr = numerous.Numerous()
nr.user()
nr.user()

t = nr.statistics['serverResponseTimes']
print (int(t*10000)/10.0)"

 which is using my NumerousApp Python library (“pip install numerous”).

I just make two user() API calls (discarding the returned info), then dig into the statistics array provided in the object to get the most recent server response time (measured as “on-the-wire” time). The reason for doing two calls is connection overhead; the first call will be significantly slower because it has to perform a TCP connect and an initial SSL setup; the second call reuses the connection (HTTP keep-alive) and is much faster. The numbers are typically around 300msec for the first API call and 60-70msec for subsequent calls (also varies substantially depending on the particular API).

The single response time in ‘statistics’ is the time from the most recent (i.e., second) nr.user() call. The int and 10000/10.0 hack is just to convert the fractional seconds in milliseconds down to tenths (truncated, not rounded … sue me).

NumerousApp libraries updated

Newest versions of my NumerousApp API bindings for python and ruby are released. Now includes support for the new fine-grained permissions server APIs.

PYTHON details:

RUBY details:

NumerousApp overview: www.numerousapp.com

API: http://docs.numerous.apiary.io/

Friday the 13th and NumerousApp

I made a new NumerousApp metric that will tell you when the next Friday the 13th is: http://n.numerousapp.com/m/1w4c4tk4uh29j

Nerd info: I wrote this brute-force python program to find the next Friday the 13th:

from datetime import datetime, date

dt = datetime.now()
while dt.day != 13 or dt.weekday() != 4:
    dt = date.fromordinal(dt.toordinal()+1)

It gets today via  datetime.now()and loops until it is a Friday and a 13th. The weekday() method returns 0 .. 6 with Monday as 0; hence Friday is 4. If “dt” isn’t a Friday the 13th, I just bump it to the next day. The toordinal() method converts a date into a number of days since some arbitrary long-ago time. So I do that, add one, and convert back to a date to get the next day.

I didn’t optimize this algorithm because it just doesn’t matter. I could have added code to compute exactly how many days to add to get to the next 13th and then just test if that is a Friday. Even more generally we could write an algorithm that would directly compute when the next Friday the 13th is (has to take month lengths and leap years into account).

But: We know that at most we’ll have to iterate no more than a few hundred times because every year has at least one Friday the 13th (proving this is left as an exercise for the reader). Speed just doesn’t matter here at all and this works and it is simple.

Once a night I run the above code and use my python NumerousApp API class to update the metric. This too could have been optimized; there’s no reason to run the code at all except on a 13th (indeed, except on a Friday the 13th) but it was just easier to stick it into my nightly updates I do for my other metrics.

Newest versions of NumerousApp API class libraries

As I wrote earlier, I have created Python and Ruby class libraries for the NumerousApp APIs. I’ve recently made a bunch of updates; the newest versions are:

And, as always, github repos: https://github.com/outofmbufs/

Ignore / Enjoy.

Arduino Data Monitor Program

Finally got around to uploading (to github) and documenting my Arduino program for monitoring analog inputs. It’s pretty cool; it:

  • Keeps a ring-buffer of readings and allows you to see what your monitored input has been doing over time.
  • Implements a web server – you can access the readings with your web browser.
  • Has a JSON interface
  • Can be used to provide network-accessible analog input readings.

Documentation: https://github.com/outofmbufs/arduino-datamon/wiki and of course source code on github too.

I’m using it with a simple circuit: a pull-up resistor (one side attached to +5V) and a photo-resistor (one side attached to the pull-up, the other to ground). This is a simple voltage divider and the voltage you will read at the midpoint will depend on how much light is hitting the sensors. I made four of these to monitor several different indicator lights on equipment in my house, as well as the basement area lights. I determined the appropriate resistor values experimentally; the behavior of the photo-resistor depends quite a bit on how much light hits it and thus how much of a difference it sees between “on” and “off”.

I hooked four of these simple circuits up to my Arduino and I use this data monitor code to record the readings. I can also get real-time readings. For example, right now I can tell that my basement area lights are on (I know there are workers doing maintenance today) because when I surf to http://monitor/v2 I get:

pin 2 value 401 @ 454619317

(“monitor” is the hostname of my arduino on my network). Granted, to interpret this I had to know that pin 2 (the “2” in the “v2″ part of the URL) is the basement light sensor pin and I had to know that values below about 800 means the basement lights are on. (pin 2 is connected to the photo-resistor monitoring basement lighting). Of course I’ve also written a small status program that shows me this in English. If I surf that web page (which runs a CGI script that queries the monitor and returns human-readable results):

Lights:

Basement: ON for 3.2 hours
Server Room: OFF for 5.3 days

Code for the arduino monitor on github as already mentioned: https://github.com/outofmbufs/arduino-datamon/