Skip to content

Posts from the ‘Development’ Category

10
Aug

Updates on Piston

About a year ago, I wrote a little about why I’m not using Piston. Piston appears to be dead! There hasn’t been a commit since September which is almost a full year ago. This project was touted as “the way” to do REST APIs in Django and I’m sad that it doesn’t seem to be maintained. I saw some other forks of the project on Github, but there still doesn’t seem to be much work on it lately. Does anybody know what happened?

23
Jul

Sparklines in D3

A couple weeks ago, Protovis, a visualization library I’d been using was deprecated in favor of D3 and I thought I’d share some of the work I’d done porting visualizations from the old to the new.

One example that Protovis has for which there is no corresponding tutorial is sparklines. This sparkline shows the San Diego Padres’ first 100 games of the 2011 season. Up ticks are wins and down ticks are losses. Red ticks show shutouts. This is similar to the visualization in Tufte’s “Beautiful Evidence” p. 54.

d3.json("padres.json", function(json) {
    var h = 16,
        w = json.length * 2;
    var svg = d3.select("#sparktick")
                .append("svg:svg")
                .attr("height", h)
                .attr("width", w);

    var node = svg.selectAll("g.tick")
                  .data(json)
                  .enter().append("svg:g")
                          .attr("class", "tick");
    node.append("svg:rect")
        .attr("class", function(d) { return d['RF'] == 0 || d['RA'] == 0?"shutout":"normal"; })
        .attr("x", function(d, i) { return i * 2 + 1; })
        .attr("y", function(d) { return d['RF'] > d['RA']?0:h/2; })
        .attr("height", h/2)
        .attr("width", 1);
    node.append("svg:title")
        .text(function (d) { return d['Team'] + " (" + d['RF'] + ") " + (d['Away']?"vs":"@") + " " + d['Opp'] + " (" + d['RA'] + ") on " + d['Date']; })
});

I created another simple visualization for the National League West. This shows all five teams of the NL West on a single graphic. It is pretty easy to adapt this code to a single sparkline. So far I have been fairly pleased with D3′s performance and the ease of use.

d3.json("nlwest.json", function(json) {
    // calculate max and min values in the NLWest data
    var max=0, min=0, len=0;
    for(var team in json) {
        min = d3.min([d3.min(json[team]), min]);
        max = d3.max([d3.max(json[team]), max]);
        len = d3.max([json[team].length, len]);
    }

    var h = 50,
        w = 250,
        p = 2,
        fill = d3.scale.category10()
        x = d3.scale.linear().domain([0, len]).range([p, w - p]),
        y = d3.scale.linear().domain([min, max]).range([h - p, p]),
        line = d3.svg.line()
                     .x(function(d, i) { return x(i); })
                     .y(function(d) { return y(d); });

    var svg = d3.select("#sparkline")
                .append("svg:svg")
                .attr("height", h)
                .attr("width", w);

    for(var team in json) {
        var g = svg.append("svg:g");
        g.append("svg:path")
         .attr("d", line(json[team]))
         .attr("stroke", function(d) { return fill(team); })
         .attr("class", "team");
        g.append("svg:title")
         .text(team);
    }
});
19
Jul

Django logging and sentry

Django-sentry has been a fairly useful tool for me. The docs are good but they only talk about integrating with logging the old way.

Here’s how to use Sentry with logging dictionary config:

LOGGING = {
    'version': 1,
    'formatters': {
        'verbose': {
            'format': '%(asctime)s %(levelname)-8s [%(name)s] -- %(message)s'
        },
    },
    'handlers': {
        //...
        'sentry': {
            'level': 'WARNING',
            'class': 'sentry.client.handlers.SentryHandler',
            'formatter': 'verbose',
        },
    },
    'loggers': {
        // ...
        'root': {
            'handlers': ['sentry'],
            'level': 'WARNING',
        },
    }
}
10
Jul

RPC4Django 0.1.9 is now available

Go get it!

Here are the changes:

  • Added a CookieTransport class with a lot of help from Douglas Peter Sculley.
  • RPC4Django’s logging now goes to the rpc4django logger.
  • Catches an ExpatError in xmlrpclib that was previously uncaught under certain conditions
  • Fixed error with scanning of INSTALLED_APPS for @rpcmethods. This was causing an issue when South was installed. (#807628)
  • Fixed bug #807653 related to scanning ServerProxy objects
30
Jun

The Nearly Perfect Package

Most of the time when I’m looking around for a package to do what I need, I find something that does maybe 60% of it. I hack the rest of the functionality into it or I use it as a guideline in a more specialized package. I was extremely impressed with Django-tables2. It does literally 100% of what I needed. I was talking to a buddy of mine and I said the real test is whether I can rip out my existing table infrastructure and replace it with this in 45 minutes. I did and I had about 10 minutes to spare. If you have a lot of data to present, I recommend this over any of the Javascript libraries out there.