Comparing Today to Yesterday

This is output from a script I cooked up for comparing today’s visitor counts to yesterday’s. The idea is to see if the counts are in line with normal activity: Hourly counts that went low would mean something wrong with the web site. High counts, which happen occasionally, mean that someone gave Entrance a plug somewhere.

(This chart was made a little after 9 AM this morning, so the red bar for 9 is low representing an incomplete count)

To ensure that any 0 counts show up, I include a LEFT JOIN with a table containing the values 0-23. SKINNY makes the second set of bars 1/3 the width of the first set. Here’s the complete script:

-- hours 0 - 23
create temporary table hours_t
    (h int, today int, yesterday int);

insert into hours_t(h) values
    (0), (1), (2), (3), (4), (5), (6), (7), (8),
    (9), (10), (11), (12), (13), (14), (15), (16),
    (17), (18), (19), (20), (21), (22), (23);

create temporary table today_t
    select h, count(distinct ip) c
      from ACCESS
      where day(dtime) = day(curdate())
      group by h;

create temporary table yesterday_t
    select h, count(distinct ip) c2
      from ACCESS
      where date(dtime) =
        date(date_sub(curdate(), interval 1 day))
      group by h;

plot
    all axislabels, very light blue bar, light red bar
    with
      no sides
      baroverlap 1
      skinny
      comment left "Number of Visitors"
      title x "Hour of Day"
select hours_t.h, c2, c
    from (hours_t LEFT JOIN today_t
    on hours_t.h = today_t.h) LEFT JOIN
    yesterday_t
    on hours_t.h = yesterday_t.h;

With a similar technique, you could compare this months performance to last months, or days in this weeks to last weeks, etc.

Comments are closed.