 decamelize = (str) ->
   str = str.replace /([a-z])([A-Z])/g, "$1 $2"
   str.toLowerCase()
+titlize = (str) ->
+  str.replace /\b[a-z]/g, (s) -> s.charAt(0).toUpperCase() + s.substr(1).toLowerCase()
 text = (t) ->
   document.createTextNode(t)
 intFormat = (int) ->

      Energy:
        id: 'energy'
        htitle: 'Time (ticks)'
        vtitle: 'Net energy embodied by indviduals'
        collector: (stats, rows) ->
          counts = Plant: 0, Herbivore: 0, Carnivore: 0
          counts[description.type] += description.hp for description in stats

            -> u.urThing('carnivore').bodyColor
          ]
        rows: []
geneChartSpec = ( type, gene, id ) ->
  title = type.charAt(0).toUpperCase() + type.substr(1)
  {
    id: id
    type: 'interval'
    htitle: 'Time (ticks)'
    vtitle: 'Value of gene'
    collector: (stats, rows) ->
      values = []
      values.push d.genes[gene] for d in stats when d.type == title
      [ min, max, mean, median ] = [ 0, 0, 0, 0 ]
      if values.length
        values.sort (a,b) -> a - b
        min = values[0]
        max = values[ values.length - 1 ]
        mean += v for v in values
        mean /= values.length
        if values.length % 2
          median = values[ Math.ceil(values.length/2) ]
        else
          i = values.length / 2
          median = ( values[i] + values[i - 1] ) / 2
        rows.push [ evoData.generation, median, mean, min, max ]
    rows: []
  }
collectData = ->
  evoData.generation += 1
  byId('ticks').innerHTML = intFormat evoData.generation
