Removing Outliers in a SQL Server Query

At the risk of getting too geeky, I figured I’d share a cool query that I put together to remove outliers when acting on a dataset.  It’s nothing too special and certainly not doing anything new mathematically, but I’ve never had to do it within a single query before.  It came together nicely and figured I’d share if anyone else needs to do something similar.

The query below will get the average weight from a fictional Scale table holding a single weigh-in for each person while not permitting those who are overly fat or thin to throw off the more realistic average:

  select w.Gender, Avg(w.Weight) as AvgWeight
    from ScaleData w
    join ( select d.Gender, Avg(d.Weight) as AvgWeight, 
                  2*STDDEVP(d.Weight) StdDeviation
             from ScaleData d
            group by d.Gender
         ) d
      on w.Gender = d.Gender
     and w.Weight between d.AvgWeight-d.StdDeviation 
                      and d.AvgWeight+d.StdDeviation
   group by w.Gender  

There may be a better way to go about this, but it works and works well.  If you have come across another more efficient solution, I’d love to hear about it.

NOTE: the above removes the top and bottom 5% of outliers out of the picture for purpose of the Average. You can adjust the number of outliers removed by adjusting the 2* in the 2*STDDEVP as per: http://en.wikipedia.org/wiki/Standard_deviation

Special thanks to buddies Komeh and Victor for the help in figuring this out.

Bookmark and Share
Comments (View)

Video of the Day

The most important video you will watch this year.

I know the year only began, but I guarantee that this video will change the way you think about technology, the internet, your government and where we head in the future.

Bookmark and Share
Comments (View)

SQL Server Pricing

I find SQL Server pricing to be very disturbing.

SQL Server Express is free for databases up to 4GB in size.  That’s fine and all, but think about this…  If you have a database that will grow to 24GB in size, it is actually cheaper to split your data in 4GB chunks across 6 rackmount servers (including purchasing new hardware) than it is to upgrade to a version of SQL Server than can handle the data.

Hey Microsoft, how about a version of SQL Server that is within range of us small business and hobbyist coders out here?  And is database size really the differentiator that you should be using to force people to upgrade?

I understand limiting the amount of RAM in use by SQL Server and even the number of cores that will be used by the free version, but it’s pretty easy to pass 4GB of data. In fact, I think the limitation is darn near unreasonable.

I thought I had found a great solution to the problem.  Microsoft’s website explains a product called SQL Server Web Edition which is priced at $15 per proc per month.  Unfortunately, a call to Microsoft clarified that since I own the server, that price is not available to me.  It can only be purchased as part of a hosting plan from a qualified web hosting service.  Seriously Microsoft?  Seriously???

I’d be happy to pay something reasonable on a subscription plan if it removed the restrictions and provided some sort of SLA with it.  Unfortunately, MS doesn’t want my money unless they get a whole bunch of it.

Guess it’s time to upgrade to MySQL, PostgreSQL or Firebird.

Bookmark and Share
Comments (View)

My Recommended DROID apps

