Bin-averages is introduced

Backed up the previous code.
Added several functions to segregate into bins, calculate averages and
query the DB. Not complete.