Andrew Que Sites list Photos
Projects Contact
Main

November 24, 2007

Drive price 6-month trends

    I added a fetcher to the drive price tracking script.  Now when you click on a drive size it shows a 6 month trend of price/gigabyte.  I've wanted this fetcher for awhile and this weekend was the first time I've had some time in quite awhile.  Because it's useful and I like playing with it, I also added linear regression to the plot.  This gave me a reason to implement such a function. 
    For algorithm for linear regression looks rather complex, but it's really not that bad--just a little multiplication and division.  Basically, the function give you the slope and y-intercept of the line that is at the center of the data.  And anyone who remember algebra 2 will recall a line is expressed simply as y = m*x b.  Doing this in PHP isn't too hard either.  As the code below shows, all the summations can be done in a single loop.  From that, the slope (m) and y-intercept (b) are calculated.  To draw the line, simple calculate two x values--one at the beginning of the graph and one at the end.
    Below is the code to do linear regression in PHP--well, a chuck of the code.  This is part of a class for drawing XY graphs I made.
    I had considered using a pre-existing graphics library for PHP, but the one I found a few months ago lacks documentation.  Oddly enough, I remember going through some examples I found and getting the thing to work.  Now, nothing.  Ah well....
 
//----------------------------------
// Draw linear regression plot
//----------------------------------
public function RenderLinearRegression()
{
$MarginLeft
= $this->Window->GetX();
$MarginTop
= $this->Window->GetY();
$MarginRight
= $this->Window->GetXX();

$Y_Delta
= $this->Y_Max - $this->Y_Min;

ksort( $this
->Data );

$TimeDelta
= $this->EndTime - $this->StartTime;
$WindowArray
= $this->BuildWindowArray();
$Count
= $n = count( $WindowArray );

// Do all sumations
$SumX = $SumY = $SumXY = $SumXX = $SumYY = 0.0;
for ( $Index = 0; $Index < $Count; $Index )
{
$x
= $WindowArray[ $Index ][ "x" ];
$y
= $WindowArray[ $Index ][ "y" ];
$SumX
= $x; // x
$SumY = $y; // y
$SumXY = $x * $y; // xy
$SumXX = $x * $x; // x^2
$SumYY = $y * $y; // y^2
}

// Slope:
// n xy - x y
// m = -------------------
// n x^2 - ( x )^2
//
$m = ( $n * $SumXY ) - ( $SumX * $SumY );
$m
/= ( $n * $SumXX ) - ( $SumX * $SumX );

// Y-intercept:
// y - m x
// b = -----------
// n
//
$b = ( $SumY - ( $m * $SumX ) ) / $n;

// Standard line function is y = mx b
$y = $this->ScaleY( ( $m ) $b );
$yy
= $this->ScaleY( ( $m * $TimeDelta ) $b );

// Save information
$this->Slope = $m;
$this
->Y_Intercept = $b;

// Draw line (thickness of 4 pixels)
for ( $Index = 0; $Index < 4; $Index )
imageline(
$this
->Image ,
$MarginLeft , $MarginTop
$y $Index ,
$MarginRight , $MarginTop
$yy $Index ,
$this
->LinearRegressionColor );
}

2 comments have been made.

From Nathan

Chicago

November 28, 2007 at 5:30 PM

