Refactor periodic grouped response

Remove duplication
Factor out period specific code

<3 deleting code.
Return None for a collect that has no data

Returns null in the JSON because we need to differentiate between
non-existent data and zero data.