def _remap_date_counts(**kwargs):
 for (label, qs) in kwargs.iteritems():
  res = defaultdict((lambda : {label: 0}))
  for x in qs:
   key = date(x['year'], x['month'], x.get('day', 1))
   res[key][label] += x['count']
  (yield res)

def _remap_date_counts ( ** kwargs ) : for ( label , qs ) in kwargs . iteritems ( ) : res = defaultdict ( ( lambda : { label : 0 } ) ) for x in qs : key = date ( x [ 'year' ] , x [ 'month' ] , x . get ( 'day' , 1 ) ) res [ key ] [ label ] += x [ 'count' ] ( yield res )
remap the query result .