I’ve been using Android for over a year now, first with the G1 on TMobile and now with the DROID on Verizon.  A big part of the Android experience is in the apps.  I figured I’d write up a list of my favorite Android apps.  They are in alphabetical order, so no preference is to be inferred by the numbering.

  1. AK Notepad - Simply the best notepad app for the Android.  Quick, simple, configurable and the data can be easily backed up and restored. - Free
  2. AndroZip - A great file unzip utility. - Free
  3. Better Keyboard - A great replacement for the built in keyboard.  Searching for this in the market is tough because of all of the skins, so look for the publisher “Better Android” - Paid but inexpensive.
  4. Bubble Level -  The best bubble level app out there for Android. - Free
  5. Google Voice - Absolutely fantasic integration with your Google Voice number… just wish it integrated better with SMS, at least as well as it does with the phone app. - Free
  6. Linda File Manager - A great file manager for your phone.  The real reason to get this (or most any file manager) is that it permits you to download file types not registered with Android from the browser.  A must have. - Free
  7. Listen - The best podcast catcher in the market. - Free
  8. NewsRob - A terrific rss newsreader that syncs perfectly with Google Reader.  You will never miss a news article or spend time rereading through crap you’ve already read or skipped. - Paid but inexpensive.
  9. PicUp - A great picture uploader.  Makes sending photos to Flickr, Twitter or Facebook extremely easy. - Paid but inexpensive
  10. Qik - Send live video streams to your website from your phone’s camera.  Awesome.  - Free
  11. Remote Desktop - This app from Xtralogic is simply a terrific way to get on to your windows machines remotely.  And now that Android supports VPNs there is no reason to be disconnected from work, ever. - Paid, not cheap.
  12. Robo Defense - This game is a terrific tower defense game for Android.  Will occupy way too much of your time. - Free trial, Paid but inexpensive.
  13. Speed Forge 3D - This game is an interesting flying/driving style game that uses the accelerometer to steer.  Very cool - Free trial.
  14. Speed Test - A nice app to determine just how fast your 3G connection is running.  Uses SpeedTest.Net in the backend. - Free
  15. Sports Tap - The best app to keep up to speed on the football scores and stats.  - Free
  16. UStream Broadcaster - Much like Qik, this app permits you to broadcast your phone’s camera live to the web but over UStream. Free.
  17. Where - The best local info app on the market.  Smartly uses locale information to provide everything from movie listings to yellow page lookups.  Terrific interface - Free.
  18. — bonus pick — Moxier Mail - This application isn’t really one that I’ll use any longer now that I’m on the DROID, but if you are stuck on a pre Android 2.0 device and don’t have built-in exchange support, I highly recommend you pick up a copy of Moxier.  It is a terrific exchange client supporting ActiveSync, Microsoft’s push technology.  - Paid and not cheap.

Hope this helps any new Android users out there.

Bookmark and Share
Comments (View)

Photo Album of the Day

Bill Murray or @Garyvee?

I was checking out clicker.com and caught a glimpse of Bill Murray from the movie Stripes.  I could have sworn it was Gary Vaynerchuk.

Bookmark and Share
Comments (View)

Video of the Day

Microsoft finally finds the Marketing Mojo.  This ad for Windows 7 is actually very well done and shows that Microsoft isn’t completely inept at marketing.  It’s no churro, but I like it.

Bookmark and Share
Comments (View)

Video of the Day

The Social Media Revolution.  Odds are you still know someone who just doesn’t get social media, be it Twitter, Facebook, Youtube, or Digg.  You must show them this video.

Bookmark and Share
Comments (View)

My beloved Delphi is under attack!!!!

As most of you know I am a software developer.  My language of choice is Embarcadero’s (formerly CodeGear’s (formerly Borland’s (formerly Inprise’s (formerly Borland’s)))) Delphi.  Apparently someone has written a virus that infects Delphi RTL source with code that will automatically compile a virus in any executable compiled with that source code. What a unique way to infect a huge number of people with very little work.  Very interesting and scary news.

— update — just talked to Nick Hodges at Embarcadero and he said that virus scanners are picking up on the virus, but it’s not clear if it’s finding only the compiled exe’s or the infected rtl files.  As he points out a scan will find all ProjectXX.exe’s on the system are infected at the very least and that would be a good indication that you’re screwed.


http://www.theregister.co.uk/2009/08/19/delphi_malware/
Bookmark and Share
Comments (View)

Video of the Day

An iPhone user finally gets fed up with Apple and vents by taking a handgun to his 3Gs and then setting it on fire.  The most remarkable thing to me is just how great a shot this guy is.

Bookmark and Share
Comments (View)

Sprint Acquires Virgin Mobile for $483m in Stock

As a prior Helio customer, this is mildly interesting to me.  Helio was the MVNO that was purchased by Virgin Mobile last year.  I abandoned Helio for the Android phone and T-Mobile.


http://www.engadget.com/2009/07/28/sprint-acquires-virgin-mobile-usa-for-a-cool-483m/
Bookmark and Share
Comments (View)

