Prius Speed vs MPG: Inconclusive

I had a roadtrip looming, so I figured I’d do some experimentation:

2014-07-23 19.49.57

I wanted to find which highway speed would give me the best MPG.  I had some hilly areas (Louisville->Cinci) and some flat areas (Cinci->Columbus) to experiment with.      I figure after 10 miles, I’ll get an okay reading for average mpg, and I could move on, right?

Wrong.  

Turns out, the relative altitude of the car makes a HUGE difference.  If I reset my trip-meter at, say, 700 ft above sea level (as measured by my cellphone GPS), then at 600ft, I might have a MPG of 62, and at 800 ft it might be 57.  Even after 15 miles.  

I could have worked with this, except that every time I seemed to reset the trip meter, I never got back to that same altitude.  The road went down.  Or it went up.

Now given some fancy math I’m sure I could have calculated some numbers.  But not worth it. 

Thanks to some really slow traffic, though, I did figure out that in general, the Prius wants to get about 70MPG for anything over 45 mph, with the AC on, except that wind resistance knocks that number down to about 45MPG at about 70MPH.  

It seems that driving with the cruise set at 55 nets me in the low 60MPG’s. 

It does not appear there is a local maximum somewhere between 50 and 60.   50 is more efficient than 60.  And that is NOT a speed I’d set my cruise control to, sorry.  I don’t want to be one of THOSE Prius drivers.

Maybe some day when I’m bored I’ll drive a loop (I264, I71, I265, I64) at 50,55,60,65 MPH and record those numbers.   I can use the straight stretch near the ford motor plant as the transition from one speed to the other.

Having Fun with SSIS

My new project involves getting data from 500+ remote sites into a target database; in parallel, quickly.  Thanks to some proof of concept work done by my coworker Mike “The Devastator” Hurd (I made up the nickname), I got to learn SSIS, and I’m cursing that I had not picked it up earlier. 

What Is SSIS?

  • Imagine you wanted to write a generic program to get data from point A to point B, but modify it along the way.
  • You wanted pluggable components that could talk to each other.
  • You wanted anything that could be done in parallel to be done in parallel.  Ie, read from two tables at the same time if you have bandwidth.
  • You want it to work buffered rather than row by row.  But dynamically figure out buffer sizes so that they fit well to the page size on the computer (to minimize swapping)
  • You want a GUI that you can configure these components with.
  • You want every component to have a configurable “if things fail” state, to redirect failed rows to other components, etc.
  • You want it to be solid – no leaking memory, etc
  • You want to parameterize the stuff getting into the components
  • You want it to be runnable from a command line, with ability to override parameters and connection strings.
  • You want the whole configuration to be saveable as an XML file, or hosted in a SQL Server
  • You want to be able to schedule it to run from SQLAGent (SQL Server’s “Cron” thing)
  • You want to be able to run it directly from C# via managed code.

Then you would write SSIS.

What Does It Look Like?

image

image

image

image

Initial Gotchas

SSIS requires some level of licensing, so this does NOT work:

  • Install SQLEXPRESS
  • install Visual Studio 2012 Premium
  • Install SSIS add-on
  • Install SSDT (“database tooling for VS2012”)

It successfully loads, and you can debug packages within Visual Studio, but you cannot run them outside via dtexec and dtexecui (the command line thingies for SSIS).  Instead, you need to add:

  • Install SQL Server Developer Edition (which includes SSIS)  (or standard edition)
    • Select Integration Services & Data Tools
    • Do NOT have to install the engine.
    • Might have to install an updated SSDT to get VS2012 support

Then everything runs fine.

The other thing I quickly learned is it is very Schema-dependent.  The reason for this is it allocates row counts into buffer sizes based on the size of the rows – so a Varchar(MAX) field is very different from a Varchar(250) field – and the schema will fail to validate if the underlying data source it is reading from does not match perfectly.

The solution I had to apply was to do a select cast(x as varchar(250)) as x to extract the data to guarantee the schema coming in to SSIS.  