any plans of actually buying drives, or you just like to build ever more complex graphs? :) in the market for a new laptop soon myself, and those ssd drives are starting to emerge, but oh so expensive :( sounds like they're incredibly fast compared to the old stuff...

From Andrew Que (http://www.DrQue.net/)

Wisconsin, USA

November 28, 2007 at 11:54 PM

I just like building ever more complex graph ;)

November 23, 2007

Get away from the family and eat leftovers gathering

    Today was the annual Get away from the family and eat leftovers at the Garage gathering.  We had a decent turnout, a lot of food and a pretty good time.
    Pictured is Rachel

November 22, 2007

Hard Drives and Snow

Cost per gig
(Click image for larger plot)
    Here are three plots of the average cost (per gigabyte) of three hard drive sizes: 250, 500 and 750 gigabyte.  What can be observed is that 750 gig drives have dropped most dramatically in price since May, from almost $0.34/gig down to under $0.23/gig by November.  The 750 gig drives have ducked below 250 gig drives and are now the second cheapest drive per gigabyte of storage.  250 gig drives have only changed a few cents over the last seven months.  I except that as the larger drive sizes become more common in new machines, 250 gig drives will actually rise in price.  They actually started to in June, hitting a 7 month high in mid August of over $0.25/gig.  500 gig drives were steadily falling until mid September, when prices came back up.  These drives have been floating around $0.19-$0.20 a gig this month and last.
    What I'm interested in observing is what these drive prices do over the holiday season.  Observing the drive price script, it seems prices have flattened out.  My guess is the prices will hold until the shopping peak is over.  Should be interesting to find out.
    The drive tracking script missed several days of data--I corrected that today.  Seems PriceWatcher changed the address of the hard drive price page so that it includes "removable media".  After I figured this out, I made a quick change and the script is back in action.  Unfortunately, I don't have data for about the last weeks now.This doesn't hurt the linear regression plots posted right now because one week a fairly small period over 7 months--but the drive price page only displays data from the last 30 days and it's much more visible on those trends.
    We got snow last night and I was pleased to see about 2 inches on the ground this morning.  Being the first snow of the season, I've updating the theme accordingly.

1 comment has been made.

From Juliet

Madison

November 24, 2007 at 11:42 AM

I like your snow theme. I loved flying into Madison yesterday and seeing the snow on the ground.
Whole-Wheat Buttermilk Bread

Whole-Wheat Buttermilk Bread

    This is a buttermilk whole-wheat bread I tried.  I had a bunch of buttermilk and decided I'd see what I could bake with it.  It's not too bad, but I think adding some honey would really make this a tasty bread.  I also baked some mint chocolate-chip cookies cuz, you know, ya gotta have those laying around :)
Sourdough Sub Rolls

Sourdough Sub Rolls

    These are some sourdough sub rolls I made up.  They are just a little too big to make good sub sandwich, but not bad.  This batch of dough made 4 rolls, so I might be fine making 6 rolls, and each a little shorter.
The Shadow Box

The Shadow Box

    End of act one of the Baraboo performance of The Shadow Box.  The light on the characters isn't terribly even, but not bad considering the time constraints.  The image was shot using Elizabeth's 40D, which is a wonderful camera.  With the lighting as it was, I used ISO 1600 and under-exposed by 2 F-stops.  I did some contrast adjustments and a strong noise filter, then some small editing to remove random objects from the dark areas.  Act one ends on a very melancholy note and I think the cast really has that expressed in this picture.

November 17, 2007

Baraboo performance

Cast and Crew

Cast and Crew

    Today was UW-Rock's trip to UW Baraboo/Sauk County.  We were to perform The Shadow Box in their theater, and being (pretty much) the lead tech, it was my job to figure out how to throw light on the cast.  I had three hours to learn an entirely new light board, place lights, set levels and program in all the lighting cues.  Somehow, it was all done and ready when it was time for house lights to dim.  And even more surprising, despite having never used the light board and having no time to verify, all but one of the lighting cues were perfect.  I was not able to figure out how to set timing for lights up/down, so I did all the timing manually.  It worked just fine, but was a little strange.  I had to start the cue ahead of time and use two faders to make the light change take place.
    The trip was really great.  We had light snow on the way up--the first snow I've seen this year--and that always makes me happy.  Baraboo was a lot of fun.  We had lunch in a little restaurant downtown and stop in at a coffee shop before heading over to the campus for setup.  While it was a good deal of running around in order to get things set up, it was a lot of fun too.  The production went well and it was neat to see our cast operate in a completely new environment.
    Pictured is the cast and crew.  From rear to front, left to right: Nick French ("Mark"), Amber (stage manager), Mark Fuller ("Joe"), myself (crew), Jim Plasky ("Jim"), Kristin Gulatta ("Beverly"), Brittany Boeche ("Maggie"), Molly Mueller ("Felicity"), Brian Stults (voice of interviewer), Elizabeth Moore (crew), H. Gene Biby ("Brain") and Amy Krebs ("Agnes").