Updates to my Live Traffic Page
New IP to Location Database
- I replaced the WIPmainia database with the GeoLite City one that Richard Lawley recommended. For some IP's it can potentially provide location information down to Region/City/Postal Code level (and its still free). teebot raised a good question about the accuracy of these free IP to Location databases. The GeoLite web site claims it's database is over 99.3% accurate on a country level and 76% on a city level for the US. Not too bad ...
Using ASP.NET to Simulate a Windows Service
- Decoding an IP address to a location isn't an instantaneous operation. And I have a feeling as I build out the rest dimensions for my Visit/PageView cube it would be nice to run some of the data scrubbing processes some where other than my home PC (right now I have a scheduled task that runs a console app every 30 minutes or so) So I tried out Omar Al Zabir's technique Simulating a Windows Service using ASP.NET.
Here is how it works:
- As visitors navigate through mattberseth.com and mattberseth2.com the raw pageview data is persisted into a table in a database that DiscountASP is hosting for me.
- Within my livetraffic site (again, hosted out on DiscountASP's servers), I am using Omar's technique to wire a bit of code that needs to be run every minute or so. This bit of code fetches the next batch of un-decoded IP's from my pageview table, converts the IP address to an IP number, and bounces it against the IP to Location database.
- After the record is decoded I keep it in memory so its available for my web service that feeds my live traffic grid.
If this works well enough (and it seems to so far) I think might consider off-loading all of the cube related data scrubbing operations.
Now wouldn't that be a cool VS web site template. File -> Add -> New -> ASP.NET Service. Fill in the web.config with the schedule and a pointer to the function to call, maybe an admin page to monitor the services health ...
Fixed a Terribly Embarrassing Bug that was Causing Incorrect IP Address to IP Number Conversion
- This is pretty embarrassing, but when converting the IP address to an IP number I was doing integer arithmetic when I should have been using longs - causing the IP numbers to overflow. I didn't catch it because my home IP decoded correctly. Below is an example that shows what I was doing wrong ...
Real-time Popular Now Link Listing
- I am planning to do some minor tweaking to my blog over the next few weeks. One of the changes I am thinking about implementing is replacing my existing Popular widget (the links there are all static) with one that leverages my PageView database to display the links that really are the most popular (at least in the last 24 hours or so). So I added a new web method that retrieves the 20 most visited links from both mattberseth.com and mattberseth2.com.
Here are a couple of screen shots of what it looks like right now. I have to admit that I am getting tired of my blogs orange theme so I kicking around some other ideas here too.
- Rick Strahl has a gem of a tip in his recent article about client side templates with jQuery. He noted that you can store the jTemplate inline with your page by placing it in a <script type='text/html'> tag. That's a nice tip for a template that you only plan on using once - or for a demo/test page like my live traffic one. So I moved my jTemplate to an inline script tag like so ...
jTemplate Foreach Set Variables
- And finally, in the previous version of my page I was running my data through the template, then going in after the fact and reapply a css class to the alternating rows ...
Well, I looked through jTemplate to see if there was any way I could include adding this class into the template. Well, it turns out you can. jTemplate has a handful of set variables that can help you with stuff like this. Here is the list of set variables ...
$index- index of element in table
$iteration- id of iteration (next number begin from 0)
$first- is first iteration?
$last- is last iteration?
$total- total number of iterations
$key- key in object (name of element) (0.6.0+)
$typeof- type of element (0.6.0+)
And here is how I am making use of the $iteration variable from within my template to add the odd css class ...
That's it. Enjoy!