Conclusion

Very glad to have this tool in my arsenal.   Thanks Mike!

Day at the Office: Using vi’s Macros

I had a method which was too long.  It was a switch/case statement, with a bunch of processing at each case label.    There were a lot of local variables that were being used:

var foo=something; 
var bar=yetsomethingelse; 
var scooby=another thing; 
var fred=yetanotherthing; 

switch(thingy) { 
  case A: 
    stuff with foo and bar; 
    break; 
    
  case B: 
    stuff with foo and scooby; 
    break; 
    
  case C:
    stuff with foo, bar, and scooby; 
    break;
    
  case D:
    stuff with foo, bar, and fred; 
    break;
    
  default:
    throw new exception(); 
    break;
}

In this mockup I only have 4 variables; the real one had 12.   And each case label was probably 20-30 lines of code.

Apply Refactoring: Replace Local Variables with a Class

And the name of the class shall be context. 

So I had a lot of errors, where this:

if (something(fred)) anotherthing(barney)

had to become this:

if (something(c.Fred) anotherthing(c.Barney);

The Vi Macro

The exact keystrokes were:

  Begin with cursor on fred
qn Begin Recording a Macro to register n.  I use n because its on the right hand, and the @ symbol to apply a macro is on the left hand.
~ Change case (now we have Fred)
h Go left one (because ~ moves you forward)
i Enter insert mode
c. <Esc> type in “c.” and exit insert mode
l move the cursor right one.
q Finish recording

 

Then, I hit rebuild (F6), looked at the list of errors, and then primed myself:

/fred @n  / enter  (find fred, fix fred macro, find next fred)

@n / enter   (fix fred, find next fred)

Apply Refactoring: Extract Methods

Now that I had a reasonable list of variables (one mega-variable, the “context”, and some other minor ones), I could take the meat of each case block and extract out a method for just that case block.

The result: cleaner code… and in one case, I could pass my context variable one layer deeper and extract out some other meaningful stuff from it (which I had not pulled out into a variable before).

Shapeways: Color Sandstone Dan

Its here!

image image
 

[youtube=http://www.youtube.com/watch?v=BwftC16fRmc&w=448&h=252&hd=1]

I was impressed at how well it was packed:

image

That’s some kid of primo bubble wrap where the air pocket extends across multiple cells; so any one cell receiving a blow.. it does NOT pop. 

It cost me $8.50 + $6.50 Shipping and handling.

The process to put this together, roughly:

  • Create a Hi-res and a low-res model (500 faces or so) from AgiSoft
  • Fix any glaring problems with the low res model
  • Add a Subdivision Surface modifier to the low-res model in Blender to give it back some curves, while retaining a simple geometry that you can edit by hand.
  • Toggling back and forth between high and low, add cuts and edge creases to get the shape correct.  (Usually: Ears, Nose, and Mouth; perhaps Eyes)
  • Export the subsurfed model back to Agisoft for texturing; then back to blender for sizing, and sending to Shapeways.

There’s an additional step around making holes to remove material; I will explain that more on the Lamont model next week.

Save the Wrists! Ordered a new keyboard / Code Dictation?

My wrists have been numbing more lately.  At my wife’s suggestion, I’ll bring it up with my GP at my appointment next Wednesday.  Meanwhile:

  • Switch to using the trackball with my left hand.
  • Switch keyboards.

This is the keyboard I’ve been using for the last 2 years or so – Microsoft Wireless Comfort Keyboard 5000.   It has some level of curve in it, however, I still have Ulnar Deviation and Pronation when using it.  The keyboard action is very light, and its been good to me for a while.   It is wireless .. less cords to deal with.

image

This is my older, wired, USB keyboard.  Microsoft Ergonomic Keyboard 4000 v1.0.  I switched back to it, but what I find is that the keys take too much pressure to press.. and my hands are tired.   I couldn’t do it.    The keyboard is also larger, which means I need to stretch my fingers further to press the keys.  However, Ulnar deviation is a bit better.

image

Just for fun, I tried using both at the same time:

image

This worked surprisingly well.  It was fluid, except when I needed to switch to the mouse.   I’m used to my keyboard being a single keyboard, and something about having two keyboards confused me; I didn’t know which hand to move.  I guess I know my “home” position based on the distance between my hands, and if I move one hand, I cannot find home easily without looking. 

I did some research and decided to order this keyboard, it should arrive next week sometime:

 

In the mean time some of the things I can do are:

  • type at a deliberate rate. (not look at keyboard)
  • type with one hand only.   (requires looking at keyboard)
  • I can also just use one finger from each hand.  By doing this the entire hand moves, and ulnar deviation is removed.   It is also quite fast.  (requires looking at keyboard)
[youtube=http://www.youtube.com/watch?v=xLR0Nwh1l6o&w=448&h=252&hd=1]
What did I type?

This is me typing with one hand.

In light of Hanselman’s new app which allows dictation from an iPhone, I wonder if there are any programmer-specific dictation tools?  I have looked at vimspeak, however that mostly addresses the control aspects of using vi.   Think of it:

public int Add(int a, int b) { return a+b; } 

“public int shift A d d paren open int a comma int b paren close curly open return a plus b semi close curly” ?

Other folks have talked about it over here: http://productivity.stackexchange.com/questions/3605/how-can-we-use-dragon-naturallyspeaking-to-code-more-efficiently

The problem is one of lost context.  In programming we are trying to be specific about contexts – usually using parens and curly’s as visual queues – for example, that “int a” and “int b” are parameters of Add.   The solution seems like it would be codifying contexts into spoken word, by adding extra keywords to tell the parser what we are trying to do.  For example:

“function <name>” => starts adding function, puts you in function mode; creates defaults; additional things make sense in this mode:

  • “parameter x”
    • [of type] y
  • “returns [type] ”
  • [visibility] “public” | “private” | “internal”   // keywords can infer that we meant visibility
  • “body”  // go to editing body mode

So theoretically, “function Shift a d d visibility public returns int parameter a of type int parameter b of type int body return a plus b”, or more specifically:

What is said What the code looks like (using underscore to denote cursor)
function object a01() { }
Shift A object A() { }
d d object Add() {  }
visibility object Add()  {  }
public public object Add() {  }
returns public object Add() { }
int public int Add() {  }
parameter public int Add() {  }
a public int Add(object a) { }
of type public int Add(object a) {  }
int public int Add(int a) { }

etc.    Ie, you map the spoke word into meanings that then get applied to the editor.

You could even navigate “into” and “out of” contexts by using clicks and clucks – sounds that are easy to make yet are definitely not letters.   “down” and “up” would apply at the context level – ie, statements, or functions.

It is an interesting problem.  It could be a fun thing to solve.  Any takers?

Day at the Office: Visual Studio Express 2013

Customer has requested sufficient documentation that after we leave the project, they could bring on another developer and they could get up to speed efficiently.

imageSo, here’s my table of contents that I’m filling out (sure to change as it progresses).    I’m currently working on the “Build From Scratch”, which, to avoid any future awkwardness, means “Create a blank windows 7 virtual machine, Install visual studio and Compile.

Just to see if it was possible, I tried installing the free Visual Studio Express 2013 for Desktop instead of the paid version.

It works.

One of my resentments against Microsoft – from back when I was a Unixite and a Micro$oft Hat3r – was that the average joe can’t afford the tools.   (Whereas, Perl and Python and gnu C++ were free).   This is no longer true

You can download and run VS2013 Express for Web, or Desktop.   Limitation:  no code analysis stuff; possibly harder to integrate 3rd party tools.   Includes: NuGet package manager, Intellisense, Multiple projects per solution, etc.

You can download and run SQLExpress.  Its pretty much the full blown SQL except it limits itself to 1 core and 1G of memory.  

I think that pretty much covers most of the software development I’ve done in the last 14 years, and gotten paid for.

Good Job, Microsoft.  I think I can be proud of you now.