Calculate averages for categories and add them to JSON