Lovin me a cupcake

Apparently, I’ve had cupcake available to install on my Android phone (TMobile G1) for a bit now.  I’ve been getting a bit frustrated because my wife has had hers for a week or so already and mine was nowhere to be found.

However, I decided to prompt the system to check for an update using the Settings | About Phone menu and guess what, there it was waiting for me to download.  Why hadn’t TMobile notified me?  I think I know the answer.

I hit the download button and up popped the progress bar… but nothing happened. Tried again… no luck.  It says the file is 32MB and I know I’m tight on app space, but they can’t honestly expect to download this into app space, could they?  They must use the SD card or the OS partition…  right?

Nope.  Apparently they use app space to store the downloaded update.  After I opened up 40MB of space in my app space and returned to check for updates, it downloaded on the second try. As soon as the update was downloaded, I received the standard update notification that you would receive had TMobile sent the file to me directly.

So, apparently, if you haven’t received your cupcake update, you might want to free up some app space memory.  About 40MB should do.  You can always reinstall your apps after the update.  And that’s what I’m off to do right now.

Bookmark and Share
Comments (View)

TMobile Hates Me

My wife has had the Cupcake release on her G1 for a few days now and still nothing for me…  I’m beginning to think that TMobile hates me.

Bookmark and Share
Comments (View)

This will change the internet world.

Dammit.  This was my idea like 3 years ago.  Now Google has gone and implemented it… and way better than I would have I’m sure.

I’m very excited about this.  It will change the way we view the web.


http://wave.google.com/
Bookmark and Share
Comments (View)

I’m now a happy Google apps (gmail) user…

I have for a long time avoided using Google apps for my mail because working with multiple mail accounts in a browser is less than satisfactory.  However, last fall I decided that upgrading my mail server for better spam protection was just too expensive so I made the move.  Overall, Google apps mail (essentially gmail on your own domain) is very functional and has great spam protection.

The biggest problem is when you have multiple accounts.  For example, I have to monitor  jsouthwell@arcanatech.com, sales@arcanatech.com and support@arcanatech.com.  In a normal email application, it is easy to add multiple accounts and monitor each as needed.  However it’s not so easy with browser based email as you have to log out and log in to swap between accounts.  I tried just opening new browser windows (or tabs) for each, but gmail doesn’t like that.  You actually will get a dialog pop up saying that you have logged into a new account and will log out the other tab.  Very frustrating.

I’ve downloaded several gmail toolbar applications that claim to support multiple accounts but none solve the problem of having multiple accounts open at the same time.

I recently downloaded Google’s Chrome 2.0 as I heard that it better supported distinct profiles and I suspected that I could create profiles for each email account and use Chrome’s cool app feature to create links to my email accounts from each profile.  Unfortunately the app feature doesn’t seem to remember the profile used to launch the link so that didn’t work.

However, I found that I could manually create shortcuts to web pages that specify the profile I want to use.  This almost completely solves the problem.  For example, shortcut one links to:

C:\Users\jason\AppData\Local\Google\Chrome\Application\chrome.exe —user-data-dir=”....\User Data-jsouthwell@arcanatech.com” —app=”http://mail.google.com/a/arcanatech.com”

and shortcut two links to:

C:\Users\jason\AppData\Local\Google\Chrome\Application\chrome.exe —user-data-dir=”....\User Data-sales@arcanatech.com” —app=”http://mail.google.com/a/arcanatech.com”

Now when I click on link one, I get a cookie space dedicated to jsouthwell@arcanatech.com and link two gives me a cookie space dedicated to sales@arcanatech.com.  The result, I can have multiple windows open for multiple gmail accounts on the same domain with no conflicts.

All I need now is a good taskbar notification app for multiple gmail accounts that link to the correct shortcut to launch for each account.  Then I’d be very very happy.

(note, this solution likely will work in the currently released version of Chrome but I haven’t tried.  It also may work in other browsers that support user profiles launched from the command line)

Bookmark and Share
Comments (View)
Bookmark and Share
Comments (View)